jim sack wrote:
Who's got more?
snmp through the oids:
ssCpuRaw{User,System,Nice}.0
I believe there's a ssCpuRawIdle.0 as well, but its easy enough to add
those and subtract from nCPUs * 100.
/proc/stat has these values. almost all the implementations take their
data from /proc/stat for overall system usage; you can also get this if
you traverse the /proc/$PID/ structure and eat the stat output from all
processes.
under /proc/stat the lines are as follows:
id user nice system idle iowait irq softirq steal
so under my system:
cpu 7962966 15058995 16388089 1320628215 563366 93238 1379810 0
cpu0 3706897 6831738 5723878 662197779 259599 39888 362236 0
cpu1 4256068 8227257 10664210 658430435 303767 53350 1017573 0
[snip]
the first line is an aggregate, that is, the totals of all the CPUs in
the system.
The units above are in jiffies (whatever USER_HZ is set to in the
kernel; this will typically be 10 ms or 1/100th of a second).
user is the amount of time spent in user mode
nice is the amount of time spent in user mode but niced down
system is the amount of time spent in kernel mode
idle is well, time spent doing nothing
iowait is time spent blocking on I/O
irq is time spent servicing hardware interrupts
softirq is time spent servicing software interrupts (context switches)
steal is the amount of ticks "stolen" from this kernel by other VMs that
may be running on the same host -- a high steal is a good sign that your
hardware is oversubscribed. systems which are not virtualized won't
increment this number (but i digress)
to make use of this information, poll on /proc/stat every n seconds.
take the current value and subtract from it the previous value, and you
have the delta. divide this by n seconds times USER_HZ (typically 100,
but being careful not to ?DIV/0!) and you have an average percentage of
CPU utilization in each time slice. viola, wasn't that easy?
under /proc/$PID/stat, there are a lot more fields and I can't remember
them all off the top of my head.
/usr/src/linux/Documentation/filesystems/proc.txt has the description.
It does seem that different programs have different ways of defining
their usage categories.
some programs just flat out display it wrong.
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?
that'd be the best place to look :)
cheers, and hope this helps some.
-kelsey
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list