#! /usr/bin/perl # add_ds.pl, program to add datasources to an existing RRD # # Copyright (C) 2000 Selena M. Brewington # fixed 30-JUL-2003 by Taylor A. Steil # verified working with rrdtool version 1.1.x # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use strict; my $ds = shift || die "need number of additional datasources desired"; if ($ds eq '-h') { &Usage; exit 0; } my $default_val = shift || 'NaN'; my $type = shift || 'GAUGE'; my $heartbeat = shift || '1800'; my $rrdmin = shift || '0'; my $rrdmax = shift || 'NaN'; my $cdp_prep_start = ''; my $cdp_prep_end = ''; my $row_end = ''; my $name = ''; my $name_end = ''; my $ds_end = ''; my $field = ' ' . $default_val . ' '; my $found_ds = 0; my $num_sources = 0; my $last; my $fields = " "; my $datasource; my $record; my $x; my $dsData; while () { if (/$cdp_prep_start/) { $record = 1; } elsif ($record) { if (/$ds_end/) { $dsData .= $_; $record = 0; } else { my $line = $_; if ($line =~ s/()(.*?)(<\/minimal_heartbeat>)/$1 $2 $3/) {} elsif ($line =~ s/()(.*?)(<\/min>)/$1 $rrdmin $3/) {} elsif ($line =~ s/()(.*?)(<\/max>)/$1 $rrdmax $3/) {} elsif ($line =~ s/()(.*?)(<\/last_ds>)/$1 UNKN $3/) {} elsif ($line =~ s/()(.*?)(<\/value>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/unknown_sec>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/primary_value>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/secondary_value>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/intercept>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/last_intercept>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/slope>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/last_slope>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/nan_count>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/last_nan_count>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/seasonal>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/last_seasonal>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/init_flag>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/history>)/$1 $default_val $3/) {} elsif ($line =~ s/()(.*?)(<\/unknown_datapoints>)/$1 $default_val $3/) {} elsif ($line =~ s/(<\w+>)(.*?)(<\/\w+>)/$1 $default_val $3/) {} $dsData .= $line; } } if (($_ =~ s/$row_end$/$fields$row_end/) && $found_ds) { # need to hit types first, if we don't, we're screwed print $_; } elsif (/$cdp_prep_end/) { print $dsData x $ds; print $_; $dsData = ''; } 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\n"; print "\t\t ds$x <\/name>\n"; print "\t\t $type <\/type>\n"; print "\t\t $heartbeat <\/minimal_heartbeat>\n"; print "\t\t $rrdmin <\/min>\n"; print "\t\t $rrdmax <\/max>\n\n"; print "\t\t\n"; print "\t\t NaN <\/last_ds>\n"; print "\t\t 0.0000000000e+00 <\/value>\n"; print "\t\t NaN <\/unknown_sec>\n"; print "\t<\/ds>\n\n"; } print $_; } else { print $_; } $last = $_; } sub Usage { print "rrdtool_add_ds.pl [default_val] [type] [heartbeat] [rrdmin] [rrdmax] < file.xml\n"; print "\t\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\n"; print "\tOptions are read in order, so if you want to change the\n"; print "\tdefault heartbeat, you need to specify the default_val and\n"; print "\ttype as well, etc.\n"; print "\n\tOutput goes to STDOUT.\n"; } WebSVN - hotsanic - Blame - Rev 6 - /branches/HotSaNIC-0.5.0-pre6/tools/rrdtool_add_ds.pl
  jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [tools/] [rrdtool_add_ds.pl] - Blame information for rev 6

 

Line No. Rev Author Line

Powered by WebSVN 2.2.1