From: Florian Forster Date: Thu, 13 Mar 2008 17:19:48 +0000 (+0100) Subject: contrib/rrd_filter.px: Added the ability to add (empty) data sources. X-Git-Tag: collectd-4.3.2~18^2~1 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=042fdc33cbe85574303d22793cb98338bf7b2774 contrib/rrd_filter.px: Added the ability to add (empty) data sources. --- diff --git a/contrib/rrd_filter.px b/contrib/rrd_filter.px index 6a827831..d28f9f23 100755 --- a/contrib/rrd_filter.px +++ b/contrib/rrd_filter.px @@ -44,6 +44,7 @@ our $InDS = []; our $OutFile; our $OutDS = []; +our $NewDSes = []; our $NewRRAs = []; our $Step = 0; @@ -132,6 +133,17 @@ GetOptions ("infile|i=s" => \$InFile, push (@$OutDS, $out_ds); }, 'step|s=i' => \$Step, + 'ds|d=s' => sub + { + #DS:ds-name:GAUGE | COUNTER | DERIVE | ABSOLUTE:heartbeat:min:max + my ($ds, $name, $type, $hb, $min, $max) = split (':', $_[1]); + if (($ds ne 'DS') || !defined ($max)) + { + print STDERR "Please use the standard RRDTool syntax when adding DSes. I. e. DS:::::.\n"; + exit (1); + } + push (@$NewDSes, {name => $name, type => $type, heartbeat => $hb, min => $min, max => $max}); + }, 'rra|a=s' => sub { my ($rra, $cf, $xff, $steps, $rows) = split (':', $_[1]); @@ -156,7 +168,6 @@ if ((1 + @$InDS) != (1 + @$OutDS)) print STDERR "You need the same amount of in- and out-DSes\n"; exit (1); } - main ($InFile, $OutFile); exit (0); @@ -445,6 +456,87 @@ sub handle_line_step }} # handle_line_step # +# The _add DS_ handler +# +{ +my $add_ds_done; +sub handle_line_add_ds +{ + my $line = shift; + my $index = shift; + + my $post = sub { for (@_) { post_line ($_, $index + 1); } }; + + if (!@$NewDSes) + { + $post->($line); + return; + } + + if (!$add_ds_done && ($line =~ m##i)) + { + for (my $i = 0; $i < @$NewDSes; $i++) + { + my $ds = $NewDSes->[$i]; + my $temp; + + my $min; + my $max; + + if ($Debug) + { + print STDOUT "Adding DS: name = $ds->{'name'}, type = $ds->{'type'}, heartbeat = $ds->{'heartbeat'}, min = $ds->{'min'}, max = $ds->{'max'}\n"; + } + + $min = 'NaN'; + if (defined ($ds->{'min'}) && ($ds->{'min'} ne 'U')) + { + $min = sprintf ('%.10e', $ds->{'min'}); + } + + $max = 'NaN'; + if (defined ($ds->{'max'}) && ($ds->{'max'} ne 'U')) + { + $max = sprintf ('%.10e', $ds->{'max'}); + } + + + $post->("\t\n", + "\t\t $ds->{'name'} \n", + "\t\t $ds->{'type'} \n", + "\t\t $ds->{'heartbeat'} \n", + "\t\t $min \n", + "\t\t $max \n", + "\n", + "\t\t\n", + "\t\t UNKN \n", + "\t\t NaN \n", + "\t\t 0 \n", + "\t\n", + "\n"); + } + + $add_ds_done = 1; + } + elsif ($add_ds_done && ($line =~ m##i)) # inside a cdp_prep block + { + $post->("\t\t\t\n", + "\t\t\t\n", + "\t\t\t NaN \n", + "\t\t\t NaN \n", + "\t\t\t NaN \n", + "\t\t\t 0 \n"); + } + elsif ($line =~ m##i) + { + my $insert = ' NaN ' x (0 + @$NewDSes); + $line =~ s##$insert#i; + } + + $post->($line); +}} # handle_line_add_ds + +# # The _add RRA_ handler # { @@ -702,6 +794,11 @@ sub handle_fh #add_handler (\&handle_line_peak_detect); + if (@$NewDSes) + { + add_handler (\&handle_line_add_ds); + } + if (@$NewRRAs) { add_handler (\&handle_line_add_rra);