From 685788a2d314033375fd544dfbfa680e99481215 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Mon, 14 Oct 2013 15:24:30 +0200 Subject: [PATCH] added support for the new 'max_historic_years' option to the 'disk' graph --- lib/disk.pm | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/disk.pm b/lib/disk.pm index 9ac204f..e36dfba 100644 --- a/lib/disk.pm +++ b/lib/disk.pm @@ -35,9 +35,15 @@ sub disk_init { my $info; my @ds; + my @rra; my @tmp; my $n; + my @average; + my @min; + my @max; + my @last; + foreach my $k (sort keys %{$disk->{list}}) { # values delimitted by ", " (comma + space) my @dsk = split(', ', $disk->{list}->{$k}); @@ -65,15 +71,30 @@ sub disk_init { push(@ds, substr($key, 3, index($key, ']') - 3)); } } + if(index($key, 'rra[') == 0) { + if(index($key, '.rows') != -1) { + push(@rra, substr($key, 4, index($key, ']') - 4)); + } + } } if(scalar(@ds) / 24 != keys(%{$disk->{list}})) { logger("$myself: Detected size mismatch between ... (" . keys(%{$disk->{list}}) . ") and $rrd (" . scalar(@ds) / 24 . "). Resizing it accordingly. All historic data will be lost. Backup file created."); rename($rrd, "$rrd.bak"); } + if(scalar(@rra) != 12 + (4 * $config->{max_historic_years})) { + logger("$myself: Detected size mismatch between 'max_historic_years' option (" . $config->{max_historic_years} . ") and $rrd (" . ((scalar(@rra) -12) / 4) . "). Resizing it accordingly. All historic data will be lost. Backup file created."); + rename($rrd, "$rrd.bak"); + } } if(!(-e $rrd)) { logger("Creating '$rrd' file."); + for($n = 1; $n <= $config->{max_historic_years}; $n++) { + push(@average, "RRA:AVERAGE:0.5:1440:" . (365 * $n)); + push(@min, "RRA:MIN:0.5:1440:" . (365 * $n)); + push(@max, "RRA:MAX:0.5:1440:" . (365 * $n)); + push(@last, "RRA:LAST:0.5:1440:" . (365 * $n)); + } for($n = 0; $n < keys(%{$disk->{list}}); $n++) { push(@tmp, "DS:disk" . $n . "_hd0_temp:GAUGE:120:0:100"); push(@tmp, "DS:disk" . $n . "_hd0_smart1:GAUGE:120:0:U"); @@ -107,19 +128,19 @@ sub disk_init { "RRA:AVERAGE:0.5:1:1440", "RRA:AVERAGE:0.5:30:336", "RRA:AVERAGE:0.5:60:744", - "RRA:AVERAGE:0.5:1440:365", + @average, "RRA:MIN:0.5:1:1440", "RRA:MIN:0.5:30:336", "RRA:MIN:0.5:60:744", - "RRA:MIN:0.5:1440:365", + @min, "RRA:MAX:0.5:1:1440", "RRA:MAX:0.5:30:336", "RRA:MAX:0.5:60:744", - "RRA:MAX:0.5:1440:365", + @max, "RRA:LAST:0.5:1:1440", "RRA:LAST:0.5:30:336", "RRA:LAST:0.5:60:744", - "RRA:LAST:0.5:1440:365", + @last, ); }; my $err = RRDs::error;