]> git.zerfleddert.de Git - upsgraph/blobdiff - upsgraph.pl
Add appropriate MIN/MAX RRAs to rrd files on creation and trigger recreation, if...
[upsgraph] / upsgraph.pl
index 3077e2357abaa0c458b56e1428a4b783782335c8..1e335acd1aa613b9a151140a4cf965b04a967203 100755 (executable)
@@ -17,15 +17,20 @@ use File::Copy;
 use Data::Dumper;
 
 $UPSGRAPH::outdir = "";
 use Data::Dumper;
 
 $UPSGRAPH::outdir = "";
+$UPSGRAPH::daysCovered = 370;
 $UPSGRAPH::step = 60;
 $UPSGRAPH::step = 60;
-$UPSGRAPH::keep = (370*24*60*60)/$UPSGRAPH::step;
+$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 = ();
 
 do $ARGV[0] or die "can't read config: $!";
 
 my $outdir = $UPSGRAPH::outdir;
 my $step = $UPSGRAPH::step;
 $UPSGRAPH::hosts = ();
 
 do $ARGV[0] or die "can't read config: $!";
 
 my $outdir = $UPSGRAPH::outdir;
 my $step = $UPSGRAPH::step;
+my $stepsPerHour = $UPSGRAPH::stepsPerHour;
 my $keep = $UPSGRAPH::keep;
 my $keep = $UPSGRAPH::keep;
+my $keepHours = $UPSGRAPH::keepHours;
 my $hosts = $UPSGRAPH::hosts;
 
 sub rrd_update(@) {
 my $hosts = $UPSGRAPH::hosts;
 
 sub rrd_update(@) {
@@ -82,6 +87,8 @@ sub rrdcreate(@) {
                $vars->{$field}->{'max'};
 
        push @cmd, "RRA:AVERAGE:0.5:1:${keep}";
                $vars->{$field}->{'max'};
 
        push @cmd, "RRA:AVERAGE:0.5:1:${keep}";
+       push @cmd, "RRA:MIN:0.4:${stepsPerHour}:${keepHours}";
+       push @cmd, "RRA:MAX:0.4:${stepsPerHour}:${keepHours}";
 
        RRDs::create(@cmd);
        if (RRDs::error) {
 
        RRDs::create(@cmd);
        if (RRDs::error) {
@@ -291,7 +298,9 @@ foreach my $host (@$hosts) {
                        exit 1;
                }
                    
                        exit 1;
                }
                    
-               if ($rrdinfo->{'rra[0].rows'} != $keep) {
+               if ($rrdinfo->{'rra[0].rows'} != $keep ||
+                       !defined($rrdinfo->{'rra[1].rows'}) || $rrdinfo->{'rra[1].rows'} != $keepHours) {
+
                        print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} .
                                " to ${keep} samples.\n";
 
                        print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} .
                                " to ${keep} samples.\n";
 
@@ -310,7 +319,7 @@ foreach my $host (@$hosts) {
                                $host->{'vars'},
                                (${start}-${ostep}));
 
                                $host->{'vars'},
                                (${start}-${ostep}));
 
-                       print "Preserving data since " . localtime($start) . "\n";
+                       print "Preserving data in file ${rrdfile}.${field} since " . localtime($start) . "\n";
 
                        my $pos = $start;
                        foreach my $line (@$data) {
 
                        my $pos = $start;
                        foreach my $line (@$data) {
@@ -416,7 +425,9 @@ while(1) {
 
                foreach my $var (@{$host->{'fields'}}) {
                        my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}, "DEF:${var}=${rrdfile}.${var}:${var}:AVERAGE", "LINE1:${var}#FF0000");
 
                foreach my $var (@{$host->{'fields'}}) {
                        my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}, "DEF:${var}=${rrdfile}.${var}:${var}:AVERAGE", "LINE1:${var}#FF0000");
-
+                       
+                       push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN", "LINE1:${var}-min#0000FF";
+                       push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX", "LINE1:${var}-max#00FF00";
                        push @graphdef, "VDEF:cur=${var},LAST";
                        push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r';
 
                        push @graphdef, "VDEF:cur=${var},LAST";
                        push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r';
 
@@ -446,13 +457,13 @@ while(1) {
                        print HTML2 '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
                        print HTML2 '<body bgcolor="#ffffff">';
 
                        print HTML2 '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
                        print HTML2 '<body bgcolor="#ffffff">';
 
-                       push @graphdef, "VDEF:min=${var},MINIMUM";
+                       push @graphdef, "VDEF:min=${var}-min,MINIMUM";
                        push @graphdef, "GPRINT:min:Minimum\\: %.2lf";
 
                        push @graphdef, "VDEF:avg=${var},AVERAGE";
                        push @graphdef, "GPRINT:avg:Average\\: %.2lf";
 
                        push @graphdef, "GPRINT:min:Minimum\\: %.2lf";
 
                        push @graphdef, "VDEF:avg=${var},AVERAGE";
                        push @graphdef, "GPRINT:avg:Average\\: %.2lf";
 
-                       push @graphdef, "VDEF:max=${var},MAXIMUM";
+                       push @graphdef, "VDEF:max=${var}-max,MAXIMUM";
                        push @graphdef, "GPRINT:max:Maximum\\: %.2lf";
 
                        push @graphdef, "VDEF:cur=${var},LAST";
                        push @graphdef, "GPRINT:max:Maximum\\: %.2lf";
 
                        push @graphdef, "VDEF:cur=${var},LAST";
Impressum, Datenschutz