From 5225937733d50608843fbf146b6ddda2b48ca237 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 10 Feb 2010 23:14:48 +0100 Subject: [PATCH 1/1] only copy files when they have changed --- upsgraph.pl | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/upsgraph.pl b/upsgraph.pl index e846a23..05553fd 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -325,6 +325,10 @@ while(1) { foreach my $var (@{$host->{'fields'}}) { my @graphdef = ("--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}, "DEF:${var}=${rrdfile}.${var}:${var}:AVERAGE", "LINE1:${var}#FF0000"); + + my $mtime; + $mtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9]; + (my $averages, my $width, my $height) = RRDs::graph("${outdir}/${hostname}.${var}.png.work", "-w", "720", @graphdef); @@ -332,8 +336,11 @@ while(1) { if (RRDs::error) { print "Error while graphing: " . RRDs::error . "\n"; } else { - copy("${outdir}/${hostname}.${var}.png.work", "${outdir}/${hostname}.${var}.png.new"); - rename("${outdir}/${hostname}.${var}.png.new", "${outdir}/${hostname}.${var}.png"); + my $newmtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9]; + if ($newmtime != $mtime) { + copy("${outdir}/${hostname}.${var}.png.work", "${outdir}/${hostname}.${var}.png.new"); + rename("${outdir}/${hostname}.${var}.png.new", "${outdir}/${hostname}.${var}.png"); + } } print HTML "
\n"; @@ -355,6 +362,7 @@ while(1) { push @graphdef, "VDEF:cur=${var},LAST"; push @graphdef, "GPRINT:cur:Current\\: %.2lf"; + $mtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9]; ($averages, $width, $height) = RRDs::graph("${outdir}/${hostname}.${var}.long.png.work", "-w", "1008", @graphdef); @@ -362,12 +370,16 @@ while(1) { if (RRDs::error) { print "Error while graphing: " . RRDs::error . "\n"; } else { - copy("${outdir}/${hostname}.${var}.long.png.work", "${outdir}/${hostname}.${var}.long.png.new"); - rename("${outdir}/${hostname}.${var}.long.png.new", "${outdir}/${hostname}.${var}.long.png"); + my $newmtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9]; + if ($newmtime != $mtime) { + copy("${outdir}/${hostname}.${var}.long.png.work", "${outdir}/${hostname}.${var}.long.png.new"); + rename("${outdir}/${hostname}.${var}.long.png.new", "${outdir}/${hostname}.${var}.long.png"); + } } print HTML2 "
"; + $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; ($averages, $width, $height) = RRDs::graph("${outdir}/${hostname}.${var}.week.png.work", "-w", "1008", "-e", "now", "-s", "end-1w", @graphdef); @@ -375,12 +387,16 @@ while(1) { if (RRDs::error) { print "Error while graphing: " . RRDs::error . "\n"; } else { - copy("${outdir}/${hostname}.${var}.week.png.work", "${outdir}/${hostname}.${var}.week.png.new"); - rename("${outdir}/${hostname}.${var}.week.png.new", "${outdir}/${hostname}.${var}.week.png"); + my $newmtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; + if ($newmtime != $mtime) { + copy("${outdir}/${hostname}.${var}.week.png.work", "${outdir}/${hostname}.${var}.week.png.new"); + rename("${outdir}/${hostname}.${var}.week.png.new", "${outdir}/${hostname}.${var}.week.png"); + } } print HTML2 "
"; + $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; ($averages, $width, $height) = RRDs::graph("${outdir}/${hostname}.${var}.year.png.work", "-w", "1008", "-e", "now", "-s", "end-1y", @graphdef); @@ -388,8 +404,11 @@ while(1) { if (RRDs::error) { print "Error while graphing: " . RRDs::error . "\n"; } else { - copy("${outdir}/${hostname}.${var}.year.png.work", "${outdir}/${hostname}.${var}.year.png.new"); - rename("${outdir}/${hostname}.${var}.year.png.new", "${outdir}/${hostname}.${var}.year.png"); + my $newmtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; + if ($newmtime != $mtime) { + copy("${outdir}/${hostname}.${var}.year.png.work", "${outdir}/${hostname}.${var}.year.png.new"); + rename("${outdir}/${hostname}.${var}.year.png.new", "${outdir}/${hostname}.${var}.year.png"); + } } print HTML2 "
"; -- 2.39.5