]> git.zerfleddert.de Git - upsgraph/blob - upsgraph.pl
adf33c968e96bfd7e71c5f612cae759f9e40a3d8
[upsgraph] / upsgraph.pl
1 #!/usr/bin/perl -w
2
3 #Due to memory leak in Debian squeeze (Bug #545519)
4 my $use_rrds = 0;
5 my $rrd_result = 0;
6
7 if ((@ARGV != 1) && (@ARGV != 2)) {
8 print STDERR "Syntax: ${0} configfile [uid]\n";
9 exit(1);
10 }
11
12 use Net::SNMP;
13 use IO::Socket::INET;
14 use IO::Select;
15 use RRDs;
16 use File::Copy;
17 use Data::Dumper;
18
19 $UPSGRAPH::outdir = "";
20 $UPSGRAPH::daysCovered = 370;
21 $UPSGRAPH::step = 60;
22 $UPSGRAPH::stepsPerHour = (60 * 60) / $UPSGRAPH::step;
23 $UPSGRAPH::keep = ($UPSGRAPH::daysCovered*24*60*60)/$UPSGRAPH::step;
24 $UPSGRAPH::keepHours = ($UPSGRAPH::daysCovered*24*60*60)/$UPSGRAPH::stepsPerHour/$UPSGRAPH::step;
25 $UPSGRAPH::hosts = ();
26 $UPSGRAPH::regenerateOnStart = 1; #when set, regenerate graphs on script startup
27
28 do $ARGV[0] or die "can't read config: $!";
29
30 my $outdir = $UPSGRAPH::outdir;
31 my $step = $UPSGRAPH::step;
32 my $stepsPerHour = $UPSGRAPH::stepsPerHour;
33 my $keep = $UPSGRAPH::keep;
34 my $keepHours = $UPSGRAPH::keepHours;
35 my $hosts = $UPSGRAPH::hosts;
36
37 sub rrd_update(@) {
38 my @args = @_;
39
40 if ($use_rrds == 1) {
41 RRDs::update(@args);
42 $rrd_result = RRDs::error;
43 } else {
44 $rrd_result = system("rrdtool", "update", @args);
45 }
46 }
47
48 sub rrd_graph(@) {
49 my @args = @_;
50 my @rrd_out = ();
51
52 if ($use_rrds == 1) {
53 @rrd_out = RRDs::graph(@args);
54 $rrd_result = RRDs::error;
55 } else {
56 my $rrd_stdout;
57
58 open(RRDFD, '-|', 'rrdtool', 'graph', @args);
59 while(<RRDFD>) {
60 chomp;
61 $rrd_stdout = $_;
62 }
63 close(RRDFD);
64 $rrd_result = $?;
65 if ($rrd_result == 0) {
66 push @rrd_out, 0;
67 push @rrd_out, split(/x/, $rrd_stdout);
68 }
69 }
70
71 return @rrd_out;
72 }
73
74 sub rrdcreate(@) {
75 my $newrrd = shift;
76 my $field = shift;
77 my $vars = shift;
78 my $start = shift;
79
80 my @cmd = ("${newrrd}", "--step=${step}");
81
82 if (defined($start)) {
83 push @cmd, "--start=${start}";
84 }
85
86 push @cmd, "DS:${field}:GAUGE:600:" .
87 $vars->{$field}->{'min'} . ":" .
88 $vars->{$field}->{'max'};
89
90 push @cmd, "RRA:AVERAGE:0.5:1:${keep}";
91 push @cmd, "RRA:MIN:0.4:${stepsPerHour}:${keepHours}";
92 push @cmd, "RRA:MAX:0.4:${stepsPerHour}:${keepHours}";
93 push @cmd, "RRA:AVERAGE:0.5:${stepsPerHour}:${keepHours}";
94
95 RRDs::create(@cmd);
96 if (RRDs::error) {
97 print "Error while creating: " . RRDs::error . "\n";
98 exit 1;
99 }
100 }
101
102 sub fetch_snmp(@) {
103 my $address = shift;
104 my $community = shift;
105 my $oid = shift;
106
107 (my $session, my $error) = Net::SNMP->session(Hostname => $address,
108 Community => $community);
109
110 if (!$session) {
111 print STDERR "session error: $error";
112 return undef;
113 }
114
115 $session->translate(0);
116
117 my $result = $session->get_request($oid);
118
119 $session->close;
120
121 return undef if (!defined($result));
122
123 $result->{$oid};
124 }
125
126 sub fetch_tcp(@) {
127 my $address = shift;
128 my $port = shift;
129
130 my $sock = IO::Socket::INET->new(PeerAddr => $address,
131 PeerPort => $port,
132 Proto => 'tcp',
133 Timeout => 1);
134
135 return undef if (!$sock);
136
137 my $select = IO::Select->new($sock);
138
139 my $value = undef;
140
141 if ($select->can_read(1)) {
142 chomp($value) if (sysread($sock, $value, 4096) > 0);
143 }
144
145 close($sock);
146
147 if (!$value) {
148 return undef;
149 }
150
151 $value=~ s/\s//g;
152
153 $value;
154 }
155
156 sub fetch_tcp_multi(@) {
157 my $address = shift;
158 my $port = shift;
159 my $delimiter = shift;
160 my %values;
161
162 my $sock = IO::Socket::INET->new(PeerAddr => $address,
163 PeerPort => $port,
164 Proto => 'tcp',
165 Timeout => 1);
166
167 return undef if (!$sock);
168
169 my $select = IO::Select->new($sock);
170
171 while($select->can_read(1)) {
172 if (sysread($sock, my $buf, 16384) > 0) {
173 $buf=~s/\r//g;
174 foreach my $line (split(/\n/, $buf)) {
175 (my $key, my $value) = split(/${delimiter}/, $line);
176 $value=~ s/\s//g;
177 $values{$key} = $value;
178 }
179 } else {
180 last;
181 }
182 }
183
184 close($sock);
185
186 %values;
187 }
188
189 sub dayGraphFunc {
190 my $dataSrc = shift;
191 my $mode = shift;
192 my $color = shift;
193 my $label = shift;
194 my $dataPoints = shift;
195 my @args = ();
196 push @args, "CDEF:prev${mode}1=PREV(${dataSrc})";
197 for (my $i = 1; $i < $dataPoints - 1; ++$i) {
198 my $prev = $i;
199 my $next = $i+1;
200 push @args, "CDEF:prev${mode}${next}=PREV(prev${mode}${prev})";
201 }
202 my $dayCons = '';
203 my $consFunc = '';
204 if ($mode ne 'AVG') {
205 for (my $i = 1; $i < $dataPoints; ++$i) {
206 $dayCons .= "prev${mode}${i},";
207 $consFunc .= ",${mode}";
208 }
209 } else {
210 for (my $i = 1; $i < $dataPoints; ++$i) {
211 $dayCons .= "prev${mode}${i},";
212 }
213 $consFunc = ",${dataPoints},${mode}";
214 }
215 push @args, "CDEF:day${mode}=${dayCons}${dataSrc}${consFunc}";
216 push @args, "CDEF:fillCalDay${mode}0=COUNT,${dataPoints},%,0,EQ,day${mode},UNKN,IF";
217 for (my $i = 1; $i < $dataPoints; ++$i) {
218 my $prev = $i-1;
219 my $next = $i;
220 push @args, "CDEF:fillCalDay${mode}${next}=PREV(fillCalDay${mode}${prev})";
221 }
222 my $fillPoint = '';
223 my $if = '';
224 for (my $i = 0; $i < $dataPoints; ++$i) {
225 $fillPoint .= "COUNT,${dataPoints},%,${i},EQ,fillCalDay${mode}${i},";
226 $if .= ",IF";
227 }
228 push @args, "CDEF:${mode}Curve=${fillPoint}UNKN${if}";
229 my $forwardShift = (24*60*60) * ($dataPoints - 1) / $dataPoints;
230 push @args, "SHIFT:${mode}Curve:-${forwardShift}";
231 push @args, "LINE1:${mode}Curve#${color}:${label}";
232 return \@args;
233 }
234
235 sub cfgToGraphDef {
236 my $cfg = shift;
237 my $varname = shift;
238 my $dpPerDay= shift;
239 my @graphDef = ();
240 foreach my $subGraph (@$cfg) {
241 if ($subGraph eq 'avg') {
242 push @graphDef, "LINE1:${varname}-avg#FF0000";
243 } elsif ($subGraph eq 'day-min') {
244 push @graphDef, @{dayGraphFunc("${varname}-min", 'MIN', '0000ff', 'Day Minimum Temperature', $dpPerDay)};
245 } elsif ($subGraph eq 'day-max') {
246 push @graphDef, @{dayGraphFunc("${varname}-max", 'MAX', '00ff00', 'Day Maximum Temperature', $dpPerDay)};
247 } elsif ($subGraph eq 'day-avg') {
248 push @graphDef, @{dayGraphFunc("${varname}-houravg", 'AVG', 'ff0000', 'Day Average Temperature', $dpPerDay)};
249 }
250 }
251 return \@graphDef;
252 }
253
254 if ($> == 0) {
255 if (@ARGV != 2) {
256 print STDERR "Running as root, please provide UID as 2th argument!\n";
257 exit(1);
258 }
259
260 print "Running as root, switching to ".$ARGV[1]."\n";
261 $< = $> = $ARGV[1];
262 }
263
264 foreach my $host (@$hosts) {
265 my $rrdfile = $host->{'rrdfile'};
266
267 foreach my $var (keys(%{$host->{'vars'}})) {
268 $host->{'vars'}->{$var}->{'min'} = 'U' if (!defined($host->{'vars'}->{$var}->{'min'}));
269 $host->{'vars'}->{$var}->{'max'} = 'U' if (!defined($host->{'vars'}->{$var}->{'max'}));
270 }
271
272 if (-e "${rrdfile}") {
273 print "Reading old ${rrdfile} to preserve data...\n";
274
275 my $rrdinfo = RRDs::info("${rrdfile}");
276 if (RRDs::error) {
277 print "Error while getting info: " . RRDs::error . "\n";
278 exit 1;
279 }
280
281 (my $start, my $ostep, my $names, my $data) =
282 RRDs::fetch("${rrdfile}",
283 "-s " . (time() - ($rrdinfo->{'rra[0].rows'} * $rrdinfo->{'step'})),
284 "AVERAGE");
285
286 if (RRDs::error) {
287 print "Error while fetching data: " . RRDs::error . "\n";
288 exit 1;
289 }
290
291 foreach my $field (@$names) {
292 if (! -e "${rrdfile}.${field}") {
293 rrdcreate("${rrdfile}.${field}",
294 "${field}",
295 $host->{'vars'},
296 (${start}-${ostep}));
297 }
298 }
299
300 my $pos = $start;
301 foreach my $line (@$data) {
302 foreach my $field (@$names) {
303 my $val = shift (@$line);
304 $val = 'U' if (!defined($val));
305
306 RRDs::update("${rrdfile}.${field}", "${pos}:${val}");
307 if (RRDs::error) {
308 print "Can't insert data: " . RRDs::error . "\n";
309 exit 1;
310 }
311
312 }
313
314 $pos += $ostep;
315
316 if ((($pos-$start)/$ostep) == $#$data) {
317 last;
318 }
319 }
320
321 rename("${rrdfile}", "${rrdfile}.old") or die "Can't rename old file: $!\n";
322 }
323
324 foreach my $field (@{$host->{'fields'}}) {
325 if (! -e "${rrdfile}.${field}") {
326 print "Creating ${rrdfile}.${field}...\n";
327 rrdcreate("${rrdfile}.${field}",
328 "${field}",
329 $host->{'vars'});
330 }
331
332 my $rrdinfo = RRDs::info("${rrdfile}.${field}");
333 if (RRDs::error) {
334 print "Error while getting info: " . RRDs::error . "\n";
335 exit 1;
336 }
337
338 my $limitsChanged = 0;
339 if (defined($rrdinfo->{"ds[${field}].min"})) {
340 if ($rrdinfo->{"ds[${field}].min"} ne $host->{'vars'}->{$field}->{'min'}) {
341 $limitsChanged = 1;
342 RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'});
343 }
344 } else {
345 if ($host->{'vars'}->{$field}->{'min'} ne 'U') {
346 $limitsChanged = 1;
347 RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'});
348 }
349 }
350
351 if (RRDs::error) {
352 print "Error while setting min: " . RRDs::error . "\n";
353 exit 1;
354 }
355
356 if (defined($rrdinfo->{"ds[${field}].max"})) {
357 if ($rrdinfo->{"ds[${field}].max"} ne $host->{'vars'}->{$field}->{'max'}) {
358 $limitsChanged = 1;
359 RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'});
360 }
361 } else {
362 if ($host->{'vars'}->{$field}->{'max'} ne 'U') {
363 $limitsChanged = 1;
364 RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'});
365 }
366 }
367
368 if (RRDs::error) {
369 print "Error while setting max: " . RRDs::error . "\n";
370 exit 1;
371 }
372
373 if ($rrdinfo->{'rra[0].rows'} != $keep ||
374 !defined($rrdinfo->{'rra[3].rows'}) || $rrdinfo->{'rra[3].rows'} != $keepHours ||
375 $limitsChanged == 1) {
376
377 print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} .
378 " to ${keep} samples.\n";
379
380 (my $start, my $ostep, my $names, my $data) =
381 RRDs::fetch("${rrdfile}.${field}",
382 "-s " . (time() - ($rrdinfo->{'rra[0].rows'} * $rrdinfo->{'step'})),
383 "AVERAGE");
384
385 if (RRDs::error) {
386 print "Error while fetching data: " . RRDs::error . "\n";
387 exit 1;
388 }
389
390 rrdcreate("${rrdfile}.${field}.new",
391 "${field}",
392 $host->{'vars'},
393 (${start}-${ostep}));
394
395 print "Preserving data in file ${rrdfile}.${field} since " . localtime($start) . "\n";
396
397 my $pos = $start;
398 foreach my $line (@$data) {
399 my $vline = "${pos}";
400
401 foreach my $val (@$line) {
402 $val = 'U' if (!defined($val));
403 $vline .= ":${val}";
404 }
405 RRDs::update("${rrdfile}.${field}.new", $vline) or die "Can't insert data\n";
406
407 if (RRDs::error) {
408 print "Error while updating: " . RRDs::error . "\n";
409 exit 1;
410 }
411 $pos += $ostep;
412
413 if ((($pos-$start)/$ostep) == $#$data) {
414 last;
415 }
416 }
417
418 rename("${rrdfile}.${field}", "${rrdfile}.${field}.old") or die "Can't rename old file: $!\n";
419 rename("${rrdfile}.${field}.new", "${rrdfile}.${field}") or die "Can't rename new file: $!\n";
420
421 $rrdinfo = RRDs::info("${rrdfile}.${field}");
422 if (RRDs::error) {
423 print "Error while getting info: " . RRDs::error . "\n";
424 exit 1;
425 }
426
427 if ($rrdinfo->{'rra[0].rows'} != $keep) {
428 print "Failed!\n";
429 exit 1;
430 }
431 }
432 }
433 }
434
435 my $child = fork();
436
437 die "fork failed!" if (!defined($child));
438
439 exit 0 if ($child != 0);
440
441 my $first = $UPSGRAPH::regenerateOnStart;
442 while(1) {
443 open(HTML, ">${outdir}/index.html.new");
444
445 print HTML '<html><head><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>Status</title></head>';
446 print HTML '<body bgcolor="#ffffff">';
447
448 foreach my $host (@$hosts) {
449 print HTML "[<a href=\"#".${host}->{'name'}."\">".${host}->{'name'}."</a>]&nbsp;";
450 }
451 print HTML "<br>\n";
452
453 foreach my $host (@$hosts) {
454 print HTML "<br>\n";
455 print HTML "<a name=\"".${host}->{'name'}."\"></a>\n";
456 my $vars = $host->{'vars'};
457 my $rrdfile = $host->{'rrdfile'};
458 my $hostname = $host->{'name'};
459 my %multi_values = ();
460
461 foreach my $var (@{$host->{'fields'}}) {
462 delete $vars->{$var}->{'value'};
463
464 my $result;
465
466 if ((!defined($vars->{$var}->{'proto'})) ||
467 ($vars->{$var}->{'proto'} eq '') ||
468 ($vars->{$var}->{'proto'} eq 'snmp')) {
469 $result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'});
470 } elsif ($vars->{$var}->{'proto'} eq 'tcp') {
471 $result = fetch_tcp($host->{'address'}, $vars->{$var}->{'port'});
472 } elsif ($vars->{$var}->{'proto'} eq 'tcp_multi') {
473 if (defined($multi_values{$vars->{$var}->{'multi_id'}})) {
474 $result = $multi_values{$vars->{$var}->{'multi_id'}}
475 } else {
476 my %values = fetch_tcp_multi($host->{'address'}, $vars->{$var}->{'port'}, $vars->{$var}->{'multi_delimiter'});
477 @multi_values{keys %values} = values %values;
478 $result = $multi_values{$vars->{$var}->{'multi_id'}};
479 }
480 }
481
482 next unless (defined $result);
483
484 $vars->{$var}->{'value'} = $result;
485 if (defined($vars->{$var}->{'factor'})) {
486 $vars->{$var}->{'value'} *= $vars->{$var}->{'factor'};
487 }
488 }
489
490 foreach my $var (@{$host->{'fields'}}) {
491 if (!(defined($vars->{$var}->{'value'}))) {
492 $vars->{$var}->{'value'} = 'U';
493 }
494 rrd_update("${rrdfile}.${var}", "N:" . $vars->{$var}->{'value'});
495 }
496 if ($rrd_result) {
497 print "Error while updating: " . $rrd_result . "\n";
498 }
499
500 foreach my $var (@{$host->{'fields'}}) {
501 my $graphWidth = 365 * 3;
502 my $graphConfig;
503 if (defined $vars->{$var}->{'graph'}) {
504 $graphConfig = $vars->{$var}->{'graph'};
505 foreach my $subGraph (qw(day week year)) {
506 if (!defined($graphConfig->{$subGraph})) {
507 $graphConfig->{$subGraph} = [ 'avg'];
508 }
509 }
510 } else {
511 $graphConfig = {
512 'day' => [ 'avg' ],
513 'week' => [ 'avg' ],
514 'year' => [ 'avg' ],
515 };
516 }
517
518 my @graphdef = ('-P', "-A", "-t", $hostname." - ".$vars->{$var}->{'name'});
519 push @graphdef, "--lazy" if !$first;
520
521 push @graphdef, "DEF:${var}-avg=${rrdfile}.${var}:${var}:AVERAGE";
522 push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN";
523 push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX";
524 push @graphdef, "DEF:${var}-houravg=${rrdfile}.${var}:${var}:AVERAGE:step=3600";
525 push @graphdef, "LINE1:${var}-avg#FF0000";
526 push @graphdef, "VDEF:cur=${var}-avg,LAST";
527 push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r';
528
529 my $mtime;
530 $mtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9];
531
532 (my $averages, my $width, my $height) =
533 rrd_graph("${outdir}/${hostname}.${var}.png.work",
534 "-w", "720", @graphdef);
535
536 pop @graphdef;
537 pop @graphdef;
538 pop @graphdef;
539
540 if ($rrd_result) {
541 print "Error while graphing: " . $rrd_result . "\n";
542 } else {
543 my $newmtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9];
544 if ((!defined($mtime)) || ($newmtime != $mtime)) {
545 copy("${outdir}/${hostname}.${var}.png.work", "${outdir}/${hostname}.${var}.png.new");
546 rename("${outdir}/${hostname}.${var}.png.new", "${outdir}/${hostname}.${var}.png");
547 }
548 }
549
550 print HTML "<a href=\"${hostname}.${var}.html\"><img src=\"${hostname}.${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a><br>\n";
551
552 open (HTML2, ">${outdir}/${hostname}.${var}.html.new");
553 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>';
554 print HTML2 '<body bgcolor="#ffffff">';
555
556 push @graphdef, "VDEF:min=${var}-min,MINIMUM";
557 push @graphdef, "GPRINT:min:Minimum\\: %.2lf";
558
559 push @graphdef, "VDEF:avg=${var}-avg,AVERAGE";
560 push @graphdef, "GPRINT:avg:Average\\: %.2lf";
561
562 push @graphdef, "VDEF:max=${var}-max,MAXIMUM";
563 push @graphdef, "GPRINT:max:Maximum\\: %.2lf";
564
565 push @graphdef, "VDEF:cur=${var}-avg,LAST";
566 push @graphdef, "GPRINT:cur:Current\\: %.2lf";
567
568 my @dayGraphDef = @graphdef;
569 push @dayGraphDef, @{cfgToGraphDef($graphConfig->{'day'}, ${var}, 24)};
570
571 $mtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9];
572 ($averages, $width, $height) =
573 rrd_graph("${outdir}/${hostname}.${var}.long.png.work",
574 "-w", $graphWidth, @dayGraphDef);
575
576 if ($rrd_result) {
577 print "Error while graphing: " . $rrd_result . "\n";
578 } else {
579 my $newmtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9];
580 if ((!defined($mtime)) || ($newmtime != $mtime)) {
581 copy("${outdir}/${hostname}.${var}.long.png.work", "${outdir}/${hostname}.${var}.long.png.new");
582 rename("${outdir}/${hostname}.${var}.long.png.new", "${outdir}/${hostname}.${var}.long.png");
583 }
584 }
585
586 print HTML2 "<img src=\"${hostname}.${var}.long.png\" width=\"${width}\" height=\"${height}\"><br>\n";
587
588 $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9];
589
590 my @weekGraphDef = @graphdef;
591 push @weekGraphDef, @{cfgToGraphDef($graphConfig->{'week'}, ${var}, 24)};
592
593 ($averages, $width, $height) =
594 rrd_graph("${outdir}/${hostname}.${var}.week.png.work",
595 "-w", "$graphWidth", "-e", "now", "-s", "00:00-8d", @weekGraphDef);
596
597 if ($rrd_result) {
598 print "Error while graphing: " . $rrd_result . "\n";
599 } else {
600 my $newmtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9];
601 if ((!defined($mtime)) || ($newmtime != $mtime)) {
602 copy("${outdir}/${hostname}.${var}.week.png.work", "${outdir}/${hostname}.${var}.week.png.new");
603 rename("${outdir}/${hostname}.${var}.week.png.new", "${outdir}/${hostname}.${var}.week.png");
604 }
605 }
606
607 print HTML2 "<img src=\"${hostname}.${var}.week.png\" width=\"${width}\" height=\"${height}\"><br>\n";
608
609 $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9];
610
611 my @yearGraphDef = @graphdef;
612 push @yearGraphDef, @{cfgToGraphDef($graphConfig->{'year'}, ${var}, 3)};
613
614 ($averages, $width, $height) =
615 rrd_graph("${outdir}/${hostname}.${var}.year.png.work",
616 "-w", "$graphWidth", "-e", "00:00", "-s", "end-365d", @yearGraphDef);
617
618 if ($rrd_result) {
619 print "Error while graphing: " . $rrd_result . "\n";
620 } else {
621 my $newmtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9];
622 if ((!defined($mtime)) || ($newmtime != $mtime)) {
623 copy("${outdir}/${hostname}.${var}.year.png.work", "${outdir}/${hostname}.${var}.year.png.new");
624 rename("${outdir}/${hostname}.${var}.year.png.new", "${outdir}/${hostname}.${var}.year.png");
625 }
626 }
627
628 print HTML2 "<img src=\"${hostname}.${var}.year.png\" width=\"${width}\" height=\"${height}\"><br>\n";
629
630 print HTML2 "</body></html>\n";
631 close(HTML2);
632 rename("${outdir}/${hostname}.${var}.html.new", "${outdir}/${hostname}.${var}.html");
633 }
634 }
635
636 print HTML "</body></html>\n";
637 print HTML "<br>Generated on: " . localtime(time());
638 print HTML ' by <a href="http://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph">upsgraph</a>.';
639
640 close(HTML);
641
642 rename("${outdir}/index.html.new", "${outdir}/index.html");
643
644 sleep(${step}/2);
645 $first = 0;
646 }
Impressum, Datenschutz