]> git.zerfleddert.de Git - upsgraph/commitdiff
Add daily average graph mode
authorBenjamin Oechslein <benjamin.oechslein@informatik.uni-erlangen.de>
Mon, 12 Jan 2015 22:08:46 +0000 (23:08 +0100)
committerBenjamin Oechslein <oechslein@informatik.uni-erlangen.de>
Mon, 19 Jan 2015 16:47:45 +0000 (17:47 +0100)
upsgraph.pl

index cade9b25c20b2f10323c4c21b533b32cecda79dd..e55622b38b8e35cfa9819db25fae89f0e176d0ab 100755 (executable)
@@ -90,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: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) {
 
        RRDs::create(@cmd);
        if (RRDs::error) {
@@ -200,9 +201,16 @@ sub dayGraphFunc {
        }
        my $dayCons = '';
        my $consFunc = '';
        }
        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";
        }
        push @args, "CDEF:day${mode}=${dayCons}${dataSrc}${consFunc}";
        push @args, "CDEF:fillCalDay${mode}0=COUNT,${dataPoints},%,0,EQ,day${mode},UNKN,IF";
@@ -236,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)};
                        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;
                }
        }
        return \@graphDef;
@@ -361,7 +371,7 @@ foreach my $host (@$hosts) {
                }
                    
                if ($rrdinfo->{'rra[0].rows'} != $keep ||
                }
                    
                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'} .
                        $limitsChanged == 1) {
 
                        print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} .
@@ -511,6 +521,7 @@ while(1) {
                        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}-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\\: <span foreground="#FF0000">%.2lf</span>\\r';
                        push @graphdef, "LINE1:${var}-avg#FF0000";
                        push @graphdef, "VDEF:cur=${var}-avg,LAST";
                        push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r';
Impressum, Datenschutz