From 66c8d49cbe278316114a6eef8ccb509c9e67d0ba Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Sun, 3 Jul 2005 22:15:20 +0000 Subject: tune the rrd files for min/max/heartbeat --- lib/Smokeping/RRDtools.pm | 57 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'lib/Smokeping') diff --git a/lib/Smokeping/RRDtools.pm b/lib/Smokeping/RRDtools.pm index 4a695d1..2b7ad2b 100644 --- a/lib/Smokeping/RRDtools.pm +++ b/lib/Smokeping/RRDtools.pm @@ -22,12 +22,15 @@ Smokeping::RRDtools - Tools for RRD file handling my $comparison = Smokeping::RRDtools::compare($file, \@create); print "Create arguments didn't match: $comparison\n" if $comparison; + Smokeping::RRDtools::tuneds($file, \@create); + =head1 DESCRIPTION -This module offers two functions, C and C. -The first can be used to recreate the arguments that an RRD file -was created with. The second checks if an RRD file was created -with the given arguments. +This module offers three functions, C, C and +C. The first can be used to recreate the arguments that an RRD file +was created with. The second checks if an RRD file was created with the +given arguments. The thirds tunes the DS parameters according to the +supplied create string. The function C must be called with one argument: the path to the interesting RRD file. It will return an array @@ -35,14 +38,17 @@ reference of the argument list that can be fed to C. Note that this list will never contain the C parameter, but it B contain the C parameter. -The function C must be called with two arguments: the path -to the interesting RRD file, and a reference to an argument list that -could be fed to C. The function will then simply compare -the result of C with this argument list. It will return -C if the arguments matched, and a string indicating the difference -if a discrepancy was found. Note that if there is a C parameter in -the argument list, C disregards it. If C isn't specified, -C will use the C default of 300 seconds. +The function C must be called with two arguments: the path to the +interesting RRD file, and a reference to an argument list that could be fed +to C. The function will then simply compare the result of +C with this argument list. It will return C if the +arguments matched, and a string indicating the difference if a discrepancy +was found. Note that if there is a C parameter in the argument list, +C disregards it. If C isn't specified, C will use +the C default of 300 seconds. C ignores non-matching DS +parameters since C will fix them. + +C talks on stderr about the parameters it fixes. =head1 NOTES @@ -168,10 +174,37 @@ sub compare { while (my $arg = shift @create) { my $arg2 = shift @create2; + my @ds = split /:/, $arg; + my @ds2 = split /:/, $arg2; + next if $ds[0] eq 'DS' and $ds[0] eq $ds2[0] and $ds[1] eq $ds2[1] and $ds[2] eq $ds2[2]; return "Different arguments: $file has $arg2, create string has $arg" unless $arg eq $arg2; } return undef; } +sub tuneds { + my $file = shift; + my $create = shift; + my @create2 = sort grep /^DS/, @{info2create($file)}; + my @create = sort grep /^DS/, @$create; + while (@create){ + my @ds = split /:/, shift @create; + my @ds2 = split /:/, shift @create2; + next unless $ds[1] eq $ds2[1] and $ds[2] eq $ds[2]; + if ($ds[3] ne $ds2[3]){ + warn "## Updating $file DS:$ds[1] heartbeat $ds2[3] -> $ds[3]\n"; + RRDs::tune $file,"--hearbeat","$ds[1]:$ds[3]" unless $ds[3] eq $ds2[3]; + } + if ($ds[4] ne $ds2[4]){ + warn "## Updating $file DS:$ds[1] minimum $ds2[4] -> $ds[4]\n"; + RRDs::tune $file,"--minimum","$ds[1]:$ds[4]" unless $ds[4] eq $ds2[4]; + } + if ($ds[5] ne $ds2[5]){ + warn "## Updating $file DS:$ds[1] maximum $ds2[5] -> $ds[5]\n"; + RRDs::tune $file,"--maximum","$ds[1]:$ds[5]" unless $ds[5] eq $ds2[5]; + } + } +} + 1; -- cgit v1.2.3-24-g4f1b