summaryrefslogtreecommitdiffstats
path: root/lib/Smokeping/RRDtools.pm
diff options
context:
space:
mode:
authorTobi Oetiker <tobi@oetiker.ch>2005-07-04 00:15:20 +0200
committerTobi Oetiker <tobi@oetiker.ch>2005-07-04 00:15:20 +0200
commit66c8d49cbe278316114a6eef8ccb509c9e67d0ba (patch)
tree3b7da28f6e77a5d5d676ed4471434c3d0102dfcf /lib/Smokeping/RRDtools.pm
parentb5a21fd2221f92bf7db544bc265a76d41912a633 (diff)
downloadsmokeping-66c8d49cbe278316114a6eef8ccb509c9e67d0ba.tar.gz
smokeping-66c8d49cbe278316114a6eef8ccb509c9e67d0ba.tar.xz
tune the rrd files for min/max/heartbeat
Diffstat (limited to 'lib/Smokeping/RRDtools.pm')
-rw-r--r--lib/Smokeping/RRDtools.pm57
1 files changed, 45 insertions, 12 deletions
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<info2create> and C<compare>.
-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<info2create>, C<compare> and
+C<tuneds>. 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<info2create> 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<RRDs::create>.
Note that this list will never contain the C<start> parameter,
but it B<will> contain the C<step> parameter.
-The function C<compare> 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<RRDs::create>. The function will then simply compare
-the result of C<info2create> with this argument list. It will return
-C<undef> if the arguments matched, and a string indicating the difference
-if a discrepancy was found. Note that if there is a C<start> parameter in
-the argument list, C<compare> disregards it. If C<step> isn't specified,
-C<compare> will use the C<rrdtool> default of 300 seconds.
+The function C<compare> 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<RRDs::create>. The function will then simply compare the result of
+C<info2create> with this argument list. It will return C<undef> if the
+arguments matched, and a string indicating the difference if a discrepancy
+was found. Note that if there is a C<start> parameter in the argument list,
+C<compare> disregards it. If C<step> isn't specified, C<compare> will use
+the C<rrdtool> default of 300 seconds. C<compare> ignores non-matching DS
+parameters since C<tuneds> will fix them.
+
+C<tuneds> 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;