LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Calculating CPU-Usage for Unix/Linux..? (https://www.linuxquestions.org/questions/linux-newbie-8/calculating-cpu-usage-for-unix-linux-932862/)

mrm5102 03-05-2012 02:07 PM

Calculating CPU-Usage for Unix/Linux..?
 
Hello All,

I'm trying to monitor CPU-Usage on a SLES 10 Server.
My question is which "CPU percentages" should I use to calculate the CPU-Usage...?

I know when you run "top" you can see about 8 different percentages lined up at the top of the page, which are:
(%user, %system, %nice, %idle, %wait, %interrupts, %soft, %steal)
You also get the same 8 percentages when you run "mpstat -P ALL".

Running vmstat you can see 5 percentages for CPU:
(%user, %system, %idle, %wait, %steal)

If I misunderstood any of the abbreviations that they use for the cpu %, please let me know.
So which of those are the most important? Also, whichever one's are the most important can I just add them and average them out?


If anyone has any suggestion please feel free to let me know.
I've searched all over and couldn't find a definite answer.

Thanks in Advance,
Matt

suicidaleggroll 03-05-2012 02:32 PM

I would use the load instead, but that's just me. It's time averaged, smooth, and incorporates everything that draws CPU time. You also have multiple values giving you the average load over different time scales, so you can see if the spike in load is just temporary or if it's been going on for a while.

mrm5102 03-05-2012 03:21 PM

Hey suicidaleggroll, thanks for the reply.

How do I see the CPU load...?

Thanks,
Matt

mrm5102 03-05-2012 03:41 PM

Or should I just take all 8 percentages add them up and divide by 8 and get the average..?

syg00 03-05-2012 04:54 PM

That would be absolutely the worst thing to do.
For definitions see the manpage(s). Also see the manpage for proc - particularly /proc/stat as that is where all the numbers probably come from.
Given how rubbery the numbers are in the first place, might be simplest to merely use "100-idle-wait-steal".
idle and wait are complements of each other for unused CPU - steal should be zero for a stand-alone (non-virtualized) server.
Doesn't give any idea of balance across CPUs/cores of course - you could do it all yourself from /proc/stat if you feel inclined.

suicidaleggroll 03-05-2012 05:05 PM

Quote:

Originally Posted by mrm5102 (Post 4619220)
Hey suicidaleggroll, thanks for the reply.

How do I see the CPU load...?

Thanks,
Matt

It should be the three numbers at the top right of "top", ie:
Code:

top - 16:04:55 up 199 days,  8:30, 30 users,  load average: 0.39, 0.24, 0.12
The three numbers next to "load average". Leftmost is the fastest, rightmost is the slowest (averaged over the longest amount of time).

chrism01 03-05-2012 06:36 PM

You might want to read a few articles; its not as simple as it seems eg http://www.linuxjournal.com/article/9001

mrm5102 03-08-2012 03:16 PM

Hey thanks to everyone who replied.

I wish they would make this a little bit harder and a bit more confusing to get something like CPU Usage in a percentage... But oh well!

suicidaleggroll,
I decided to go with your suggestion using the load average from the first line of the top command.
I think I'm just going to have a simple Perl script to extract the "load average" from the output of "top -n 1"... Simple enough.


Thanks Again,
Matt


All times are GMT -5. The time now is 08:30 PM.