Operating System - HP-UX
1834908 Members
2869 Online
110071 Solutions
New Discussion

How to retrieve cpu usage for all processes

 
Charles Li_2
Occasional Advisor

How to retrieve cpu usage for all processes

Hi,
I would to retrieve cpu usage for all processes. I have try TOP and PS, but after adding up the cpu usage percentage for all the processes, it did not equal or come close to the total CPU usage reported by TOP.

This is what I used:
# to get all process with top
top -n 300 -f top_list.file
# to get all process with ps
ps -elfo pcpu,args
# I get the total CPU usage from vmstat
vmstat 1 5

Thanks,
Charles Li
9 REPLIES 9
RAC_1
Honored Contributor

Re: How to retrieve cpu usage for all processes

UNIx95= ps -ef -o "pcpu" | awk '(s+=41) END {printf "%d\n", s}'

say sd1

How many cpus you have??. check the value you got from above to "no of cpus*valus_above" (sat sd)

The value sd should match sd1 (roughly and not exactly.)

glance/sar is better tool for this and not top.
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: How to retrieve cpu usage for all processes

Some corrections.

UNIX95= ps -ef -o "pcpu" | awk '(s+=41) END {printf "%d\n", s}'

This value should match with what you see in top/glance
There is no substitute to HARDWORK
Raj D.
Honored Contributor

Re: How to retrieve cpu usage for all processes

Hi Charles ,

for all the CPU usage details :

# sar -u -M 5 5 ( For 5 instance)


for all top processes:

# ps -elf pcpu | sort -r -k4 | more ( 4rth column is cpu usage).

Cheers,
Raj.D.
" If u think u can , If u think u cannot , - You are always Right . "
Bill Hassell
Honored Contributor

Re: How to retrieve cpu usage for all processes

It's very important to understand that top, Glance, sar and vmstat cannot possibly give you an exact picture of CPU usage. You and I are far too slow to keep up with the hundreds of program changes that take place every second on a busy system. Combine the slow nature of human comprehension with multiple processors (and possibly threaded applcations), about all these tools can do is to approximate long term usage. These tools try to make measurements while the the very processes they are measuring disappear during the measurement period.

It doesn't make any sense to track all the programs and add up the usage. Instead, you look at the 'interesting' processes, those which consume more than 5-10% of total CPU for the system. top is a good start, but keep in mind that there is nothing wrong with your system is these processes are supposed to consume large amounts of CPU. Of course, the trick is how to determine 'normal' application behavior.


Bill Hassell, sysadmin
Charles Li_1
Advisor

Re: How to retrieve cpu usage for all processes

This is part of our performance monitoring process. I will plot the total CPU usage as well as CPU usage of groups of processes that are related. When I plot these graphs, I would like to see them add up.
Charles Li_1
Advisor

Re: How to retrieve cpu usage for all processes

We do not have sar or sat.
All I got is ps, top and vmstat.

Anyways, I am using the same ps parameters to get the CPU usage, and its not adding up to what top and vmstat is displaying.
Even when I add up %CPU from top, it does not match top's cpu usage.
Mel Burslan
Honored Contributor

Re: How to retrieve cpu usage for all processes

As Bill has explained in his post, any tool that you are going to run is going to be too slow to capture every instant of the cpu usage. Otherwise your cpu should do nothing but monitoring itself, which is quite oxymoron if you think about it.

So, if you collec the cpu utilization data in a long term, and be content with some inaccuracies, you already have your answer above. If your are trying to get a 100% match between the decomposition of process cpu utilizations adding up to the total cpu utilization, you will never get there. There will always be a discrepancy regardless how small it is.
________________________________
UNIX because I majored in cryptology...
Bill Hassell
Honored Contributor

Re: How to retrieve cpu usage for all processes

sar is standard on all version of HP-UX. There is no sat program. You always run sar with an option and at least the interval as in:

sar -u 1
HP-UX yoda B.11.11 U 9000/831 08/22/05

12:39:33 %usr %sys %wio %idle
12:39:34 47 4 0 50

Note that to do all the graphs, HP has a very extensive program set in the GlancePlus product line which offers PerfView to create graphs of every metric (about 200+) measure by Glance.


Bill Hassell, sysadmin
John E.Ophious
Regular Advisor

Re: How to retrieve cpu usage for all processes

Charles,

I'll have to agree with some of my other parnters in this post... it'll be down right hard to get it down to an exact amount. However, I have some good news.. there are some programs out there that can help with your graphs/measurements. One good one I've used in the past is called sarcheck. I also saved a bunch of money on my car insurance... jk. Check it out partner.

Into the sunset,

John E. Ophious