From c6447adc80a0ab439d6e573f69de4ae3e6b9df01 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:04:13 +0100 Subject: [PATCH 1/5] Add use_nan_for_missing_data option to nut.pm --- lib/nut.pm | 46 +++++++++++++++++++++------------------ man/man5/monitorix.conf.5 | 7 ++++++ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/nut.pm b/lib/nut.pm index e7f36d7..ae8ca0c 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -147,29 +147,33 @@ sub nut_update { my $n; my $rrdata = "N"; + my $use_nan_for_missing_data = lc($nut->{use_nan_for_missing_data} || "") eq "y" ? 1 : 0; + my $e = 0; foreach my $ups (my @nl = split(',', $nut->{list})) { - my $ltran = 0; - my $htran = 0; - my $ivolt = 0; - my $ovolt = 0; - my $bchar = 0; - my $loadc = 0; - my $mbatc = 0; - my $nxfer = 0; - my $atemp = 0; - my $itemp = 0; - my $humid = 0; - my $battv = 0; - my $nomba = 0; - my $timel = 0; - my $minti = 0; - my $linef = 0; - my $val01 = 0; - my $val02 = 0; - my $val03 = 0; - my $val04 = 0; - my $val05 = 0; + my $default_value = $use_nan_for_missing_data ? (0+"nan") : 0; + + my $ltran = $default_value; + my $htran = $default_value; + my $ivolt = $default_value; + my $ovolt = $default_value; + my $bchar = $default_value; + my $loadc = $default_value; + my $mbatc = $default_value; + my $nxfer = $default_value; + my $atemp = $default_value; + my $itemp = $default_value; + my $humid = $default_value; + my $battv = $default_value; + my $nomba = $default_value; + my $timel = $default_value; + my $minti = $default_value; + my $linef = $default_value; + my $val01 = $default_value; + my $val02 = $default_value; + my $val03 = $default_value; + my $val04 = $default_value; + my $val05 = $default_value; my $data; if(open(PIPE, "upsc $ups |")) { diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index ab195e6..7e7ae27 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -4199,6 +4199,13 @@ WARNING: Every time the number of entries in this option changes, Monitorix will .P Default value: \fIups@localhost\fP .RE +.P +.BI use_nan_for_missing_data +.RS +This option, when enabled via \fIy\fP, shows \fInan\fP values for missing data instead of \fI0\fP. This is useful when \fI0\fP could be mistaken for valid data. +.P +Default value: \fIn\fP +.RE .SS Wowza Media Server (wowza.pm) This graph is able to monitor an unlimited number of Wowza servers. .P From d3f25583529955b51ce80051d23fd0b53a74e3c5 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:07:27 +0100 Subject: [PATCH 2/5] Add gap_on_all_nan option to nut.pm This option shows gaps only if all data points are nan instead of requiring only one to be nan for a gap. --- lib/nut.pm | 32 ++++++++++++++++++++------------ man/man5/monitorix.conf.5 | 7 +++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/nut.pm b/lib/nut.pm index ae8ca0c..2d7a57c 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -303,6 +303,8 @@ sub nut_cgi { $temp_scale = "Fahrenheit"; } + my $gap_on_all_nan = lc($nut->{gap_on_all_nan} || "") eq "y" ? 1 : 0; + # text mode # if(lc($config->{iface_mode}) eq "text") { @@ -483,6 +485,7 @@ sub nut_cgi { ($width, $height) = split('x', $config->{graph_size}->{main}) if $silent eq "imagetagbig"; @tmp = @tmpz; } + my $cdef_allvalues_volt = $gap_on_all_nan ? "CDEF:allvalues=ltran,UN,0,1,IF,htran,UN,0,1,IF,ivolt,UN,0,1,IF,ovolt,UN,0,1,IF,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=ltran,htran,ivolt,ovolt,+,+,+"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6]", "--title=$config->{graphs}->{_nut1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -499,7 +502,7 @@ sub nut_cgi { "DEF:htran=$rrd:nut" . $e . "_htran:AVERAGE", "DEF:ivolt=$rrd:nut" . $e . "_ivolt:AVERAGE", "DEF:ovolt=$rrd:nut" . $e . "_ovolt:AVERAGE", - "CDEF:allvalues=ltran,htran,ivolt,ovolt,+,+,+", + $cdef_allvalues_volt, @CDEF, "COMMENT: \\n", @tmp, @@ -526,7 +529,7 @@ sub nut_cgi { "DEF:htran=$rrd:nut" . $e . "_htran:AVERAGE", "DEF:ivolt=$rrd:nut" . $e . "_ivolt:AVERAGE", "DEF:ovolt=$rrd:nut" . $e . "_ovolt:AVERAGE", - "CDEF:allvalues=ltran,htran,ivolt,ovolt,+,+,+", + $cdef_allvalues_volt, @CDEF, @tmpz); $err = RRDs::error; @@ -588,6 +591,7 @@ sub nut_cgi { ($width, $height) = split('x', $config->{graph_size}->{main}) if $silent eq "imagetagbig"; @tmp = @tmpz; } + my $cdef_allvalues_bat = $gap_on_all_nan ? "CDEF:allvalues=bchar,UN,0,1,IF,mbatc,UN,0,1,IF,loadc,UN,0,1,IF,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=bchar,mbatc,loadc,+,+"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6 + 1]", "--title=$config->{graphs}->{_nut2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -603,7 +607,7 @@ sub nut_cgi { "DEF:bchar=$rrd:nut" . $e . "_bchar:AVERAGE", "DEF:loadc=$rrd:nut" . $e . "_loadc:AVERAGE", "DEF:mbatc=$rrd:nut" . $e . "_mbatc:AVERAGE", - "CDEF:allvalues=bchar,mbatc,loadc,+,+", + $cdef_allvalues_bat, @CDEF, "COMMENT: \\n", @tmp, @@ -630,7 +634,7 @@ sub nut_cgi { "DEF:bchar=$rrd:nut" . $e . "_bchar:AVERAGE", "DEF:loadc=$rrd:nut" . $e . "_loadc:AVERAGE", "DEF:mbatc=$rrd:nut" . $e . "_mbatc:AVERAGE", - "CDEF:allvalues=bchar,mbatc,loadc,+,+", + $cdef_allvalues_bat, @CDEF, @tmpz); $err = RRDs::error; @@ -693,6 +697,7 @@ sub nut_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } + my $cdef_allvalues_temp = $gap_on_all_nan ? "CDEF:allvalues=itemp,UN,0,1,IF,atemp,UN,0,1,IF,humid,UN,0,1,IF,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=itemp,atemp,humid,+,+"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6 + 2]", "--title=$config->{graphs}->{_nut3} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -709,7 +714,7 @@ sub nut_cgi { "DEF:itemp=$rrd:nut" . $e . "_itemp:AVERAGE", "DEF:atemp=$rrd:nut" . $e . "_atemp:AVERAGE", "DEF:humid=$rrd:nut" . $e . "_humid:AVERAGE", - "CDEF:allvalues=itemp,atemp,humid,+,+", + $cdef_allvalues_temp, @CDEF, @tmp); $err = RRDs::error; @@ -733,7 +738,7 @@ sub nut_cgi { "DEF:itemp=$rrd:nut" . $e . "_itemp:AVERAGE", "DEF:atemp=$rrd:nut" . $e . "_atemp:AVERAGE", "DEF:humid=$rrd:nut" . $e . "_humid:AVERAGE", - "CDEF:allvalues=itemp,atemp,humid,+,+", + $cdef_allvalues_temp, @CDEF, @tmpz); $err = RRDs::error; @@ -783,6 +788,7 @@ sub nut_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } + my $cdef_allvalues_batvolt = $gap_on_all_nan ? "CDEF:allvalues=battv,UN,0,1,IF,nomba,UN,0,1,IF,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=battv,nomba,+"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6 + 3]", "--title=$config->{graphs}->{_nut4} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -798,7 +804,7 @@ sub nut_cgi { @{$colors->{graph_colors}}, "DEF:battv=$rrd:nut" . $e . "_battv:AVERAGE", "DEF:nomba=$rrd:nut" . $e . "_nomba:AVERAGE", - "CDEF:allvalues=battv,nomba,+", + $cdef_allvalues_batvolt, @CDEF, @tmp); $err = RRDs::error; @@ -821,7 +827,7 @@ sub nut_cgi { @{$colors->{graph_colors}}, "DEF:battv=$rrd:nut" . $e . "_battv:AVERAGE", "DEF:nomba=$rrd:nut" . $e . "_nomba:AVERAGE", - "CDEF:allvalues=battv,nomba,+", + $cdef_allvalues_batvolt, @CDEF, @tmpz); $err = RRDs::error; @@ -871,6 +877,7 @@ sub nut_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } + my $cdef_allvalues_timeleft = $gap_on_all_nan ? "CDEF:allvalues=timel,UN,0,1,IF,minti,UN,0,1,IF,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=timel,minti,+"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6 + 4]", "--title=$config->{graphs}->{_nut5} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -886,7 +893,7 @@ sub nut_cgi { @{$colors->{graph_colors}}, "DEF:timel=$rrd:nut" . $e . "_timel:AVERAGE", "DEF:minti=$rrd:nut" . $e . "_minti:AVERAGE", - "CDEF:allvalues=timel,minti,+", + $cdef_allvalues_timeleft, "CDEF:timel_min=timel,60,/", "CDEF:minti_min=minti,60,/", @CDEF, @@ -911,7 +918,7 @@ sub nut_cgi { @{$colors->{graph_colors}}, "DEF:timel=$rrd:nut" . $e . "_timel:AVERAGE", "DEF:minti=$rrd:nut" . $e . "_minti:AVERAGE", - "CDEF:allvalues=timel,minti,+", + $cdef_allvalues_timeleft, "CDEF:timel_min=timel,60,/", "CDEF:minti_min=minti,60,/", @CDEF, @@ -960,6 +967,7 @@ sub nut_cgi { push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n"); } + my $cdef_allvalues_freq = $gap_on_all_nan ? "CDEF:allvalues=linef,UN,0,1,IF,0,GT,1,UNKN,IF" : "CDEF:allvalues=linef"; $pic = $rrd{$version}->("$IMG_DIR" . "$IMG[$e * 6 + 5]", "--title=$config->{graphs}->{_nut6} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", @@ -974,7 +982,7 @@ sub nut_cgi { @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, "DEF:linef=$rrd:nut" . $e . "_linef:AVERAGE", - "CDEF:allvalues=linef", + $cdef_allvalues_freq, @CDEF, @tmp); $err = RRDs::error; @@ -996,7 +1004,7 @@ sub nut_cgi { @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, "DEF:linef=$rrd:nut" . $e . "_linef:AVERAGE", - "CDEF:allvalues=linef", + $cdef_allvalues_freq, @CDEF, @tmpz); $err = RRDs::error; diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index 7e7ae27..269bb86 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -4206,6 +4206,13 @@ This option, when enabled via \fIy\fP, shows \fInan\fP values for missing data i .P Default value: \fIn\fP .RE +.P +.BI gap_on_all_nan +.RS +This option, when enabled via \fIy\fP, combined with the \fIshow_gaps\fP option shows gaps only if all data points are \fInan\fP instead of requiring only one to be \fInan\fP for a gap. This can be useful if not all sensor data are required for normal operation. +.P +Default value: \fIn\fP +.RE .SS Wowza Media Server (wowza.pm) This graph is able to monitor an unlimited number of Wowza servers. .P From 780e067604f24b0c097450dda529b7582bcb104c Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:08:44 +0100 Subject: [PATCH 3/5] Add ignore_error_output option to nut.pm This option, when enabled, suppresses error output from upsc. --- lib/nut.pm | 14 ++++++++++++-- man/man5/monitorix.conf.5 | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/nut.pm b/lib/nut.pm index 2d7a57c..e34f397 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -148,6 +148,7 @@ sub nut_update { my $rrdata = "N"; my $use_nan_for_missing_data = lc($nut->{use_nan_for_missing_data} || "") eq "y" ? 1 : 0; + my $ignore_error_output = lc($nut->{ignore_error_output} || "") eq "y" ? 1 : 0; my $e = 0; foreach my $ups (my @nl = split(',', $nut->{list})) { @@ -176,7 +177,11 @@ sub nut_update { my $val05 = $default_value; my $data; - if(open(PIPE, "upsc $ups |")) { + my $upsc_cmd = "upsc $ups"; + if ($ignore_error_output) { + $upsc_cmd .= " 2>/dev/null"; + } + if(open(PIPE, "$upsc_cmd |")) { while() { $data .= $_; } close(PIPE); } @@ -304,6 +309,7 @@ sub nut_cgi { } my $gap_on_all_nan = lc($nut->{gap_on_all_nan} || "") eq "y" ? 1 : 0; + my $ignore_error_output = lc($nut->{ignore_error_output} || "") eq "y" ? 1 : 0; # text mode # @@ -394,7 +400,11 @@ sub nut_cgi { foreach my $ups (my @nl = split(',', $nut->{list})) { my $data; - if(open(PIPE, "upsc $ups |")) { + my $upsc_cmd = "upsc $ups"; + if ($ignore_error_output) { + $upsc_cmd .= " 2>/dev/null"; + } + if(open(PIPE, "$upsc_cmd |")) { while() { $data .= $_; } close(PIPE); } diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index 269bb86..9dec156 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -4213,6 +4213,13 @@ This option, when enabled via \fIy\fP, combined with the \fIshow_gaps\fP option .P Default value: \fIn\fP .RE +.P +.BI ignore_error_output +.RS +This option, when enabled via \fIy\fP, suppresses error output from upsc. +.P +Default value: \fIn\fP +.RE .SS Wowza Media Server (wowza.pm) This graph is able to monitor an unlimited number of Wowza servers. .P From 284cae9fdc5e3aa2248abbb225ddb813a1cdcd1f Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 24 Feb 2022 16:24:16 +0100 Subject: [PATCH 4/5] Print the used upsc call. --- lib/nut.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nut.pm b/lib/nut.pm index e34f397..b58e5b7 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -187,7 +187,7 @@ sub nut_update { } if(!$data) { - logger("$myself: unable to execute 'upsc $ups' command or invalid connection."); + logger("$myself: unable to execute '$upsc_cmd' command or invalid connection."); $rrdata .= ":$ltran:$htran:$ivolt:$ovolt:$bchar:$loadc:$mbatc:$nxfer:$atemp:$itemp:$humid:$battv:$nomba:$timel:$minti:$linef:0:0:0:0:0"; next; } From f05e4b5ea4fe6902852aeb51cd726d4428723f35 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Fri, 25 Feb 2022 00:49:53 +0100 Subject: [PATCH 5/5] Also use the default value for placeholder values. --- lib/nut.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nut.pm b/lib/nut.pm index b58e5b7..872cce5 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -188,7 +188,7 @@ sub nut_update { if(!$data) { logger("$myself: unable to execute '$upsc_cmd' command or invalid connection."); - $rrdata .= ":$ltran:$htran:$ivolt:$ovolt:$bchar:$loadc:$mbatc:$nxfer:$atemp:$itemp:$humid:$battv:$nomba:$timel:$minti:$linef:0:0:0:0:0"; + $rrdata .= ":$ltran:$htran:$ivolt:$ovolt:$bchar:$loadc:$mbatc:$nxfer:$atemp:$itemp:$humid:$battv:$nomba:$timel:$minti:$linef:$default_value:$default_value:$default_value:$default_value:$default_value"; next; }