ps i hate you |
2008-05-29
|
CPU usage is currently expressed as the percentage of time spent running
during the entire lifetime of a process. This is not ideal, and it does not
conform to the standards that ps otherwise conforms to. CPU usage is unlikely
to add up to exactly 100%.
This explains why my nagios checks for processes with >90% CPU use doesn't work.
It's logical when you think it through, but the nagios check is very misleading because it doesn't mention this at all, just talks about CPU.
Sigh, let's try with sar instead.
I came across the same problem using top in batch mode.
top -b -n1 |grep Cpu
the solution seems to be let top give two iterations in batch mode
top -b -n2 |grep Cpu
the second one gives the current cpu usage
Comment by ssam — 2008-05-29 @ 23:45
best title ever.
Comment by fons — 2008-05-30 @ 09:34
Would “top” give you something meaningful to monitor with Nagios?
On my OS X / BSD machine:
top -l 2 -o cpu -n 10 | tail
The “-l 2” seems to be crucial, as I suspect the output from the first iteration isn’t what you want here.
On Ubuntu 7.10, it seems the closest equivalent is
top -b -n 1 | grep ‘^[ 0123456789]’ | grep -v ‘^ PID USER’ | sort -nr -k 9 | head
The greps get rid of header/summary lines which would otherwise mess up the output.
Comment by Jamie — 2008-05-30 @ 12:19