Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-09-2009, 11:19 PM   #1
LQ Newbie
Registered: Sep 2009
Posts: 5

Rep: Reputation: 0
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?
Old 09-09-2009, 11:45 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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:

Last edited by paulsm4; 09-09-2009 at 11:48 PM.
Old 09-10-2009, 07:06 AM   #3
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,064

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
I don't know about the others, but for vmstat this behaviour is described on the man page.
The first report produced gives averages since the last reboot.
Old 09-10-2009, 10:21 PM   #4
LQ Newbie
Registered: Sep 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the link, helped me loads.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
processes/CPU Usage/Mem Usage desktop wallpaper ceantuco Linux - Newbie 2 04-13-2009 01:14 PM
Why %CPU total not equal to cpu(s) usage? pii.ajah Linux - Server 2 12-02-2008 08:30 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration