LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CPU usage accuracy puzzlement (https://www.linuxquestions.org/questions/linux-newbie-8/cpu-usage-accuracy-puzzlement-754050/)

peroxide 09-09-2009 11:19 PM

CPU usage accuracy puzzlement
 
Hi fellas,

I'm trying to write a script to capture the CPU usage for a particular server. I have tried iostat, vmstat and top, but in batch mode they always give a consistent value. For example, if I just run 'iostat -c' once, it will return the same value, no matter how many times I run it. However, if I use 'iostat -c 1 5' for example, the first value returned will be that same value, but the remaining values will fluctuate wildly.
The same behaviour is also observed with vmstat and top -b.

Can anyone tell me whether this is normal behaviour?

paulsm4 09-09-2009 11:45 PM

Yes, it's absolutely normal behavior.

And, in fact, a good (and often stated) rule of thumb is to *always* use "-5" (or "-3", or whatever you prefer), then always *disregard* the first value:

http://perfhints.blogspot.com/2009/02/vmstat.html

salasi 09-10-2009 07:06 AM

I don't know about the others, but for vmstat this behaviour is described on the man page.
Quote:

The first report produced gives averages since the last reboot.

peroxide 09-10-2009 10:21 PM

Thanks for the link, helped me loads.

:D


All times are GMT -5. The time now is 12:15 AM.