PDA

View Full Version : HOWTO: monitor load average of your servers


bsdvm
June 29th, 2009, 08:50
Many times I came across the problem, that when you need to instantly monitor the load average of your servers it is not very comfortable to stare at the console. Especially when you need to know what was going on when you were sleeping ;). So I wrote a very basic script for monitoring purposes. When load average is higher than it should be an email notification will be sent to specified address. Feel free to modify it ;).

#!/bin/sh

MAX_LAVG=1 #set the MAX load average value
EMAIL=your@email.here #set the email to send the notification
INTERVAL=30 #set the time interval in seconds to check the load average value

while sleep $INTERVAL
do

LAVG=$(uptime | awk '{gsub(",",""); print $10}')

MLAVG=`echo $LAVG|awk -F \. '{print $1}'`
if [ "$MLAVG" -ge "$MAX_LAVG" ]; then

SUBJECT="$(hostname) LOAD AVERAGE ALERT $LAVG (>$MAX_LAVG)"
EMAILMESSAGE="WARNING! Load average is $LAVG an is more than $MAX_LAVG on $(date)"

echo $EMAILMESSAGE | mail -s "$SUBJECT" "$EMAIL"
fi
done

vivek
June 29th, 2009, 10:18
Really bad idea, server load may spike for few seconds or minutes and it will sent an email. You may wanna modify script so that if last 15 minutes average is above 5 or something like that. A better solution is monit or other such tools.

bsdvm
June 29th, 2009, 11:00
30 seconds INTERVAL is just an example. Anyone can set his own value. I do usually set 600 seconds interval. So if there is a spike for a few seconds/minutes email won't be sent.

Maurovale
July 25th, 2009, 15:18
Hi for a lot of servers I use nagios, to monitor load average, Disks, memory and latency.

Nagios can send you sms, emal and jabber alerts, and create various users and timetables to receive the alerts, very good indeed :P

When I have time I will try zenoss - http://www.zenoss.com/community/open-source-network-monitoring-software/)

dennylin93
July 29th, 2009, 10:11
Munin is also useful (sysutils/munin-main and sysutils/munin-node), although not as powerful as Nagios.

vermaden
July 29th, 2009, 10:28
@bsdvm

If you want to monitor load, then check bsdsar(1):
http://freshports.org/sysutils/bsdsar

bsdvm
July 30th, 2009, 11:02
Thanks to all for replies.
I'm using nagios as well for some of my servers.

@vermaden
Will try bsdsar(1) when I have some spare time. Thanks.

Probably should had given this post slightly another title like:
" Quick script to monitor load average " :P