From: Benjamin Oechslein Date: Mon, 8 Dec 2014 20:33:17 +0000 (+0100) Subject: Added script for moving data from one rrd file to another one X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/commitdiff_plain/cc12f2c6ebe9b3e265e571f6d8fb9d32d9ffdd1b?ds=inline Added script for moving data from one rrd file to another one --- diff --git a/mvrrd.pl b/mvrrd.pl new file mode 100755 index 0000000..32cd860 --- /dev/null +++ b/mvrrd.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +use strict; +use RRDs; + +sub usage { + print("usage: mvrrd.pl src.rrd dst.rrd start end\n"); +} + +usage() if scalar(@ARGV) != 4; + +my $src = @ARGV[0]; +my $dst = @ARGV[1]; +my $start = $ARGV[2]; +my $end = $ARGV[3]; + +sub RRDupdate { + my $time = shift; + my $val = shift; + + my @arg = (); + + push @arg, $dst; + push @arg, "$time:$val"; + RRDs::update(@arg); + my $error = RRDs::error; + die "RRD error: $error\n" if $error; +} + +my @arg = (); +push @arg, "$src"; +push @arg, "AVERAGE"; +push @arg, "--start", $start; +push @arg, "--end", $end; + +my ($dataStart,$step,$names,$data) = RRDs::fetch(@arg); +my $error = RRDs::error; +die "RRD error: $error\n" if $error; +print "Start: ", scalar localtime($dataStart), " ($dataStart)\n"; +print "Step size: $step seconds\n"; +print "DS names: ", join (", ", @$names)."\n"; +print "Data points: ", $#$data + 1, "\n"; +print "Data:\n"; +for my $line (@$data) { +# print " ", scalar localtime($dataStart), " ($dataStart) "; + my ($sec, $min, $hour, $mday, $mon, $year) = localtime($dataStart); + my $isoDate = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $mday); + for my $val (@$line) { +# printf "%f ", $val; + $val = 'U' if !defined $val; +# print "val: $val @ time $isoDate"; +# print " ... Updating dst"; + RRDupdate($dataStart, $val); + } + $dataStart += $step; +# print "\n"; +}