Adding a Datastore to an RRD File

Mainly for personal future reference.

Adding a DS to a bunch of RRD files is a big pain, RRD doesn’t have any sort of native mechanism for doing this. The usual procedure is exporting the RRD data to XML, creating a new rrd file with the old datastores plus your new ones, then importing the data back in from the XML.

A while back I needed to do this for a load of RRDs so I wrote a quick and dirty bash script for it. Today I had reason to add a DS again but couldn’t find my script. A bit of googling was no help either, surely other people have this problem too? I discovered Nicola Worthington’s RRD::Simple contains add_source method so a few moments in TextMate later we have:

#!/usr/bin/perl

use strict;
use warnings;

use RRD::Simple();

my $rrd_path = "/path/to/dir/of/rrds/";
my @rrd_files = <$rrd_path/*.rrd>;

my $rrd = RRD::Simple->new();

for my $file (@rrd_files) {
    print "Processing $file...";
    $rrd->add_source($file, 'DS_name' => 'DERIVE');
    print " ok.\n";
}
This entry was posted in geek, neat and tagged , , . Bookmark the permalink.

6 Responses to Adding a Datastore to an RRD File

  1. Pingback: Pnp4nagios, adding a datasource to a rrd file (not only for pnp4nagios) « Erralt

  2. Serial says:

    Hi, i would like to thank you because your post was helpul for me.

  3. Chris Kelch says:

    Thanks, very helpful.

  4. Pingback: Temperaturmessung mit einem 10€ Eigenbau-Sensor « M8IN.DE

  5. Jeremy Fox says:

    Sweet script, just what I was looking for! Thx!

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>