[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: current cpu usage

On Thu, Sep 06, 2001 at 03:50:01PM +0200, Robert Waldner wrote:
> On Thu, 06 Sep 2001 09:34:05 EDT, Peter Billson writes:
> >> cat /proc/meminfo
> >> cat /proc/loadavg
> >
> > The meminfo would help him but he posted that he didn't understand load
> >average and, anyway, needs percent of CPU used. You can not calculate
> >CPU usage from load average.
> Not to mention the deep dark magic by which loadavg is generated. I 
>  still don´t understand that completely ;-)
> And yep, that should´ve read 
>  cat /proc/stat
> instead. (And no, I don´t know what the values in the first line 
>  exactly mean, but as soon as I set up mrtg again, I´m gonna read up on 
>  the kernel-sources)

The problem with using /proc/stat is the values presented on the cpu
line are running totals of jiffies spent in user, nice, system, and
idle respectively.  So, you have to read /proc/stat at least twice and
then calculate the deltas (and average over the time delta if you seek
an average.  Reading man proc and the source code (proc_misc.c;
function kstat_read_proc) helped a lot; man proc seems a bit out of
date WRT 2.4.x kernels.

Yesterday I wrote a perl script that does this (I'm playing with
cricket ... see


I'll make the script source available if someone wants it ... I use a
db file to store the readings from each run for use in the next run.

My loadavg figures come from /proc/loadavg ... I wasn't interested in
any heavy lifting :)

Now for the mem stats ...

Nathan Norman - Staff Engineer | A good plan today is better
Micromuse Ltd.                 | than a perfect plan tomorrow.
mailto:nnorman@micromuse.com   |   -- Patton

Attachment: pgptZU9wDvEKJ.pgp
Description: PGP signature

Reply to: