[rrd-users] adding datasources to existing RRDs using XML

Selena M Brewington smbrewin at ichips.intel.com
Tue Jan 11 21:27:26 MET 2000



I have several thousand RRDs that I want to add a couple datasources to, and 
I've tested out a script that seems to do the right thing.  I go through
each directory that has rrds, dump out xml, change the xml and reform the
rrds.  Below is the part of the scripts that reforms the xml.  Could someone 
tell me if I did this correctly?  One of the things I am wondering is if
using NaN vs. 0 makes much of a difference in the rows and the PDP entries I
am altering/adding.  I tried it out on a few RRDs and it seems to work.

example of usage:

cat my-rrd.xml | ./add-ds.pl 2 > my-rrd2.xml

-selena

---

#!/usr/bin/perl -w

use strict;

my $ds = shift || die "need number of additional datasources desired";
if ($ds eq '-h') {
  &Usage;
  exit 0;
}

my $default_val = shift || '0';
my $type = shift || 'COUNTER';
my $heartbeat = shift || '1800';
my $rrdmin = shift || 'NaN';
my $rrdmax = shift || 'NaN';

my $cdp_prep_end = '</cdp_prep>';

my $row_end = '</row>';
my $name = '<name>';
my $name_end = '</name>';

my $field = '<v> ' . $default_val . ' </v>';

my $found_ds = 0;
my $num_sources = 0;
my $last;
my $fields = " ";
my $datasource;
my $x;

while (<STDIN>) {

  if (($_ =~ s/$row_end$/$fields$row_end/) && $found_ds) {
    # need to hit <ds> types first, if we don't, we're screwed
    print $_; 

  } elsif (/$cdp_prep_end/) {
    print $last x $ds;
    print $_;

  } elsif (/$name_end$/) {
    ($datasource) = /$name (\w+)/;
    $found_ds++;
    print $_;

  } elsif (/Round Robin Archives/) {
    # print out additional datasource definitions

    ($num_sources) = ($datasource =~ /(\d+)/);
    
    for ($x = $num_sources+1; $x < $num_sources+$ds+1; $x++) {

      $fields .= $field;
      
      print "\n\t<ds>\n";
      print "\t\t<name> ds$x <\/name>\n";
      print "\t\t<type> $type <\/type>\n";
      print "\t\t<minimal_heartbeat> $heartbeat <\/minimal_heartbeat>\n";
      print "\t\t<min> $rrdmin <\/min>\n";
      print "\t\t<max> $rrdmax <\/max>\n\n";
      print "\t\t<!-- PDP Status-->\n";
      print "\t\t<last_ds> 0 <\/last_ds>\n";
      print "\t\t<value> 0 <\/value>\n";
      print "\t\t<unknown_sec> 0 <\/unknown_sec>\n"; 
      print "\t<\/ds>\n\n";

    }

    print $_;
  } else {
    print $_;
  }

  $last = $_;
}

sub Usage {

  print "add-ds.pl <add'l ds> [default_val] [type] [heartbeat] [rrdmin] [rrdmax] < file.xml\n";
  print "\t<add'l ds>\tnumber of additional datasources\n";
  print "\t[default_val]\tdefault value to be entered in add'l fields\n";
  print "\t[type]\ttype of datasource (i.e. COUNTER, GAUGE...)\n";
  print "\t[heatbeat]\tlength of time in seconds before RRD thinks your DS is dead\n";
  print "\t[rrdmin]\tminimum value allowed for each datasource\n";
  print "\t[rrdmax]\tmax value allowed for each datasource\n";
}

--
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



More information about the rrd-users mailing list