Friday, 12 May 2017


RRDTool is a very cool round robin database and graph generation tool. There is a lot of documentation around the web - if you got the time (and patience).

The idea of a RRD  is a fixed number of sample data points in a given database. The size of the database is defined at its creation time. The advantage of such a database is that the space allocated is fixed, and there s no danger of running out of storage space, ever; hence it is ideal for embedded / low resource systems.

Creating a database

rrdtool create eth0.rrd \
	--start now   \
	--step 60	\
	DS:ina:GAUGE:120:U:U  \
	DS:outa:GAUGE:120:U:U  \
	DS:in:DERIVE:120:U:U  \
	DS:out:DERIVE:120:U:U  \
	RRA:LAST:0.5:1:10  RRA:AVERAGE:0.5:5:10 
eth0.rrd is the name of the database (saved filename)
--start  means when do we start populating the database 
--step means sample size in seconds ( enter data every minute  - will get a cron job to do this)
DS  - definition of a dataset: label : type  : heartbeat : lower limit : upper limit
type  can be of :
GAUGE  - save the value vithout any modification  
COUNTER - save the rate (current - last) / sampletime 
DERIVE - same as about with over/underflow adjust
ABSOLUTE - for data which gets reset when read

The key thing to remember is, the data gets modified before saving, for counter,derive types by rrdtool. Counter / Derive is ideal for saving data such as bitrate - as it is computed at ever sampling point, and then saved.

In above database each data entry point will need 4 bits of data (= number of DS definitions)
First two data will be saved as absolute values, next two will be saved as rate values. (in this case it will only start updating database after 2 sets of data has received. We the also define two Round Robin Archives :
RRA:LAST:0.5:1:10    - holds 10 absolute values, updated every minute
RRA:AVERAGE:0.5:5:10 - holds 10 values, averaged every 5 minutes

Instead of creating multiple RRA's  one can have a single RRA , with 1 minute resolution. 
The following will create a foo.rra which hold an year's worth of data in 1 minute resolution:
rrdtool create foo.rrd \
	--start now   \
	--step 60	\
	DS:in:DERIVE:120:U:U  \
	DS:out:DERIVE:120:U:U  \
and the datebase will only take 8MB of space -Incredibly efficient !                                                                                                                            

Inserting data

As defined in the DS section, we must insert 4 data values at every minute (at every sample point). The command to do so is:
rrdtool update eth0.rrd N:<value>:<value>:<value>:<value>
N neans "now" - inserts the current timestamp. If samples arrive faster than the intended sample time (60 secs) the database will not be updated

Dumping out the contents of RRD

rrdtool dump eth0.rrd  will dump out the contents in xml

Creating pretty graphs ..

coming soon