James,
What about this:
CPU=0.0; for load in $(ps axu | awk '{print $3}' | grep -vE "^%|0.0"); do
CPU=$(echo $CPU + $load | bc); done; echo CPU Idle: $(echo 100 - $CPU | bc)
Of course, discard the load from the loop, pipes and 'bc' :)
Regards,
-Urivan Flores-Saaib
==============Original message text===============
On Mon, 04 Feb 2008 12:50:44 PST "James G. Sack (jim)" wrote:
How many ways are there to get CPU idle-time percentages
(my examples not all from the same system, in case anyone cares)
top -n1 | grep ^Cpu
> Cpu(s): 3.0%us, 0.5%sy, 96.2%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
iostat|grep -A1 avg-cpu
> avg-cpu: %user %nice %system %iowait %steal %idle
> 3.12 96.33 0.32 0.01 0.00 0.22
vmstat 1 3
> procs -----------memory---------- ---swap-- -----io---- --system--
-----cpu------
> r b swpd free buff cache si so bi bo in cs us sy
id wa st
> 0 0 397328 180788 21712 308620 4 6 36 34 116 59 9 5
85 1 0
> 0 0 397328 180780 21720 308612 0 0 0 48 1017 178 8 1
91 0 0
> 0 0 397328 180780 21720 308620 0 0 0 0 1076 602 8 0
92 0 0
(if the sysstat service is running..)
sar -P | egrep 'CPU|Average'
> 09:50:02 AM CPU %user %nice %system %iowait %steal
> %idle
> Average: all 8.58 0.01 0.64 0.75 0.00
> 90.02
I'm sure it can be done via ps, but I've sort-of given up on
understanding what options control what for ps. :-(
Then there are the GUI programs:
System Monitor (gnome-system-monitor)
subtract: 100% system-usage, I guess
gkrellm
subtract ..
Who's got more?
- - -
One burning question I have, is how do (each of) these programs
determine CPU usage -- I see the proc filesystem has things like
/proc/stat, /proc/vmstat, and of course each process has its own set of
data.
It does seem that different programs have different ways of defining
their usage categories.
Is there someplace that nicely explains this kind of stuff? Does anyone
want to ramble about it here? Or do have to break down and read the
docs in /usr/share/doc/kernel-doc-XXXX.Documentation/filesystems/proc.txt?
Regards,
..jim
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
===========End of original message text===========
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list