|
There are several programs that do this, including iostat.
You can find details of the format or /proc/stat in section 1.8 (in my installation at least) of /usr/src/linux/Documentation/filesystems/proc.txt, or google search for filesystems/proc.txt
I should point out that the CPU usage isn't a very measurable quantity; at any point in time a CPU either is being used (executing code), or it isn't (waiting, context-switching, powered down), so the numbers only make sense over time. /proc/stat contains the total values since power-up I think.
Basically, the fourth field is the proportion of time spent idle, the ones before it are working, and the ones after it are waiting for/dealing with hardware. Plot these on a pie chart, and that's your average CPU usage.
Programs like top take the difference in these values sampled every two seconds, to work it out for over a shorter length of time.
|