RRDtool

RRDtool is a useful tool for logging and graphing data that is collected at regular time intervals and kept for a limited amount of time. Whereas with a traditional database, you would need to periodically remove old entries to keep the size down, RRDs (Round Robin Databases) are a constant size and keep only the last n samples (where you define what n is). In that way, RRDs are akin to a circular buffer or a sliding window. RRDtool also allows consolidating the data with various functions (average, min, max, etc.), graphing, and APIs for popular languages such as Perl, Python, and Ruby.

Here’s a tutorial on RRDtool that explains the tool pretty succintly.

And here’s a concise little example to give you an idea of how it works:

rrdtool create target.rrd \
        --start 1023654125 \
        --step 300 \
        DS:mem:GAUGE:600:0:671744 \
        RRA:AVERAGE:0.5:12:24 \
        RRA:AVERAGE:0.5:288:31

What this does is create a file called target.rrd. We are going to start measuring data at epoch time (Unix time, time in seconds since 01-01-1970) 1023654125 and the tool is going to expect input measurements every 300 seconds (5 minutes). We’re measuring something called mem which can range in value from 0 to 671744. We’re going to average each 12 measurements (at 5 minutes apiece this will cover 1 hour) and keep 24 of those and we’re also going to average each 288 (at 5 minutes apiece this will cover 24 hours) and keep 31. The 600 represents a “heartbeat” which is how long the system will go without a measurement before it logs “unknown” for the period in question. The 0.5 in the two RRA lines is saying that the average can be computed as long as least half of the measurements are present; otherwise it will be considered “unknown”. Once you have this, you can use other rrdtool commands to fetch the data and create graphs. These are the basics, for more details check out the man page or some of the tutorials that I referenced above.

An interesting-looking package built on top of RRDtool is Cacti. Cacti is a complete frontend to RRDtool, it stores all of the necessary information to create graphs and populate them with data in a MySQL database. The frontend is completely PHP driven. Along with being able to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering. There is also SNMP support for those used to creating traffic graphs with MRTG.

Leave a Reply

Your email address will not be published. Required fields are marked *