]> git.zerfleddert.de Git - upsgraph/blobdiff - upsgraph.pl
Add option to regenerate graphs on script startup
[upsgraph] / upsgraph.pl
index 3f17d38409199cf128004ac4f26fe57606ee10ee..e291cc73abe6f7efd6f014346e2e790e4d72bf65 100755 (executable)
@@ -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: $!";
 
@@ -325,12 +326,15 @@ foreach my $host (@$hosts) {
                        exit 1;
                }
 
+               my $limitsChanged = 0;
                if (defined($rrdinfo->{"ds[${field}].min"})) {
                        if ($rrdinfo->{"ds[${field}].min"} ne $host->{'vars'}->{$field}->{'min'}) {
+                               $limitsChanged = 1;
                                RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'});
                        }
                } else {
                        if ($host->{'vars'}->{$field}->{'min'} ne 'U') {
+                               $limitsChanged = 1;
                                RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'});
                        }
                }
@@ -342,10 +346,12 @@ foreach my $host (@$hosts) {
 
                if (defined($rrdinfo->{"ds[${field}].max"})) {
                        if ($rrdinfo->{"ds[${field}].max"} ne $host->{'vars'}->{$field}->{'max'}) {
+                               $limitsChanged = 1;
                                RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'});
                        }
                } else {
                        if ($host->{'vars'}->{$field}->{'max'} ne 'U') {
+                               $limitsChanged = 1;
                                RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'});
                        }
                }
@@ -356,7 +362,8 @@ foreach my $host (@$hosts) {
                }
                    
                if ($rrdinfo->{'rra[0].rows'} != $keep ||
-                       !defined($rrdinfo->{'rra[1].rows'}) || $rrdinfo->{'rra[1].rows'} != $keepHours) {
+                       !defined($rrdinfo->{'rra[1].rows'}) || $rrdinfo->{'rra[1].rows'} != $keepHours ||
+                       $limitsChanged == 1) {
 
                        print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} .
                                " to ${keep} samples.\n";
@@ -422,6 +429,7 @@ foreach my $host (@$hosts) {
 #
 #exit 0 if ($child != 0);
 
+my $first = $UPSGRAPH::regenerateOnStart;
 while(1) {
        open(HTML, ">${outdir}/index.html.new");
 
@@ -498,7 +506,8 @@ while(1) {
                                };
                        }
 
-                       my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'});
+                       my @graphdef = ('-P', "-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";
@@ -623,4 +632,5 @@ while(1) {
        rename("${outdir}/index.html.new", "${outdir}/index.html");
 
        sleep(${step}/2);
+       $first = 0;
 }
Impressum, Datenschutz