added support for the new 'max_historic_years' option to the 'ntp' graph

This commit is contained in:
Jordi Sanfeliu 2013-10-28 18:35:10 +01:00
parent 526da8dccd
commit d2b18568ed
1 changed files with 26 additions and 5 deletions

View File

@ -35,9 +35,15 @@ sub ntp_init {
my $info; my $info;
my @ds; my @ds;
my @rra;
my @tmp; my @tmp;
my $n; my $n;
my @average;
my @min;
my @max;
my @last;
if(-e $rrd) { if(-e $rrd) {
$info = RRDs::info($rrd); $info = RRDs::info($rrd);
for my $key (keys %$info) { for my $key (keys %$info) {
@ -46,15 +52,30 @@ sub ntp_init {
push(@ds, substr($key, 3, index($key, ']') - 3)); 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) / 14 != scalar(my @nl = split(',', $ntp->{list}))) { if(scalar(@ds) / 14 != scalar(my @nl = split(',', $ntp->{list}))) {
logger("Detected size mismatch between 'list' (" . scalar(my @nl = split(',', $ntp->{list})) . ") and $rrd (" . scalar(@ds) / 14 . "). Resizing it accordingly. All historic data will be lost. Backup file created."); logger("$myself: Detected size mismatch between 'list' (" . scalar(my @nl = split(',', $ntp->{list})) . ") and $rrd (" . scalar(@ds) / 14 . "). Resizing it accordingly. All historical 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' (" . $config->{max_historic_years} . ") and $rrd (" . ((scalar(@rra) -12) / 4) . "). Resizing it accordingly. All historical data will be lost. Backup file created.");
rename($rrd, "$rrd.bak"); rename($rrd, "$rrd.bak");
} }
} }
if(!(-e $rrd)) { if(!(-e $rrd)) {
logger("Creating '$rrd' file."); 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 < scalar(my @nl = split(',', $ntp->{list})); $n++) { for($n = 0; $n < scalar(my @nl = split(',', $ntp->{list})); $n++) {
push(@tmp, "DS:ntp" . $n . "_del:GAUGE:120:U:U"); push(@tmp, "DS:ntp" . $n . "_del:GAUGE:120:U:U");
push(@tmp, "DS:ntp" . $n . "_off:GAUGE:120:U:U"); push(@tmp, "DS:ntp" . $n . "_off:GAUGE:120:U:U");
@ -78,19 +99,19 @@ sub ntp_init {
"RRA:AVERAGE:0.5:1:1440", "RRA:AVERAGE:0.5:1:1440",
"RRA:AVERAGE:0.5:30:336", "RRA:AVERAGE:0.5:30:336",
"RRA:AVERAGE:0.5:60:744", "RRA:AVERAGE:0.5:60:744",
"RRA:AVERAGE:0.5:1440:365", @average,
"RRA:MIN:0.5:1:1440", "RRA:MIN:0.5:1:1440",
"RRA:MIN:0.5:30:336", "RRA:MIN:0.5:30:336",
"RRA:MIN:0.5:60:744", "RRA:MIN:0.5:60:744",
"RRA:MIN:0.5:1440:365", @min,
"RRA:MAX:0.5:1:1440", "RRA:MAX:0.5:1:1440",
"RRA:MAX:0.5:30:336", "RRA:MAX:0.5:30:336",
"RRA:MAX:0.5:60:744", "RRA:MAX:0.5:60:744",
"RRA:MAX:0.5:1440:365", @max,
"RRA:LAST:0.5:1:1440", "RRA:LAST:0.5:1:1440",
"RRA:LAST:0.5:30:336", "RRA:LAST:0.5:30:336",
"RRA:LAST:0.5:60:744", "RRA:LAST:0.5:60:744",
"RRA:LAST:0.5:1440:365", @last,
); );
}; };
my $err = RRDs::error; my $err = RRDs::error;