added the ability to include an alert for each defined sensor in 'nvidia.pm'

This commit is contained in:
Jordi Sanfeliu 2017-08-04 10:20:49 +02:00
parent 1017f69f58
commit f992d069a9
3 changed files with 43 additions and 0 deletions

View File

@ -37,6 +37,7 @@
- Added the ability to include an alert for each defined sensor in 'hptemp.pm'.
- Added the ability to include an alert for each defined sensor in 'ipmi.pm'.
- Added alert capabilities to 'lmsens.pm'. [#171]
- Added the ability to include an alert for each defined sensor in 'nvidia.pm'.
- Fixed an undeclared global symbol "$imgfmt_lc" in 'traffacct.pm'.
- Fixed the MIME type of graphs in 'emailreports.pm' and in 'traffacct.pm' to
honor the 'image_format' option. [#174]

View File

@ -133,10 +133,44 @@ sub nvidia_init {
}
}
$config->{nvidia_hist_alerts} = ();
push(@{$config->{func_update}}, $package);
logger("$myself: Ok") if $debug;
}
sub nvidia_alerts {
my $myself = (caller(0))[3];
my $config = (shift);
my $sensor = (shift);
my $val = (shift);
my $nvidia = $config->{nvidia};
my @al = split(',', $nvidia->{alerts}->{$sensor} || "");
if(scalar(@al)) {
my $timeintvl = trim($al[0]);
my $threshold = trim($al[1]);
my $script = trim($al[2]);
if(!$threshold || $val < $threshold) {
$config->{nvidia_hist_alerts}->{$sensor} = 0;
} else {
if(!$config->{nvidia_hist_alerts}->{$sensor}) {
$config->{nvidia_hist_alerts}->{$sensor} = time;
}
if($config->{nvidia_hist_alerts}->{$sensor} > 0 && (time - $config->{nvidia_hist_alerts}->{$sensor}) >= $timeintvl) {
if(-x $script) {
logger("$myself: alert on NVIDIA ($sensor): executing script '$script'.");
system($script . " " . $timeintvl . " " . $threshold . " " . $val);
} else {
logger("$myself: ERROR: script '$script' doesn't exist or don't has execution permissions.");
}
$config->{nvidia_hist_alerts}->{$sensor} = time;
}
}
}
}
sub nvidia_update {
my $myself = (caller(0))[3];
my ($package, $config, $debug) = @_;
@ -216,12 +250,18 @@ sub nvidia_update {
}
for($n = 0; $n < scalar(@temp); $n++) {
# check alerts for each sensor defined
nvidia_alerts($config, "temp$n", $temp[$n]);
$rrdata .= ":$temp[$n]";
}
for($n = 0; $n < scalar(@gpu); $n++) {
# check alerts for each sensor defined
nvidia_alerts($config, "gpu$n", $gpu[$n]);
$rrdata .= ":$gpu[$n]";
}
for($n = 0; $n < scalar(@mem); $n++) {
# check alerts for each sensor defined
nvidia_alerts($config, "mem$n", $mem[$n]);
$rrdata .= ":$mem[$n]";
}

View File

@ -259,6 +259,8 @@ secure_log_date_format = %b %e
# -----------------------------------------------------------------------------
<nvidia>
max = 1
<alerts>
</alerts>
rigid = 1, 2, 2
limit = 50, 100, 100
</nvidia>