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

This commit is contained in:
Jordi Sanfeliu 2013-10-24 10:54:36 +02:00
parent ad8f4fc8f8
commit ed49e77a2d
1 changed files with 26 additions and 5 deletions

View File

@ -36,9 +36,15 @@ sub lighttpd_init {
my $info;
my @ds;
my @rra;
my @tmp;
my $n;
my @average;
my @min;
my @max;
my @last;
if(!scalar(my @ll = split(',', $lighttpd->{list}))) {
logger("$myself: ERROR: missing or not defined 'list' option.");
return 0;
@ -52,15 +58,30 @@ sub lighttpd_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) / 9 != scalar(my @ll = split(',', $lighttpd->{list}))) {
logger("Detected size mismatch between 'list' option (" . scalar(my @ll = split(',', $lighttpd->{list})) . ") and $rrd (" . scalar(@ds) / 9 . "). Resizing it accordingly. All historic data will be lost. Backup file created.");
logger("$myself: Detected size mismatch between 'list' (" . scalar(my @ll = split(',', $lighttpd->{list})) . ") and $rrd (" . scalar(@ds) / 9 . "). 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");
}
}
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 < scalar(my @ll = split(',', $lighttpd->{list})); $n++) {
push(@tmp, "DS:lighttpd" . $n . "_acc:GAUGE:120:0:U");
push(@tmp, "DS:lighttpd" . $n . "_kb:GAUGE:120:0:U");
@ -79,19 +100,19 @@ sub lighttpd_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;