From f992d069a96ccf7e63b729c272487771168a5fc1 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Fri, 4 Aug 2017 10:20:49 +0200 Subject: [PATCH] added the ability to include an alert for each defined sensor in 'nvidia.pm' --- Changes | 1 + lib/nvidia.pm | 40 ++++++++++++++++++++++++++++++++++++++++ monitorix.conf | 2 ++ 3 files changed, 43 insertions(+) diff --git a/Changes b/Changes index 053d25d..38ae3f8 100644 --- a/Changes +++ b/Changes @@ -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] diff --git a/lib/nvidia.pm b/lib/nvidia.pm index edb94bc..03e790d 100644 --- a/lib/nvidia.pm +++ b/lib/nvidia.pm @@ -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]"; } diff --git a/monitorix.conf b/monitorix.conf index 7995f60..0067656 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -259,6 +259,8 @@ secure_log_date_format = %b %e # ----------------------------------------------------------------------------- max = 1 + + rigid = 1, 2, 2 limit = 50, 100, 100