Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Feb 05, 2011 3:47 am 
Offline
Newbie

Joined: Fri Aug 27, 2010 5:24 pm
Posts: 4
Website: http://serverboy.net/
Location: Pennsylvania
When I run mpstat or vmstat, the CPU is shown to be mostly idle (95+% in most cases). When I run top, though, it shows my CPU as being 40% idle (mostly in use). What's up with that?

Using vmstat 1, it will slowly adjust to the correct numbers, but I need to get that data on the fly from the command line. Any way I could just cut the crap and skip right to the "real" numbers?


Top
   
 Post subject:
PostPosted: Sat Feb 05, 2011 8:56 am 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Each vmstat line displays the average CPU percentages since the last line it displayed; the first line will be the average since your last boot. This is because the kernel only keeps track of how much cumulative time has elapsed in various states (via /proc/stat)... you can't know a "right now" percentage, you can only take two samples and compare them.

munin has a "cpu" plugin that handles all this for you.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
PostPosted: Sat Feb 05, 2011 1:45 pm 
Offline
Senior Member

Joined: Fri Feb 18, 2005 4:09 pm
Posts: 594
bastawhiz wrote:
...I need to get that data on the fly from the command line. Any way I could just cut the crap and skip right to the "real" numbers?


As I recall, top displays the same load average numbers found in the file /proc/loadavg. On the command line, you might use:

cat /proc/loadavg

James


Top
   
 Post subject:
PostPosted: Sat Feb 05, 2011 2:15 pm 
Offline
Senior Member

Joined: Fri Dec 07, 2007 1:37 am
Posts: 385
Location: NC, USA
Load average is not the same thing as CPU percentage. As hoopycat explained, there is no "current" CPU percentage being maintained by the kernel - userspace tools have to figure it out by comparing cumulative CPU counters over time.

If you can wait a second for the result you can use something like this:
Code:
$ vmstat 1 2 |tail -1


Otherwise you need a daemon like munin watching it for you all the time.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group