A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Raspberry pi server monitoring with MRTG

A number of projects have been created to log sensor data from various things such as temperature or server availability etc. One of the most popular ways has been to use the cosm website or to write to google docs.

In a previous experiment I used mrtg to create graphs on my own web server. So having a spare raspberry pi and a bunch of scripts from other people I hacked it all together…

Some example graphs:-

 The first one is my router throughput and the second is a temperature sensor






I’ll start with simply gettung mrtg to run on the Pi and then show how to log other things.  Currently I’m logging two different temperature sensors, pressure, humidity, ping response from 2 servers and my adsl router usage.

First step is to install apache web server and mrtg.

This post may help

sudo apt-get install apache2 php5 libapache2-mod-php5

type “sudo groupadd www-data”, then
“sudo usermod -g www-data www-data”.
Now restart apache with
“sudo service apache2 restart”.

Then install mrtg. Amongst the other web sites, this one provides a lot of hints and tips.

Sudo apt-get install mrtg

Create the mrtg work directory

Sudo mkdir /var/www/mrtg

You will need to enable snmp on your router and change the community string from public to a more secure value. In this case we will use ‘community’

Assuming this is done then create an mrtgconfig file. Replacing the ip address below for yours.

sudo cfgmaker –output=/etc/mrtg.cfg  –global “workdir: /var/www/mrtg” community@

This looks at the snmp mibs in your router and creates a standard cfg file.

Next we need to create the html file to display the graphs.

Sudo indexmaker –output=/var/www/mrtg/index.html /etc/mrtg.cfg

Finally we need to set a cron job to refreshh the graphs every 5 mins.

Edit the cron file.

Sudo nano /etc/cron.d/mrtg

To add the line

*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log

This line may already be configured by MRTG. Essenstially it causes MRTG to run every 5 minutes and read the config file /etc/mrtg.cfg. The graph will then be output into the /var/www/mrtg directory where it is then displayed precio del viagra using thr /var/www/mrtg/index.html file.

MRTG can be used to graph many other data series. All it needs is 2 values output to the screen. So a simple script for the temperature sensor just needs to return two values. e.g. the command:-

sudo ./ 11 4 # read temp



MRTG would then plot the two series as 0 and 24. In my example only 1 value is significant as the sensor only provides temperature. Another example may provide temperature and humidity. e.g.

sudo ./dht11 11 4



MRTG can then plot the two values on the same graph.

To plot ping stats for an IP address i installed mrtg-ping-probe. This just returns a couple of values. e.g.




In order to get mrtg to add thes feature we need to add another element to the config file

A sample cfg file…

Target[temp2]: `/home/pi/bmp085/`

 MaxBytes[temp2]: 100

YLegend[temp2]: Deg

Legend1[temp2]: .

Legend2[temp2]: .

Legend3[temp2]: .

Legend4[temp2]: .



ShortLegend[temp2]: Temp

Title[temp2]: Temp2

Options[temp2]: gauge, nopercent, integer, unknaszero

Colours[temp2]: GREEN#00eb0c,BLUE#0000ff,GRAY#AAAAAA,VIOLET#ff00ff

WithPeak[temp2]: ymw

PageTop[temp2]: <H1>Temp2</H1>




1 comment to Raspberry pi server monitoring with MRTG

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>