It is currently Sun May 20, 2018 7:58 am

Server load alert

All times are UTC - 6 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Feb 29, 2008 7:19 pm   

Joined: Wed Jul 04, 2007 5:11 pm
Posts: 8
Location: new york
Here is a simple script that will send an email to you when the server load reaches a certain level.



loadavg=$( cut -d' ' -f2 /proc/loadavg | cut -d. -f1 )
alarmme="[email protected]"

if [ $loadavg -gt "5" ] ; then
       echo "Hi the server load for the past 5 minutes is $loadavg" | mail -s "Alarm from $HOSTNAME" $alarmme ;


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.


 PostPosted: Mon Mar 03, 2008 5:38 am   
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 265
Location: London - UK
you can monitor many basic things with scripts such as these however you'll find that they're very limited. I strongly suggest using a monitoring system that is fully developed as you'll find significant advantages. I personally suggest Nagios but there are several about.

Nagios can auto restart services based on various criteria, inform support through a variety of systems and is easy to add extra checks to for your own custom software. All major and many minor services already have nagois plugins available.

 PostPosted: Fri Mar 07, 2008 2:21 pm   

Joined: Fri Mar 07, 2008 2:04 pm
Posts: 2
This is another one that can check tcp connections and alert you if they are greater than 100


connections=$( cat /proc/net/tcp | wc | cut -d' ' -f6 )
echo $connections;
alarmme="[email protected]"

if [ $connections -gt "102" ] ; then
echo "TCP connections has reached 100 connections" | mail -s "Alarm from $HOSTNAME" $alarmme ;

Take into account that the proc filesystem should be mounted in /proc


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group