email when unix system CPU usage is above 70%
Hey Colleagues;
I need to write a shell script that will send me an email when unix system CPU usage is bove 70% threshold, will really appreciate your response as i equally put it together from my end. |
70% of one processor usage? 70% of all procs? Do you include hyper-threading virtual procs in this count? 70% instantaneous or time-averaged? Over what length of time? When the limit is exceeded, how do you want to handle emails. Every minute while it's over the limit? Every 5 minutes? Once when it passes the limit and not again until it drops back below for at least XX minutes, then rises back above?
|
When 70% of all processes, an email should be sent to a specified email id with a subject "WARNING CPU USAGE HIGH"
|
That answered one of the five questions that were asked.
You can't expect to tackle a problem (or have somebody else tackle the problem for you) if you can't define it properly. |
Quote:
|
Let me be more explicit
I intend to explain in details what i really want so i can get suport easily from you guys, i want a script that can monitor CPU usage of unix system so that if the CPU usage is more than 70% your script will send out email saying that CPU is more than threshold of 70%. I created the below script but it did send a warning email but the percentage was wrong when compared to the result when i use the "top" command.
#!/bin/sh #Date = 10/18/2013 #Set the alarm threshold here #Set to 70 to make it send notifications if average utilization goes past 70% THRESHOLD=70 MAILTO="meray@company.com" #The temp file below will be replaced everytime this script runs TEMPFILE=/tmp/cpu.temp # #LOGIC BLOCK: # HOSTNAME=`isbinf03` rm -f $TEMPFILE #Calculate the CPU Utilization with the command below #Note: this command will calculate the avg CPU utilization of last 10 secs CPU=$(vmstat 10 2 | tail -1 | awk '{print $15}' | sed 's/%//') let "CPU = 100 - $CPU" #echo "`date` - CPU Utilization: $CPU" #Compare the current value with the threshold one. if [ $(expr $CPU ">=" $THRESHOLD) -ne 0 ] then echo "Warning - CPU utilization on server $HOSTNAME is ${CPU}%" >> $TEMPFILE fi #Send an email if /tmp/cpu.temp is present. if [ -e $TEMPFILE ] then mail -s "$HOSTNAME CPU Warning" $MAILTO < $TEMPFILE fi rm -f $TEMPFILE once again i will appreciate your help. |
It would help if you read http://en.wikipedia.org/wiki/Load_%28computing%29 as it shows you how to calculate CPU usage like you should?
|
All times are GMT -5. The time now is 10:46 PM. |