Wednesday, June 11, 2008

Want a better "top", try atop

I was recently looking for a utility that could record cpu, memory, and load usage on a per-process basis over a specified period of time. "top" itself has a -p flag, that lets you watch a single process, but no way to record to a logfile that I could find. Other utilities, like sar are system-wide, instead of process-specific. I was ready to write a script, when I found atop.

Atop can work like top or sar(if used with atopsar binary), but unlike either of these, it has heaps of flexibility, including being able to write to a logfile. It also has color highlighting, so that you can define when the CPU reaches a certain threshold, that it should turn red. It can write an ASCII logfile with timestamps based on the intervals you define, and it lists the system state, along with the process state that you've chosen.

Try this simple .atoprc to watch firefox's activity at 5 minute intervals:
interval 5
procname firefox

Then just run it with "atop -M > your_log_file" and let it's do it's magic. This produces human-readable format but if you want something that's easily parseable(ie. tab separated data, check out the -P flag.

No comments: