# HOWTO: monitor load average of your  servers



## bsdvm (Jun 29, 2009)

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 (Jun 29, 2009)

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 (Jun 29, 2009)

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 (Jul 25, 2009)

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 

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


----------



## dennylin93 (Jul 29, 2009)

Munin is also useful (sysutils/munin-main and sysutils/munin-node), although not as powerful as Nagios.


----------



## vermaden (Jul 29, 2009)

@bsdvm

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


----------



## bsdvm (Jul 30, 2009)

*Thanks for replies*

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 "


----------

