Simple monitoring

I was searhing for a simple monitoring tool but most tools out there are very complex. We use 3rd party virtual private servers now so hardware monitoring is not our business. We're interested in monitoring two things:

  1. Free disk space
  2. CPU load
So I use two simple scripts that send out an e-mail alert when the diskspace is low or the CPU load it too high.

You can create the two scripts below and edit the MAILTO and TRIGGER variables to suit your needs /usr/local/bin/monitor-load.sh:

#!/bin/bash
TRIGGER=2.00
MAILTO=mail@somedomain.com


host=`hostname -f`
load=`cat /proc/loadavg | awk '{print $2}'`
response=`echo | awk -v T=$TRIGGER -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'`
if [[ $response = "greater" ]]
then
        #capture top command output for the mail body
        body=`top -n 1 -b`

        echo "$body\n."|mail -s "High load on $host - [ $load ]" $MAILTO
fi
/usr/local/bin/monitor-disk-usage.sh:

#!/bin/bash
MAILTO=mail@somedomain.com
TRIGGER=80

HOST=`hostname -f`
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')

if [ "$CURRENT" -gt "$TRIGGER" ] ; then

    mail -s "Disk Space Alert for $HOST" $MAILTO << EOF
The root partition of '$HOST' remaining free space is critically low. Used: $CURRENT%
EOF
fi

Make these two scripts executable:
chmod +x /usr/local/bin/monitor-load.sh 
chmod +x /usr/local/bin/monitor-disk-usage.sh
Now schedule these script in system cron jobs:
/etc/cron.d/monitor:
# Check server load and diskspace
* * * * * root /usr/local/bin/monitor-load.sh
0 7,16 * * * root /usr/local/bin/monitor-disk-usage.sh
This will check the server load every minute and disk space at 7am and 4pm. Finally it's wise to test if mails sent from console arrive. Change the e-mail address in this command and run it:
echo "."|mail -s "Test mail from console" mail@somedomain.com

Comments


  • Pieter van de Ven
    April 07, 2016 at 09:18

    Hai Merijn,

    The last cronjob will run every minute from 7:00 to 7:59 and from 16:00 to 16:59.


  • Merijn Schering
    April 07, 2016 at 09:40

    Thanks! I've adjusted it.


  • Peter Stirnberg
    April 08, 2016 at 15:01

    Hi Merijn,

    nice scripts. We use dedicated hardware an monit for this purposes. I'll post a howto in the forum.


  • SAS Training
    August 16, 2016 at 13:51

    I recently joined a small team of people who have a lot of different small apps that include Celery, Django, Flask, Java, et al and now they are critical enough that they'd like to know if they are all working.

    What is a good monitoring and visualization tool to track custom events?

    Examples:

    1) Simple: We have a Python script that can test each service and test if it's working... but we would like to see a dashboard of: "when was the last time this was successfully tested?" so we can get a sense of availability... and maybe some trend graphs over time.

    2) We would like to track events to see when things overlap.

    Analyst #1 runs report A at 11:33am.
    Analyst #2 runs report B at 11:35am.
    Report B finishes at 11:40am.
    Report A finishes at 11:50am.
    I've done some searching but a lot of the projects seem to be unmaintained. So I'd like to know what the community here uses.

    Whatever we choose needs to be self-hostable internally as this environment is very locked down.

    Thanks. R Programming Training | DataStage Training | SQL Training| SAS Training | Android Training | SharePoint Training


  • make your own website business
    September 02, 2016 at 09:44

    The amazing things on this blog are what you have to write on a freedom spaces.

Back to Top
SourceForge.net Logo