From 8b0b32dbdcab44a4f7edb06f9763002d4d6a8bc6 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 5 May 2021 15:48:54 +0200 Subject: [PATCH] added the option 'time_unit' in 'system.pm' to set the scale of the uptime graph #331 --- lib/system.pm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/system.pm b/lib/system.pm index 166a178..0efb22a 100644 --- a/lib/system.pm +++ b/lib/system.pm @@ -1004,8 +1004,24 @@ sub system_cgi { undef(@tmp); undef(@tmpz); undef(@CDEF); + my $ytitle; + my $unit; + my $format; + if(lc(($system->{time_unit} || "") eq "minute")) { + $ytitle = "Minutes"; + $unit = 60; + $format = "%5.0lf"; + } elsif(lc(($system->{time_unit} || "") eq "hour")) { + $ytitle = "Hours"; + $unit = 3600; + $format = "%5.0lf"; + } else { + $ytitle = "Days"; + $unit = 86400; + $format = "%5.1lf"; + } push(@tmp, "LINE2:uptime_days#EE44EE:Uptime"); - push(@tmp, "GPRINT:uptime_days:LAST:(in days) Current\\:%5.1lf\\n"); + push(@tmp, "GPRINT:uptime_days:LAST: Current\\:$format\\n"); push(@tmpz, "LINE2:uptime_days#EE44EE:Uptime"); if(lc($config->{show_gaps}) eq "y") { push(@tmp, "AREA:wrongdata#$colors->{gap}:"); @@ -1023,7 +1039,7 @@ sub system_cgi { "--title=$config->{graphs}->{_system5} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", - "--vertical-label=Days", + "--vertical-label=$ytitle", "--width=$width", "--height=$height", @extra, @@ -1033,7 +1049,7 @@ sub system_cgi { @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, "DEF:uptime=$rrd:system_uptime:AVERAGE", - "CDEF:uptime_days=uptime,86400,/", + "CDEF:uptime_days=uptime,$unit,/", "CDEF:allvalues=uptime", @CDEF, @tmp); @@ -1045,7 +1061,7 @@ sub system_cgi { "--title=$config->{graphs}->{_system5} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=$imgfmt_uc", - "--vertical-label=Days", + "--vertical-label=$ytitle", "--width=$width", "--height=$height", @extra, @@ -1055,7 +1071,7 @@ sub system_cgi { @{$cgi->{version12_small}}, @{$colors->{graph_colors}}, "DEF:uptime=$rrd:system_uptime:AVERAGE", - "CDEF:uptime_days=uptime,86400,/", + "CDEF:uptime_days=uptime,$unit,/", "CDEF:allvalues=uptime", @CDEF, @tmpz);