X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/3679b92785fa7106d07999fcc95750457693e077..3d7df03fdea9e5c8d72b08bf6df57203be5885e5:/upsgraph.pl?ds=sidebyside
diff --git a/upsgraph.pl b/upsgraph.pl
index 010d114..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(@) {
@@ -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) {
@@ -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';
@@ -443,16 +454,16 @@ while(1) {
print HTML "
\n";
open (HTML2, ">${outdir}/${hostname}.${var}.html.new");
- print HTML2 '