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

This commit is contained in:
Jordi Sanfeliu 2013-10-29 09:13:09 +01:00
parent d2b18568ed
commit 8721889dde
1 changed files with 35 additions and 4 deletions

View File

@ -32,6 +32,16 @@ sub nvidia_init {
my ($package, $config, $debug) = @_; my ($package, $config, $debug) = @_;
my $rrd = $config->{base_lib} . $package . ".rrd"; my $rrd = $config->{base_lib} . $package . ".rrd";
my $info;
my @rra;
my @tmp;
my $n;
my @average;
my @min;
my @max;
my @last;
# checks if 'nvidia-smi' does exists. # checks if 'nvidia-smi' does exists.
if(!open(IN, "nvidia-smi |")) { if(!open(IN, "nvidia-smi |")) {
logger("$myself: unable to execute 'nvidia-smi'. $!"); logger("$myself: unable to execute 'nvidia-smi'. $!");
@ -39,8 +49,29 @@ sub nvidia_init {
} }
close(IN); close(IN);
if(-e $rrd) {
$info = RRDs::info($rrd);
for my $key (keys %$info) {
if(index($key, 'rra[') == 0) {
if(index($key, '.rows') != -1) {
push(@rra, substr($key, 4, index($key, ']') - 4));
}
}
}
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)) { 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));
}
eval { eval {
RRDs::create($rrd, RRDs::create($rrd,
"--step=60", "--step=60",
@ -74,19 +105,19 @@ sub nvidia_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;