Hackosis is an Open Blog. You Can Participate.

  • 26
  • Jan

Monitoring your website on a shared host is vital to the well being of your existence on the internet. There are several online services that will do this for you in exchange for a small price. While they may be a bit more accurate, I would like to share with you how to use RRDTool to monitor your website’s response time yourself.

RRDTool Ping Graph
image via rrdwiki (didn’t use mine because it hasn’t completed a full cycle yet.)

NOTE: I am using Ubuntu based Linux Mint. This process should be the same on other Debian based distributions. If you are not running a Debian based distribution, you may have to modify some paths to the rrdtool executable. Some of this procedure has been taken from the rrdwiki.

The first step is to install RRDTool:

  1. sudo apt-get install rrdtool


Now we need to create 4 files to configure our monitoring. I created all of these in my /home//hackping/ directory.

hackping.conf (replace HOST and variable appropriately):

  1. #!/bin/bash
  2.  
  3. RRDTOOL=‘/usr/bin/rrdtool’
  4. FILE=‘/home/<username>/hackping/ping.rrd’
  5. HOST=‘hackosis.com’
  6. OUTPUT=‘/home/<username>/hackping/ping.png’

create.sh:

  1. #!/bin/bash
  2.  
  3. . /home/<username>/hackping/hackping.conf
  4.  
  5. $RRDTOOL create $FILE -s 60 \
  6. DS:ping:GAUGE:120:0:65535 \
  7. RRA:AVERAGE:0.5:1:2880

graph.sh:

  1. #!/bin/bash
  2.  
  3. . /home/<username>/hackping/hackping.conf
  4.  
  5. $RRDTOOL graph $OUTPUT \
  6.         -t "WAN Ping" -v "Time in ms" \
  7.         –start="now-1d" \
  8.         –end="now" \
  9.         –height="400" \
  10.         –width="700" \
  11.         -c "BACK#000000" \
  12.         -c "SHADEA#000000" \
  13.         -c "SHADEB#000000" \
  14.         -c "FONT#DDDDDD" \
  15.         -c "CANVAS#202020" \
  16.         -c "GRID#666666" \
  17.         -c "MGRID#AAAAAA" \
  18.         -c "FRAME#202020" \
  19.         -c "ARROW#FFFFFF" \
  20.         "DEF:ping_time=$FILE:ping:AVERAGE" \
  21.         "CDEF:shading2=ping_time,0.98,*" "AREA:shading2#F90000:$HOST" \
  22.         "GPRINT:ping_time:LAST:Last\: %5.2lf ms" \
  23.         "GPRINT:ping_time:MIN:Min\: %5.2lf ms" \
  24.         "GPRINT:ping_time:MAX:Max\: %5.2lf ms" \
  25.         "GPRINT:ping_time:AVERAGE:Avg\: %5.2lf ms" \
  26.         "CDEF:shading10=ping_time,0.90,*" "AREA:shading10#E10000" \
  27.         "CDEF:shading15=ping_time,0.85,*" "AREA:shading15#D20000" \
  28.         "CDEF:shading20=ping_time,0.80,*" "AREA:shading20#C30000" \
  29.         "CDEF:shading25=ping_time,0.75,*" "AREA:shading25#B40000" \
  30.         "CDEF:shading30=ping_time,0.70,*" "AREA:shading30#A50000" \
  31.         "CDEF:shading35=ping_time,0.65,*" "AREA:shading35#960000" \
  32.         "CDEF:shading40=ping_time,0.60,*" "AREA:shading40#870000" \
  33.         "CDEF:shading45=ping_time,0.55,*" "AREA:shading45#780000" \
  34.         "CDEF:shading50=ping_time,0.50,*" "AREA:shading50#690000" \
  35.         "CDEF:shading55=ping_time,0.45,*" "AREA:shading55#5A0000" \
  36.         "CDEF:shading60=ping_time,0.40,*" "AREA:shading60#4B0000" \
  37.         "CDEF:shading65=ping_time,0.35,*" "AREA:shading65#3C0000" \
  38.         "CDEF:shading70=ping_time,0.30,*" "AREA:shading70#2D0000" \
  39.         "CDEF:shading75=ping_time,0.25,*" "AREA:shading75#180000" \
  40.         "CDEF:shading80=ping_time,0.20,*" "AREA:shading80#0F0000" \
  41.         "CDEF:shading85=ping_time,0.15,*" "AREA:shading85#000000" >/dev/null

update.sh:

  1. #!/bin/bash
  2.  
  3. . /home/<username>/hackping/hackping.conf
  4.  
  5. UPDATECMD=$(ping -c 3 -w 6 $HOST | grep rtt | awk -F "/" ‘{ print $5 }’
  6. )
  7.  
  8. $RRDTOOL update $FILE N:$UPDATECMD

After creating the files, feel free to modify the colors, etc in the graph.sh file. For more info on the different parameters and syntax check the RRDGraph manpage.

Make the script files executable:

  1. chmod u+x /home/<username>/hackping/*

The only thing left to do is add some entries into crontab to automatically update the RRD database every one minute and the graph image every ten minutes:

  1. crontab -e

Enter the following into the crontab:

  1. * * * * * /home/<username>/hackping/update.sh
  2. 0,10,20,30,40,50 * * * * /home/<username>/hackping/graph.sh

And that is it! The script will create an image called ping.png that will represt the RRD data. The graph will hold data for the past 24 hours. You could even extend this by creating a cron script to automatically upload the graph image to your website for viewing anywhere. I hope this helps you monitor your website so you can tell when the site might be getting high traffic volume, or other websites on your shared host are taking up your resources, etc.

If you have any more tips on monitoring websites, please share in the comments.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts


Tags: , , , , , ,

Like this post? Subscibe to the RSS feed.


3 Comments

  1. Berta Says:

    Thanks for the post. It is very useful for me.

  2. GrokCode Says:

    Hey sweet post. Thats a pretty nice looking graph too.

    I’d like to set something like this up, although my internet connection isn’t always that great so my results might not be that reflective of what other people see.

  3. Shane Says:

    GrokCode,

    Very good point. This is dependent on your Internet connection, so results may vary.

Leave a Comment