Operating System - HP-UX
1836623 Members
1717 Online
110102 Solutions
New Discussion

Re: CPU Utilization per process

 
SOLVED
Go to solution
Stephen Kozlowski
Occasional Advisor

CPU Utilization per process

In top, it reports the CPU utilization (%) for each individual process. I am trying to do the same command line. I want to report any process that is running over 100% and email me the process and its PID.... I tried using ps but that only reports CPU utilization for scheduling. Any Ideas?

This is in a script.....
7 REPLIES 7
Alex Lavrov.
Honored Contributor
Solution

Re: CPU Utilization per process

export UNIX95=1
ps -ef -o pcpu,args | sort -n
unset UNIX95


This will print cpu usage and process name
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Ranjit_3
Advisor

Re: CPU Utilization per process

Apologies for asking a question in between this post , but i have tried teh above command , and it gives total of %CPU to 311.79 , how can any %CPU go above 100 % ?

$ ps -ef -o pcpu,args | sort -n | awk '{print $1}' | grep -v "%CPU" | awk '{a+=$1}END {print a}'

311.79

Thanks in advance
Alex Lavrov.
Honored Contributor

Re: CPU Utilization per process

If you have 7 cpu's, then u'll have total of 700%, if you have 4 cpu's u'll have total of 400%, etc ...


REgards,
Alex.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Stephen Kozlowski
Occasional Advisor

Re: CPU Utilization per process

Thanks.... It worked great....
Alex Lavrov.
Honored Contributor

Re: CPU Utilization per process

You welcome, also some points will be much appriciated ;)

Regards,
Alex
I don't give a damn for a man that can only spell a word one way. (M. Twain)
TwoProc
Honored Contributor

Re: CPU Utilization per process

Steve, Assign points, please.
We are the people our parents warned us about --Jimmy Buffett
Emil Velez
Honored Contributor

Re: CPU Utilization per process

I personally would do this using measureware (AKA the Openview performance agent). If you have a mission critical or enterprise OE you probably have measureware on the box. IT is collecting and can be used to generate alarms on systems.

Here are a few loops that you might use in the measureware alarmdef file

The first one generates a alarm is a process uses more than a specified amount of memory and > 50 seconds of CPU time. Another metric can be replaced.

The second one looks at a group of processes and generates a alarm if a group of processses use > 30% of the CPU.

PROCESS LOOP
IF ( proc_mem_res < 21000 ) and ( proc_cpu_total_time_cum > 50 ) THEN
{
IF (proc_proc_name != "vxfsd") and (proc_proc_name != "syncer") and
(proc_proc_name != "vbda") and (proc_proc_name != "fsadm") and
(proc_proc_name != "rep_server") THEN
ALERT "User ",proc_user_name," ",proc_proc_name," PID ",proc_proc_id, " PPID ",proc_parent_proc_id," has been running for ",proc_cpu_total_time_cum," minutes!"
}

big_app=""
highest_cpu=0
APPLICATION LOOP
IF (app_cpu_total_util > highest_cpu) THEN
{
highest_cpu=app_cpu_total_util
big_app=app_name
}
IF highest_cpu > 30 THEN
ALERT "App:",big_app," is a hog at",highest_cpu,"%"