X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/99c552bff6f4dddd9bbbb3806dcca44ea845f5cc..refs/heads/minmax-merge:/upsgraph.pl diff --git a/upsgraph.pl b/upsgraph.pl index ce19500..adf33c9 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -23,6 +23,7 @@ $UPSGRAPH::stepsPerHour = (60 * 60) / $UPSGRAPH::step; $UPSGRAPH::keep = ($UPSGRAPH::daysCovered*24*60*60)/$UPSGRAPH::step; $UPSGRAPH::keepHours = ($UPSGRAPH::daysCovered*24*60*60)/$UPSGRAPH::stepsPerHour/$UPSGRAPH::step; $UPSGRAPH::hosts = (); +$UPSGRAPH::regenerateOnStart = 1; #when set, regenerate graphs on script startup do $ARGV[0] or die "can't read config: $!"; @@ -89,6 +90,7 @@ sub rrdcreate(@) { push @cmd, "RRA:AVERAGE:0.5:1:${keep}"; push @cmd, "RRA:MIN:0.4:${stepsPerHour}:${keepHours}"; push @cmd, "RRA:MAX:0.4:${stepsPerHour}:${keepHours}"; + push @cmd, "RRA:AVERAGE:0.5:${stepsPerHour}:${keepHours}"; RRDs::create(@cmd); if (RRDs::error) { @@ -199,9 +201,16 @@ sub dayGraphFunc { } my $dayCons = ''; my $consFunc = ''; - for (my $i = 1; $i < $dataPoints; ++$i) { - $dayCons .= "prev${mode}${i},"; - $consFunc .= ",${mode}"; + if ($mode ne 'AVG') { + for (my $i = 1; $i < $dataPoints; ++$i) { + $dayCons .= "prev${mode}${i},"; + $consFunc .= ",${mode}"; + } + } else { + for (my $i = 1; $i < $dataPoints; ++$i) { + $dayCons .= "prev${mode}${i},"; + } + $consFunc = ",${dataPoints},${mode}"; } push @args, "CDEF:day${mode}=${dayCons}${dataSrc}${consFunc}"; push @args, "CDEF:fillCalDay${mode}0=COUNT,${dataPoints},%,0,EQ,day${mode},UNKN,IF"; @@ -235,6 +244,8 @@ sub cfgToGraphDef { push @graphDef, @{dayGraphFunc("${varname}-min", 'MIN', '0000ff', 'Day Minimum Temperature', $dpPerDay)}; } elsif ($subGraph eq 'day-max') { push @graphDef, @{dayGraphFunc("${varname}-max", 'MAX', '00ff00', 'Day Maximum Temperature', $dpPerDay)}; + } elsif ($subGraph eq 'day-avg') { + push @graphDef, @{dayGraphFunc("${varname}-houravg", 'AVG', 'ff0000', 'Day Average Temperature', $dpPerDay)}; } } return \@graphDef; @@ -360,7 +371,7 @@ foreach my $host (@$hosts) { } if ($rrdinfo->{'rra[0].rows'} != $keep || - !defined($rrdinfo->{'rra[1].rows'}) || $rrdinfo->{'rra[1].rows'} != $keepHours || + !defined($rrdinfo->{'rra[3].rows'}) || $rrdinfo->{'rra[3].rows'} != $keepHours || $limitsChanged == 1) { print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} . @@ -427,6 +438,7 @@ die "fork failed!" if (!defined($child)); exit 0 if ($child != 0); +my $first = $UPSGRAPH::regenerateOnStart; while(1) { open(HTML, ">${outdir}/index.html.new"); @@ -503,11 +515,13 @@ while(1) { }; } - my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}); + my @graphdef = ('-P', "-A", "-t", $hostname." - ".$vars->{$var}->{'name'}); + push @graphdef, "--lazy" if !$first; push @graphdef, "DEF:${var}-avg=${rrdfile}.${var}:${var}:AVERAGE"; push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN"; push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX"; + push @graphdef, "DEF:${var}-houravg=${rrdfile}.${var}:${var}:AVERAGE:step=3600"; push @graphdef, "LINE1:${var}-avg#FF0000"; push @graphdef, "VDEF:cur=${var}-avg,LAST"; push @graphdef, 'GPRINT:cur:Current\\: %.2lf\\r'; @@ -628,4 +642,5 @@ while(1) { rename("${outdir}/index.html.new", "${outdir}/index.html"); sleep(${step}/2); + $first = 0; }