From fd198fcdfda36da547af84d57ab456faf16a0dd0 Mon Sep 17 00:00:00 2001 From: Benjamin Oechslein Date: Fri, 9 Jan 2015 20:22:15 +0100 Subject: [PATCH 1/1] Generate day-max/min graph definitions --- upsgraph.pl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/upsgraph.pl b/upsgraph.pl index 1e335ac..c8bc4c6 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -184,6 +184,45 @@ sub fetch_tcp_multi(@) { %values; } +sub dayGraphFunc { + my $dataSrc = shift; + my $mode = shift; + my $color = shift; + my $label = shift; + my $dataPoints = shift; + my @args = (); + push @args, "CDEF:prev${mode}1=PREV(${dataSrc})"; + for (my $i = 1; $i < $dataPoints - 1; ++$i) { + my $prev = $i; + my $next = $i+1; + push @args, "CDEF:prev${mode}${next}=PREV(prev${mode}${prev})"; + } + my $dayCons = ''; + my $consFunc = ''; + for (my $i = 1; $i < $dataPoints; ++$i) { + $dayCons .= "prev${mode}${i},"; + $consFunc .= ",${mode}"; + } + push @args, "CDEF:day${mode}=${dayCons}${dataSrc}${consFunc}"; + push @args, "CDEF:fillCalDay${mode}0=COUNT,${dataPoints},%,0,EQ,day${mode},UNKN,IF"; + for (my $i = 1; $i < $dataPoints; ++$i) { + my $prev = $i-1; + my $next = $i; + push @args, "CDEF:fillCalDay${mode}${next}=PREV(fillCalDay${mode}${prev})"; + } + my $fillPoint = ''; + my $if = ''; + for (my $i = 0; $i < $dataPoints; ++$i) { + $fillPoint .= "COUNT,${dataPoints},%,${i},EQ,fillCalDay${mode}${i},"; + $if .= ",IF"; + } + push @args, "CDEF:${mode}Curve=${fillPoint}UNKN${if}"; + my $forwardShift = (24*60*60) * ($dataPoints - 1) / $dataPoints; + push @args, "SHIFT:${mode}Curve:-${forwardShift}"; + push @args, "LINE1:${mode}Curve#${color}:${label}"; + return \@args; +} + if ($> == 0) { if (@ARGV != 2) { print STDERR "Running as root, please provide UID as 2th argument!\n"; -- 2.39.5