From 3d7df03fdea9e5c8d72b08bf6df57203be5885e5 Mon Sep 17 00:00:00 2001 From: Benjamin Oechslein Date: Fri, 9 Jan 2015 22:10:13 +0100 Subject: [PATCH] Add appropriate MIN/MAX RRAs to rrd files on creation and trigger recreation, if they are not yet present. --- upsgraph.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/upsgraph.pl b/upsgraph.pl index 3077e23..1e335ac 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -17,15 +17,20 @@ use File::Copy; use Data::Dumper; $UPSGRAPH::outdir = ""; +$UPSGRAPH::daysCovered = 370; $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; +my $stepsPerHour = $UPSGRAPH::stepsPerHour; my $keep = $UPSGRAPH::keep; +my $keepHours = $UPSGRAPH::keepHours; my $hosts = $UPSGRAPH::hosts; sub rrd_update(@) { @@ -82,6 +87,8 @@ sub rrdcreate(@) { $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) { @@ -291,7 +298,9 @@ foreach my $host (@$hosts) { 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"; @@ -310,7 +319,7 @@ foreach my $host (@$hosts) { $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) { @@ -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"); - + + 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\\: %.2lf\\r'; @@ -446,13 +457,13 @@ while(1) { print HTML2 '' . $vars->{$var}->{'name'} . ''; print HTML2 ''; - 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, "VDEF:max=${var},MAXIMUM"; + push @graphdef, "VDEF:max=${var}-max,MAXIMUM"; push @graphdef, "GPRINT:max:Maximum\\: %.2lf"; push @graphdef, "VDEF:cur=${var},LAST"; -- 2.39.2