Data logging and graphing using RRDtool

hourlyWhen it comes to logging some data over a long period of time, RRDtool is a convenient solution. Creating and updating the RRD database is simple, graphing is fairly easy as well. To make the graphs available over the web, I chose to install the lighttpd web server.

Getting the packages

opkg install rrdtool lighttpd

After installing lighttpd, I changed its port to 8090 to avoid interference with the service running on port 80. In /etc/lighttpd.conf:

## bind to port (default: 80)
server.port                = 8090

In the same file you can change the document-root if you wish, I left it unchanged:

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root        = "/www/pages/"

The scripts presented below are available in my GitHub repository:

Building the database

First of all, edit the LOG_CONFIG file:



The variable RRD_DB contains the path of the RRD database file, it will be created by The script will create the graph images in the directory defined by GRAPH_DIR. I set it to be the default root directory of lighttpd. GET_TEMP is the path of the executable which supplies the raw data. It must have an output format compatible with the rrdtool update syntax. In my case it is a sligthly modified version of the presented in the previous post.

source $(dirname $0)/LOG_CONFIG

rrdtool create $RRD_DB --start N --step 60 \
DS:temperature:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:60 \
RRA:AVERAGE:0.5:10:144 \

We create the RRD database starting from now (N), it will accept a new data point every 60 seconds. The name of the data source (DS) is “temperature”, it is of GUAGE type, RRD will consider it unkown if we don’t supply new data for 600 seconds. We store every the raw data of the past hour (averaging of 1, 60 samples) and the past day with averaging of 10 (144 samples).

Updating the database and graphing

source $(dirname $0)/LOG_CONFIG

rrdtool update $RRD_DB N:$TEMP

This code simply invokes our executable supplying the data point (a number) and adds it to the RRD database.

source $(dirname $0)/LOG_CONFIG



# past hour
rrdtool graph $GRAPH_DIR/hourly.png  \
--width 800 --height 200 \
--start -$HOUR  --end -1 \
--vertical-label "Temperature" \
--title "Inside temperature" \
DEF:temperature=$RRD_DB:temperature:AVERAGE \

# past day
rrdtool graph $GRAPH_DIR/daily.png \
--width 800 --height 200 \
--start -$DAY  --end -1 \
--vertical-label "Temperature" \
--title "Inside temperature" \
DEF:temperature=$RRD_DB:temperature:AVERAGE \

This script creates two graphs for us, one about the past hour and another one about the past day:



Simple HTML code to show both graphs on a single web page:


<img src="hourly.png">
<img src="daily.png">

Save it as index.html in the document-root of the web server, then check the web page on http://beagleboneIP:PORT. If your BeagleBone is behind a router and you want to access the webpage you have just created from anywhere, you have to set up port forwarding on your router. Furthermore, you may register for a dynamic DNS service to make yourself able using a domain name instead of the WAN IP of your router.

Making it automatic

To make the logging and graph publishing run every minute, add the following two lines to /etc/crontab with the proper paths:

*/1 * * * * root /home/root/ADS1248/
*/1 * * * * root /home/root/ADS1248/



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s