X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/41cfd72381789f7b695a18d1051a938f2204b884..fd198fcdfda36da547af84d57ab456faf16a0dd0:/upsgraph.pl diff --git a/upsgraph.pl b/upsgraph.pl index 954b8b0..c8bc4c6 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(@) { @@ -79,9 +84,11 @@ sub rrdcreate(@) { push @cmd, "DS:${field}:GAUGE:600:" . $vars->{$field}->{'min'} . ":" . - $vars->{$field}->{'max'} . " "; + $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) { @@ -177,6 +184,45 @@ sub fetch_tcp_multi(@) { %values; } +sub dayGraphFunc { + my $dataSrc = shift; + my $mode = shift; + my $color = shift; + my $label = shift; + my $dataPoints = shift; + my @args = (); + push @args, "CDEF:prev${mode}1=PREV(${dataSrc})"; + for (my $i = 1; $i < $dataPoints - 1; ++$i) { + my $prev = $i; + my $next = $i+1; + push @args, "CDEF:prev${mode}${next}=PREV(prev${mode}${prev})"; + } + my $dayCons = ''; + my $consFunc = ''; + for (my $i = 1; $i < $dataPoints; ++$i) { + $dayCons .= "prev${mode}${i},"; + $consFunc .= ",${mode}"; + } + push @args, "CDEF:day${mode}=${dayCons}${dataSrc}${consFunc}"; + push @args, "CDEF:fillCalDay${mode}0=COUNT,${dataPoints},%,0,EQ,day${mode},UNKN,IF"; + for (my $i = 1; $i < $dataPoints; ++$i) { + my $prev = $i-1; + my $next = $i; + push @args, "CDEF:fillCalDay${mode}${next}=PREV(fillCalDay${mode}${prev})"; + } + my $fillPoint = ''; + my $if = ''; + for (my $i = 0; $i < $dataPoints; ++$i) { + $fillPoint .= "COUNT,${dataPoints},%,${i},EQ,fillCalDay${mode}${i},"; + $if .= ",IF"; + } + push @args, "CDEF:${mode}Curve=${fillPoint}UNKN${if}"; + my $forwardShift = (24*60*60) * ($dataPoints - 1) / $dataPoints; + push @args, "SHIFT:${mode}Curve:-${forwardShift}"; + push @args, "LINE1:${mode}Curve#${color}:${label}"; + return \@args; +} + if ($> == 0) { if (@ARGV != 2) { print STDERR "Running as root, please provide UID as 2th argument!\n"; @@ -291,7 +337,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 +358,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 +464,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 +496,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"; @@ -473,7 +523,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; ($averages, $width, $height) = @@ -490,7 +540,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; ($averages, $width, $height) = @@ -507,7 +557,7 @@ while(1) { } } - print HTML2 "
"; + print HTML2 "
\n"; print HTML2 "\n"; close(HTML2);