Operating System - HP-UX
1827855 Members
1621 Online
109969 Solutions
New Discussion

Re: Help? Script to monitor process cpu and email if over 85%

 
Craig A. Sharp
Super Advisor

Help? Script to monitor process cpu and email if over 85%

Hi all,

I need to monitor a single process by name not PID and then email if the cpu exceeds 85% for more than say 30 seconds.
Does anyone have any idea on how to do this? A script for ksh is great, perl would be even better.

Thanks,

Craig Sharp
Roush Industries
10 REPLIES 10
harry d brown jr
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

glance+ will do this for you, but it requires a license. Try looking at www.bb4.com/bb, it'll do it for ya.
Live Free or Die
Craig A. Sharp
Super Advisor

Re: Help? Script to monitor process cpu and email if over 85%

I have Glance+. How would I set it up. If I remember right, I would not have to have GPM running, just the daemons. The alarms should then be able to send emails or whatever.

I think that this might still be better suited for a perl or ksh script so it is portable.

someone_4
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

 
Sridhar Bhaskarla
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

Craig,

It will be too much to put down here. If you have the Pak installed, look at /var/opt/perf/alarmdef file. There are some nice examples in
/opt/perf/examples/adviser directory too that will give you a good direction. It's easy.

Enjoy.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Santosh Nair_1
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

You can write a script to parse the output of this command:

UNIX95= ps -o pid,comm,pcpu -C

where is the name of the process that you are interested in. This command returns the process ID, the command and the percentage CPU that this process is taking. Hope this helps.

-Santosh
Life is what's happening while you're busy making other plans
Kevin Wright
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

you can set alarms in the alarmdef file if using glance..don't know if you can set it on specific processes though.
Craig A. Sharp
Super Advisor

Re: Help? Script to monitor process cpu and email if over 85%

The ps command looks like the easiest way to do this. The only problem is that the -o and -C options are XPG4 only. What does this mean? I get unknow options when I try to run the command. I am also having a look at the glance option.
Santosh Nair_1
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%

XPG4 is just another attempt at a UNIX standard. If you set the environment variable UNIX95 to anything, then these option are available. That's why I had the UNIX95= in my command above.

-Santosh
Life is what's happening while you're busy making other plans
Bernie Vande Griend
Respected Contributor

Re: Help? Script to monitor process cpu and email if over 85%

If you already have glance, then using its alarm features would be the easiest way to do this.
Attached is an example of a alarmdef definition that you could tweak to do exactly what you want. (You'll have to add the check for the process name)
Just add it to /var/opt/perf/alarmdef and restart the alarm process.
Ye who thinks he has a lot to say, probably shouldn't.
harry d brown jr
Honored Contributor

Re: Help? Script to monitor process cpu and email if over 85%


In gpm (glance+) you can change the advisor to execute an alarm:

ALARM

gbl_cpu_total_util > 90 FOR 30 SECONDS

gbl_run_queue > 3 FOR 30 SECONDS

START YELLOW ALERT "CPU AT ", gbl_cpu_total_util, "% at ", gbl_stattime

REPEAT EVERY 300 SECONDS {RED ALERT "CPU AT ", gbl_cpu_total_util

exec "/usr/bin/pager -n 555-3456"}

END ALERT "CPU at ", gbl_cpu_total_util, "% at ", gbl_stattime, " - RELAX"
Live Free or Die