Here is a simple script that will send an email to you when the server load reaches a certain level.
Code:
#!/bin/bash
loadavg=$( cut -d' ' -f2 /proc/loadavg | cut -d. -f1 )
alarmme="youremail@yourdomain.com"
if [ $loadavg -gt "5" ] ; then
echo "Hi the server load for the past 5 minutes is $loadavg" | mail -s "Alarm from $HOSTNAME" $alarmme ;
fi
This alert is for a server that has been running with a server load of 5 or greater for the past 5 minutes.
it queries /proc/loadavg
here is what this shows on my computer
1.33 1.62 1.59 10/275 8241
the first 3 fields are server load at 1 minute then at 5 minutes and then 15 minutes.
so basically I need the second field
i end up with 1.62
then I use cut to only get the number before the period. I don't care about the decimals.
cut -d. -f1
i will end up with the number 1
then evaluate the result against the number 5 which is server load that i want to be notified.
if [ $loadavg -gt "5" ]
then if that condition is met it will send me a message and alertme when the server load has been over 5 for over 5 minutes
you can change the limit to your needs.
thanks.