I modified a simple script to allow me to do just that and then ran it from cron. Only problem is that if it detects a high load, an email is sent each time the cron is run (maybe every 5 minutes!)
!/bin/bashCron might look something like this:
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"
if [ $cur -ge 1 ]; then
info1="Server load is high presently"
touch /tmp/tmp.00
echo -e "$str\n$info\n$info1\n$str\n" >> /tmp/tmp.00
ps aux | head -1 >> /tmp/tmp.00
ps aux | sort -rn +2 | head -10 >> /tmp/tmp.00;
mail -s "Alert: Load Average for `hostname` on `date` " jeremy@yourdomainnamehere.com < /tmp/tmp.00;
rm -f /tmp/tmp.00
else
#echo -e "$str\n$info\n$str"
fi
*/5 * * * * /usr/local/bin/loadaverage
No comments:
Post a Comment