CMTS info

Helpful linux and DOCSIS/CMTS howtos and tips

RRDtool: The Ultra Quick Start Guide

1) Intro

There are tons of howtos/tutorials for RRDtool, however if you just want one graph most are pretty useless. I hope this one will get you through pretty quick.

2) Install

By default RRDtool wants to install itself in /opt. Not a good idea if you don't like to work. Also ldconfig must be run after install. Copy & paste:

  ./configure --prefix=/usr/local
  make install
3) Create a database

Lets say we want to create simplest DB with: temperature/current/total users or something similar.
I've numbered the lines. Remove numbering before you execute. Warning: No spaces after "\"!

Main data and daily graphs:
1: Nothing fancy here, we're creating test.rrd database with step 600sec. It means data should be collected every 600 sec = 10min.
2: First monitored atribute - IP. Since we want to create a gauge of some kind we will use GAUGE type. If we wanted to create traffic stats we would used COUNTER. Data must be fed to it at least every 1200 sec or it will be invalid. Minimal value - 0, Max value - U (unknown). Keep the step ratio 1:2 (in this case 600:1200)
3: Second attribute - CM.
4:Database for daily graphs. We take Average value out of 1 measurements and we keep 600 data samples - 100 hours.

Weekly graphs:
We take Average/Max/Min value out of 2 measurements (20 minutes) and we keep 576 data samples = 192 hours = 8 days.
5:Average values for weekly graphs.
6:Max values for weekly graphs.
7:Min values for weekly graphs.

Monthly graphs:
We take Average/Max/Min value out of 6 measurements (1 hour) and we keep 960 data samples - 40 days.
8:Average values for monthly graphs.
9:Max values for monthly graphs.
9:Min values for monthly graphs.

You get the point, right?

1:	rrdtool create test.rrd -s 600 \
2:	DS:IP:GAUGE:1200:0:U \
3:	DS:CM:GAUGE:1200:0:U \
4:	RRA:AVERAGE:0.5:1:600 \
5:	RRA:AVERAGE:0.5:2:576 \
6:	RRA:MAX:0.5:2:576 \
7:	RRA:MIN:0.5:2:576 \
8:	RRA:AVERAGE:0.5:6:960 \
9:	RRA:MAX:0.5:6:960 \
10:	RRA:MIN:0.5:6:960 
4) Get the data inside our database

Lets assume we've have data in bash variables named $IP and $CM. Updating our database in real time would look something tlike this:

rrdtool update /path/to/test.rrd N:$IP:$CM

After verifying it works, put that script to cron.

5) Draw a graph

Lets say we want to have a PNG daily graph in dimensions 600 by 200.
We also want to see the 0 mark and have a title of Graph generated at current_date.
Now for the RRDtool parts:
DEF statements specify that we take data from CM and IP fields from AVERAGE database.
AREA and LINE statements specify that an area or line will be drawn, with legend of Cable modems and IPs.
GPRINT prints some statistical data from cm and ip sources. "\j" is a newline.

rrdtool graph /path/to/graph.png -a PNG --lower-limit 0 \
--title="Graph generated at $Date"  -w $Width -h $Height \
'DEF:cm=/path/to/test.rrd:CM:AVERAGE' \
'DEF:ip=/path/to/test.rrd:IP:AVERAGE' \
'AREA:cm#00dd00:Cable modems' \
'LINE:ip#0000ff:IPs\l' \
"GPRINT:cm:LAST:Last CM\: %6.0lf %s" \
"GPRINT:cm:AVERAGE:Avg CM\: %6.0lf %s" \
"GPRINT:cm:MIN:Min CM\: %6.0lf %s" \
"GPRINT:cm:MAX:Max CM\: %6.0lf %s \j" \
"GPRINT:ip:LAST:Last IP\: %6.0lf %s" \
"GPRINT:ip:AVERAGE:Avg IP\: %6.0lf %s" \
"GPRINT:ip:MIN:Min IP\: %6.0lf %s" \
"GPRINT:ip:MAX:Max IP\: %6.0lf %s"

If we want to create weekly or monthly graphs simply add --start -1w or --start -1m to the command line. If you want to take advantage from Min and Max databases we've created before you need to add DEF statements that get data from those databases. Weekly graph below:

rrdtool graph /path/to/graph.png -a PNG --lower-limit 0 \
--title="IP usage - $Date"  -w $Width -h $Height --start -1w \
'DEF:cm=/path/to/test.rrd:CM:AVERAGE' \
'DEF:cm_min=/path/to/test.rrd:CM:MIN' \
'DEF:cm_max=/path/to/test.rrd:CM:MAX' \
'DEF:ip=/path/to/test.rrd:IP:AVERAGE' \
'DEF:ip_min=/path/to/test.rrd:IP:MIN' \
'DEF:ip_max=/path/to/test.rrd:IP:MAX' \
'AREA:cm#00dd00:Cable modems' \
'LINE:ip#0000ff:IPs\l' \
"GPRINT:cm:LAST:Last CM\: %6.0lf %s" \
"GPRINT:cm:AVERAGE:Avg CM\: %6.0lf %s" \
"GPRINT:cm_min:MIN:Min CM\: %6.0lf %s" \
"GPRINT:cm_max:MAX:Max CM\: %6.0lf %s \j" \
"GPRINT:ip:LAST:Last IP\: %6.0lf %s" \
"GPRINT:ip:AVERAGE:Avg IP\: %6.0lf %s" \
"GPRINT:ip_min:MIN:Min IP\: %6.0lf %s" \
"GPRINT:ip_max:MAX:Max IP\: %6.0lf %s"

Template: on license
All trademarks belong to their respective owners. All materials presented here for informational purposes only.