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] 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