Thursday, April 7, 2016

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/


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" ]]
        #capture top command output for the mail body
        body=`top -n 1 -b`

        echo "$body\n."|mail -s "High load on $host - [ $load ]" $MAILTO


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%

Make these two scripts executable:
chmod +x /usr/local/bin/ 
chmod +x /usr/local/bin/
Now schedule these script in system cron jobs:
# Check server load and diskspace
* * * * * root /usr/local/bin/
0 7,16 * * * root /usr/local/bin/
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"


  1. Hai Merijn,

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

  2. Hi Merijn,

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

  3. 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?


    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

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

  5. This comment has been removed by the author.

  6. This comment has been removed by the author.

  7. Really appreciate you sharing this post.Much thanks again. Keep writing.
    Windows Hosting India

  8. This is such a great resource that you are providing and you give it away for free. I love
    seeing that understand the value of providing a quality resource for free. :) :)
    bloons tower defense 5

  9. For any mobile app development , there is one company offering better prices in USA,

  10. For any mobile app development , there is one company offering better prices in USA,

  11. Thanks for info Merijn Schering,

    laptop rental dubai,

  12. google drive for pcApril 17, 2018 at 8:49 AM

    Very Interesting and wonderfull information keep sharing
    google drive for pc not syncing

  13. Useful information. Lucky me I discovered your website accidentally, and I am stunned why this twist of fate did not happened in advance! I bookmarked it.

  14. Very Informative article you have described everything in a brilliant way. This is really useful arrticle for begginer learner. Appreciated!

    Mobile Apps Training
    Mobile Apps Training in Chennai

  15. Great post and creative ideas. I am happy to visit and read useful articles here. I hope you continue to do the sharing through the post to the reader.

    AWS Online Training

    AWS Training