Operating System - HP-UX
1832856 Members
2972 Online
110047 Solutions
New Discussion

Re: How can i generate the alterts if CPU utilization goes above 90%

 
SOLVED
Go to solution
praveen..
Super Advisor

How can i generate the alterts if CPU utilization goes above 90%

Hi all,
I have sendmail configured on my server.
i need to generate the alterts on my email id if CPU utilization goes above 90%.

how can i do this?
please suggest

24 REPLIES 24
Arunvijai_4
Honored Contributor
Solution

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi Praveen,

You may have to write a shell script for this, http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1008702

Or, you have to use tools such as Openview performance manager, http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=989506

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Michael Steele_2
Honored Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Something like

sar -u 1 10 |awk '{print $5}' | if [ "$5" -le 10 ]; then
echo "High CPU Utilization" | mailx -s 'subject' praveen@domain.com
fi

Note: You want to read %idle less then 10%.
Support Fatherhood - Stop Family Law
Darrel Louis
Honored Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi praveen,

If Openview isn't in the scope of your budget, check for BigBrother which is free for non-commercial use.
http://www.bb4.org/

Darrel
Arturo Galbiati
Esteemed Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi,
If you have Glnace on your server I can send yu the script which sent by email an alert when 2 of the resources: memory, disc, cpu, swap are over a threshould.
Rgds,
Art
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

hi,
yes i have glance plus utility,
please send me the script
thanks in advance
Arturo Galbiati
Esteemed Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi,
you have to set the varaiabile MaiAdd with your email address.
HTH,
Art
Raimo Lesonen_1
Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

This one checks if cpu-load average gets over 90% in the past hour. I find it better than just check sudden peaks.

LIMIT="90"
let VALUE=100-$(sar -s$(( $(date +%H)-1))|tail -1|awk '{print $5}')
if [ "$VALUE" -gt "$LIMIT" ]
then
mailx ...
fi
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi,
thanks for sending me the scripts.
please let me know how to configure it and is there any need to make some entries in crontab?

please let me know the full steps to use this scripts

thanks for your support.
Arturo Galbiati
Esteemed Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi,
set the variabile MaiAdd to your email a ddress and add in crontab to run every 10 minutes:
3,13,23,33,43,53 * * * * res-cop-alert.ksh 90 >/tmp/res-cop-alert.log 2>71

I suggest you to perform some runs manually to understand how the script works.

HTH,
Art
Steven E. Protter
Exalted Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Shalom praveen,

You don't want to do this. Its perfectly normal for a system even with low usage, to jump over 90% CPU user once in a while.

You will find the alerts to be unhelpful.

What I recommend to do is use the code provided above to alert you when usage has been over 90% for a certain period of time.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

hi steven,
you are talking about which code?

can you please give me the full details to use that code.

thanks
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

i copied this script in /tmp directory and added my email address in MaiAdd.

#cd /tmp
#ll
total 16
-rw-r--r-- 1 root sys 2306 Jun 19 04:43 277457.ksh
#mv 277457.ksh cpu_alert.ksh
# chmod 777 cpu_alert.ksh
#ll
total 16
-rwxrwxrwx 1 root sys 2306 Jun 19 04:43 cpu_alert.ksh
#ksh ./cpu_alert.ksh



./cpu_alert.ksh[3]: ^M: is not an identifier
logout root
#
#

what is this error?
Pete Randall
Outstanding Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Usually ^M is a carriage return that results from migrating code from dos to unix. I would suggest running your code through the dos2ux command:

dos2ux cpu_alert.ksh > /tmp/cpu_alert.ksh
mv /tmp/cpu_alert.ksh cpu_alert.ksh


Pete

Pete
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

#cd /tmp
#ll
total 16
-rwxrwxrwx 1 root sys 2306 Jun 19 04:43 cpu_alert.ksh

should i run these two commands, cpu_alert.ksh is in /tmp directory.

#dos2ux cpu_alert.ksh > /tmp/cpu_alert.ksh
#mv /tmp/cpu_alert.ksh cpu_alert.ksh

and now which command i need to use to run this script?
Arunvijai_4
Honored Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi,

You can just # chmod 555 cpu_alert.ksh and
# ./cpu_alert.ksh to run the script

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

