Frank4DD, @2008-2010
Introduction
RRD stands for Round Robin Database, which works with a pre-configured, fixed amount of data. It's best known implementation, RRDtool, is at the heart of many monitoring and graphing systems, providing a convenient way to organize measurements against a timescale.
Accessing RRD databases from Perl
RRDtool provides a Perl module called RRDs for easy manipulation of RRD databases. However with documentation being minimal, the following test program demonstrates how to access and retrieve RRD information.
#!/usr/bin/perl
# ###################################################################### #
# file: rrd-ds-extraction-example.pl v1.0 #
# purpose: Tests extracting the data source information from RRD's #
# author: 02/23/2012 Frank4DD #
# #
# This program prints the data source names from a Nagiosgraph test RRD. #
# ###################################################################### #
use RRDs;
$rrdfile = "/srv/app/nagiosgraph/rrd/susie114/os_memory___memory.rrd";
# First, we load the RRD properties into a hash
$hash = RRDs::info $rrdfile;
foreach my $key (keys %$hash){
# Debug: print all hash information:
#print $key." = ".$hash->{$key}."\n";
# Select the information for the data sources, starting with 'ds':
#
# key = value
# ---------------+------
# ds[swap].index = 1
# ds[ram].index = 0
if ($key =~ /ds\[(.*)\].index/) {
# The datasource name is inside brackets, here we extract them:
$dsname = substr($key, index($key,"[")+1, rindex($key,"]")-index($key,"[")-1);
print "DS: ".$dsname."\n";
}
}
exit;
A test run of this program returns the following output:
susie114:/home/fm # ./rrd-ds-extraction-example.pl DS: swap DS: ram