1824359 Members
3310 Online
109669 Solutions
New Discussion юеВ

CPU MONITORING SCRIPT

 
maxpayne
Occasional Contributor

CPU MONITORING SCRIPT

Hi,

I need a script that can monitor the cpu utilization. If the cpu usage reached 90% it will send an sms alert. Thank you in advance.
7 REPLIES 7
Peter Godron
Honored Contributor
Hein van den Heuvel
Honored Contributor

Re: CPU MONITORING SCRIPT

Think about it... do you think this is the first time this requirement is showing up.
This problem is solved many times over, please (google) look aroudn for prior solutions, see how close they are to what you need and adpat if needed.

You may find that prior solutions also though the whole problem through for a little longer and refined that rules. For example... you just indicate "If the cpu usage reached 90%". I ask... for how long?
shoudl any spike trigger this? Any everage over n minutes?

Cheers,
Hein.

Yogeeraj_1
Honored Contributor

Re: CPU MONITORING SCRIPT

hi,

Have a look at SEP's script at:
http://www.hpux.ws/system.perf.sh

also, why are you worry about your CPU usage reaching 90?

When the CPU usage reaches 99% or even 100%, this is a good sign that your system is working well and it only when this situation persist over a long period that you should be "worried"

look into measureware also.

hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
maxpayne
Occasional Contributor

Re: CPU MONITORING SCRIPT

Well,
Here is the script that I create, but it doesn't seems rite. It keep on sending email eventhough the cpu idle is 95%.

sar -u 1 1 |awk '{print $5}' | if [ "$5" -le 95 ]; then
echo "High CPU Utilization" | mailx -s 'cpu reach 85% PLS CALL ADMIN' admin@admin.com
fi
Patrick Wallek
Honored Contributor

Re: CPU MONITORING SCRIPT

Here's a script that should work better. Although I agree with previous posts that you do need to better define you requirements.

#!/usr/bin/sh
PCT=$(sar -u 1 1 | tail -1 | awk '{print $5}')
if (( ${PCT} <= 10 )) ; then
echo "CPU Usage is currently at ${PCT}. Please call an admin" | mailx -s "CPU Usage at ${PCT}" me@my.com
fi
Peter Godron
Honored Contributor

Re: CPU MONITORING SCRIPT

Hi,

Isn't field 5 "%idle" ?
So, you want to get mail if the CPU is Less or equal to 95% idle ?!

Can you show field 5 in your debug ?
Patrick Wallek
Honored Contributor

Re: CPU MONITORING SCRIPT

Yes, field 5 is "%idle". That is why in my script I modified it to be <= 10 so that the if statement will be true only if CPU usage is 90% or greater.