[/tmp]# ll
total 16
-rwxrwxrwx 1 root sys 2306 Jun 19 04:43 cpu_alert.ksh
[/tmp]# dos2ux cpu_alert.ksh >/tmp/cpu_alert.ksh
[/tmp]# ll
total 0
-rwxrwxrwx 1 root sys 0 Jun 19 05:33 cpu_alert.ksh

why it is making this file of 0 bytes?
Arunvijai_4
Honored Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi Praveen,

Do a # strings cpu_alert.ksh > /tmp/cpu_alert.ksh

It should work.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

it is also making it of 0 byte.

tmp]# ll
total 32
-rw-r--r-- 1 root sys 2306 Jun 19 04:43 277457.ksh
-r-xr-xr-x 1 root sys 2306 Jun 19 06:09 cpu_alert.ksh
[/tmp]# strings cpu_alert.ksh >/tmp/cpu_alert.ksh
[/tmp]# ll
total 16
-rw-r--r-- 1 root sys 2306 Jun 19 04:43 277457.ksh
-r-xr-xr-x 1 root sys 0 Jun 19 06:10 cpu_alert.ksh
James R. Ferguson
Acclaimed Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi Praveen:

If you are 'cd'ed to the '/tmp' directory and you do:

# dos2ux cpu_alert.ksh >/tmp/cpu_alert.ksh

Then, you are actually truncating the file before you begin filtering it! This nulls the file. That is the reason your file is now 0-byes long.

You should *change* the name of the output file to differ from its input file in this case.

Regards!

...JRF...
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

#cd /tmp
#dos2ux cpu_alert.ksh >/tmp/cpualert.ksh
#./cpualert.ksh
*** Can't find server name for address 170.120.6.12: Query refused
*** Can't find server name for address 170.120.6.13: Query refused
*** Default servers are not available
./cpualert.ksh[57]: DebFlg: parameter not set
logout root
#

why i am getting this error?

everytime i am getting two more files in /tmp directory with name "root*****.err" & "root*****.out".
#cd /tmp
#ll
-rwxr-xr-x 1 root sys 2220 Jun 19 11:07 cpualert.ksh
-rw-r--r-- 1 root sys 233 Jun 19 11:41 gln_syntax_file
-rw-r--r-- 1 root sys 29 Jun 19 11:08 roota04239.err
-rw-r--r-- 1 root sys 37 Jun 19 11:08 roota04239.out
-rw-r--r-- 1 root sys 29 Jun 19 11:20 roota04599.err
-rw-r--r-- 1 root sys 74 Jun 19 11:20 roota04599.out
-rw-r--r-- 1 root sys 29 Jun 19 11:33 roota04977.err
-rw-r--r-- 1 root sys 74 Jun 19 11:33 roota04977.out
-rw-r--r-- 1 root sys 29 Jun 19 11:36 roota05039.err
-rw-r--r-- 1 root sys 74 Jun 19 11:36 roota05039.out
-rw-r--r-- 1 root sys 29 Jun 19 11:41 roota05141.err
-rw-r--r-- 1 root sys 74 Jun 19 11:41 roota05141.out

why are it not deleting the old files?
Yogeeraj_1
Honored Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

hi praveen,

a few comments:
1. You don't have to run the dos2ux command every time.
#dos2ux cpu_alert.ksh >/tmp/cpualert.ksh

2. Try to run the commands from the script individually to determine which command is causing the errors.

3. The deletion of th emporary files must be a logic in the script. So if there is no such commands in the script, these temporary files will be never deleted....

Hope this helps!

you may wish to post the content of the script here...




kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

script is already attached in the thread.

check above Arturo Galbiati's comment
praveen..
Super Advisor

Re: How can i generate the alterts if CPU utilization goes above 90%

can any body please help?
Arturo Galbiati
Esteemed Contributor

Re: How can i generate the alterts if CPU utilization goes above 90%

Hi Praveen,
sorry for late reply but I was in vacation.
The temporary files are deleted an the end oif teh script if all went fine, otherwise in case of error they remained on teh error to help you in debug. Please, could you post teh contnet of one of teh .err files?
In seems me that teh script failed.
Rgds,
Art