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@192.168.0.1
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 ./bmp085.py 11 4 # read temp
0
24
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
24
35
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.
mrtg-ping-probe 192.168.0.1
24
133
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/bmp085.py`
MaxBytes[temp2]: 100
YLegend[temp2]: Deg
Legend1[temp2]: .
Legend2[temp2]: .
Legend3[temp2]: .
Legend4[temp2]: .
LegendO[temp2]:Events
LegendI[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>
Hi, could you publish your DHT11 script you use with mrtg
Thanks
Aaron