[rrd-users] Re: Neverending Spikes issue -- again

Todd Caine todd_caine at eli.net
Wed Feb 20 01:56:09 MET 2002


Sticking with Perl's motto of TMTOWTDI (there's more that one way to do it),
here is one implementation that does the following:

1.  Takes as arguments a source and destination RRD file
2.  Does a 'rrdtool dump' on the source RRD file to a pipe.
3.  The XML data is read from the pipe into XML::Parser and parsed
4.  Every time we see a <v> element we turn on the data flag
5.  If we parse some data and the flag is on send the data to munge_data()
6.  Every time we see a </v> element we turn off the data flag
7.  The whole xml file is sent into another pipe where 'rrdtool restore' is
waiting patiently  :)

Currently munge_data() only prints out the value of the data source but you
could easily modify this to do other things for you.  By the way every data
value is treated completely independent of every other data point.  There is
no correlation of data points between the various archives with this
implementation.

It seems to me that we could write some very useful tools for munging RRD
files after they have been created with techniques similar to this.

Cheers,
Todd

Przemyslaw Karwasiecki wrote:

> Any suggestions -- how efficiently iterate through content of DS
> in RRD file in order to do some massive processing.
> (possibly generating another RRD file with RRD:update?)

#!/usr/local/bin/perl -w

use strict;

use XML::Parser;

my $rrdtool = '/usr/local/bin/rrdtool';
my $rrdfile = shift || usage();
my $newfile = shift || usage();

my $p = new XML::Parser(Style => 'Stream');

my $data_flag = 0;

open(RRD, "$rrdtool dump $rrdfile |")
  or die "Can't dump $rrdfile: $!\n";

open(NEW, "| $rrdtool restore - $newfile")
  or die "Can't open $newfile: $!\n";

$p->parse(*RRD);

close RRD;
close NEW;

exit;


sub usage { die "$0 <rrd_file> <new_file>\n" }

sub StartTag {
    $data_flag = 1 if $_ eq '<v>';
    print NEW $_;
}

sub EndTag {
    $data_flag = 0 if $_ eq '</v>';
    print NEW $_;
}

sub Text {
    if($data_flag) {
        munge_data($_);
    }
    else {
        print NEW $_;
    }
}

sub munge_data {
  print NEW $_[0];
}




--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list