]>
Commit | Line | Data |
---|---|---|
e18c93b3 MG |
1 | #!/usr/bin/perl -w |
2 | ||
f49c04f7 MG |
3 | #Due to memory leak in Debian squeeze (Bug #545519) |
4 | my $use_rrds = 0; | |
5 | my $rrd_result = 0; | |
6 | ||
1c9fb9df MG |
7 | if ((@ARGV != 1) && (@ARGV != 2)) { |
8 | print STDERR "Syntax: ${0} configfile [uid]\n"; | |
e18c93b3 MG |
9 | exit(1); |
10 | } | |
11 | ||
1c9fb9df | 12 | use Net::SNMP; |
0e572cdc | 13 | use IO::Socket::INET; |
3679b927 | 14 | use IO::Select; |
e5da3876 | 15 | use RRDs; |
e26b065f | 16 | use File::Copy; |
e5da3876 | 17 | use Data::Dumper; |
e18c93b3 | 18 | |
1c9fb9df | 19 | $UPSGRAPH::outdir = ""; |
3d7df03f | 20 | $UPSGRAPH::daysCovered = 370; |
1c9fb9df | 21 | $UPSGRAPH::step = 60; |
3d7df03f BO |
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; | |
6c1071ee | 25 | $UPSGRAPH::hosts = (); |
e18c93b3 | 26 | |
1c9fb9df | 27 | do $ARGV[0] or die "can't read config: $!"; |
e18c93b3 | 28 | |
1c9fb9df | 29 | my $outdir = $UPSGRAPH::outdir; |
1c9fb9df | 30 | my $step = $UPSGRAPH::step; |
3d7df03f | 31 | my $stepsPerHour = $UPSGRAPH::stepsPerHour; |
e5da3876 | 32 | my $keep = $UPSGRAPH::keep; |
3d7df03f | 33 | my $keepHours = $UPSGRAPH::keepHours; |
6c1071ee | 34 | my $hosts = $UPSGRAPH::hosts; |
e18c93b3 | 35 | |
f49c04f7 MG |
36 | sub rrd_update(@) { |
37 | my @args = @_; | |
38 | ||
39 | if ($use_rrds == 1) { | |
40 | RRDs::update(@args); | |
41 | $rrd_result = RRDs::error; | |
42 | } else { | |
43 | $rrd_result = system("rrdtool", "update", @args); | |
44 | } | |
45 | } | |
46 | ||
47 | sub rrd_graph(@) { | |
48 | my @args = @_; | |
49 | my @rrd_out = (); | |
50 | ||
51 | if ($use_rrds == 1) { | |
52 | @rrd_out = RRDs::graph(@args); | |
53 | $rrd_result = RRDs::error; | |
54 | } else { | |
55 | my $rrd_stdout; | |
56 | ||
57 | open(RRDFD, '-|', 'rrdtool', 'graph', @args); | |
58 | while(<RRDFD>) { | |
59 | chomp; | |
60 | $rrd_stdout = $_; | |
61 | } | |
62 | close(RRDFD); | |
63 | $rrd_result = $?; | |
64 | if ($rrd_result == 0) { | |
65 | push @rrd_out, 0; | |
66 | push @rrd_out, split(/x/, $rrd_stdout); | |
67 | } | |
68 | } | |
69 | ||
70 | return @rrd_out; | |
71 | } | |
72 | ||
e5da3876 | 73 | sub rrdcreate(@) { |
21377f43 MG |
74 | my $newrrd = shift; |
75 | my $field = shift; | |
6c1071ee | 76 | my $vars = shift; |
e5da3876 MG |
77 | my $start = shift; |
78 | ||
21377f43 | 79 | my @cmd = ("${newrrd}", "--step=${step}"); |
e5da3876 MG |
80 | |
81 | if (defined($start)) { | |
82 | push @cmd, "--start=${start}"; | |
83 | } | |
84 | ||
21377f43 MG |
85 | push @cmd, "DS:${field}:GAUGE:600:" . |
86 | $vars->{$field}->{'min'} . ":" . | |
f447c2a1 | 87 | $vars->{$field}->{'max'}; |
21377f43 | 88 | |
e5da3876 | 89 | push @cmd, "RRA:AVERAGE:0.5:1:${keep}"; |
3d7df03f BO |
90 | push @cmd, "RRA:MIN:0.4:${stepsPerHour}:${keepHours}"; |
91 | push @cmd, "RRA:MAX:0.4:${stepsPerHour}:${keepHours}"; | |
e5da3876 MG |
92 | |
93 | RRDs::create(@cmd); | |
94 | if (RRDs::error) { | |
95 | print "Error while creating: " . RRDs::error . "\n"; | |
96 | exit 1; | |
97 | } | |
98 | } | |
99 | ||
6c1071ee MG |
100 | sub fetch_snmp(@) { |
101 | my $address = shift; | |
102 | my $community = shift; | |
103 | my $oid = shift; | |
e5da3876 | 104 | |
6c1071ee MG |
105 | (my $session, my $error) = Net::SNMP->session(Hostname => $address, |
106 | Community => $community); | |
e18c93b3 | 107 | |
0e572cdc MG |
108 | if (!$session) { |
109 | print STDERR "session error: $error"; | |
e0acc35a | 110 | return undef; |
0e572cdc | 111 | } |
e5da3876 | 112 | |
6c1071ee | 113 | $session->translate(0); |
e5da3876 | 114 | |
0e572cdc | 115 | my $result = $session->get_request($oid); |
e5da3876 | 116 | |
6c1071ee | 117 | $session->close; |
21377f43 | 118 | |
0e572cdc MG |
119 | return undef if (!defined($result)); |
120 | ||
121 | $result->{$oid}; | |
122 | } | |
123 | ||
124 | sub fetch_tcp(@) { | |
125 | my $address = shift; | |
126 | my $port = shift; | |
127 | ||
128 | my $sock = IO::Socket::INET->new(PeerAddr => $address, | |
129 | PeerPort => $port, | |
130 | Proto => 'tcp', | |
131 | Timeout => 1); | |
132 | ||
133 | return undef if (!$sock); | |
134 | ||
3679b927 MG |
135 | my $select = IO::Select->new($sock); |
136 | ||
137 | my $value = undef; | |
138 | ||
139 | if ($select->can_read(1)) { | |
140 | chomp($value) if (sysread($sock, $value, 4096) > 0); | |
141 | } | |
0e572cdc MG |
142 | |
143 | close($sock); | |
144 | ||
145 | if (!$value) { | |
146 | return undef; | |
147 | } | |
148 | ||
149 | $value=~ s/\s//g; | |
150 | ||
151 | $value; | |
6c1071ee | 152 | } |
e5da3876 | 153 | |
b57167a1 MG |
154 | sub fetch_tcp_multi(@) { |
155 | my $address = shift; | |
156 | my $port = shift; | |
157 | my $delimiter = shift; | |
158 | my %values; | |
159 | ||
160 | my $sock = IO::Socket::INET->new(PeerAddr => $address, | |
161 | PeerPort => $port, | |
162 | Proto => 'tcp', | |
163 | Timeout => 1); | |
164 | ||
165 | return undef if (!$sock); | |
166 | ||
3679b927 MG |
167 | my $select = IO::Select->new($sock); |
168 | ||
169 | while($select->can_read(1)) { | |
170 | if (sysread($sock, my $buf, 16384) > 0) { | |
171 | $buf=~s/\r//g; | |
172 | foreach my $line (split(/\n/, $buf)) { | |
173 | (my $key, my $value) = split(/${delimiter}/, $line); | |
174 | $value=~ s/\s//g; | |
175 | $values{$key} = $value; | |
176 | } | |
177 | } else { | |
178 | last; | |
179 | } | |
b57167a1 MG |
180 | } |
181 | ||
182 | close($sock); | |
183 | ||
184 | %values; | |
185 | } | |
186 | ||
6c1071ee MG |
187 | if ($> == 0) { |
188 | if (@ARGV != 2) { | |
189 | print STDERR "Running as root, please provide UID as 2th argument!\n"; | |
190 | exit(1); | |
e5da3876 MG |
191 | } |
192 | ||
6c1071ee MG |
193 | print "Running as root, switching to ".$ARGV[1]."\n"; |
194 | $< = $> = $ARGV[1]; | |
21377f43 | 195 | } |
e5da3876 | 196 | |
6c1071ee MG |
197 | foreach my $host (@$hosts) { |
198 | my $rrdfile = $host->{'rrdfile'}; | |
21377f43 | 199 | |
46ead44b MG |
200 | foreach my $var (keys(%{$host->{'vars'}})) { |
201 | $host->{'vars'}->{$var}->{'min'} = 'U' if (!defined($host->{'vars'}->{$var}->{'min'})); | |
202 | $host->{'vars'}->{$var}->{'max'} = 'U' if (!defined($host->{'vars'}->{$var}->{'max'})); | |
203 | } | |
204 | ||
6c1071ee MG |
205 | if (-e "${rrdfile}") { |
206 | print "Reading old ${rrdfile} to preserve data...\n"; | |
e5da3876 | 207 | |
6c1071ee MG |
208 | my $rrdinfo = RRDs::info("${rrdfile}"); |
209 | if (RRDs::error) { | |
210 | print "Error while getting info: " . RRDs::error . "\n"; | |
211 | exit 1; | |
212 | } | |
21377f43 MG |
213 | |
214 | (my $start, my $ostep, my $names, my $data) = | |
6c1071ee | 215 | RRDs::fetch("${rrdfile}", |
21377f43 MG |
216 | "-s " . (time() - ($rrdinfo->{'rra[0].rows'} * $rrdinfo->{'step'})), |
217 | "AVERAGE"); | |
218 | ||
219 | if (RRDs::error) { | |
220 | print "Error while fetching data: " . RRDs::error . "\n"; | |
221 | exit 1; | |
222 | } | |
223 | ||
6c1071ee MG |
224 | foreach my $field (@$names) { |
225 | if (! -e "${rrdfile}.${field}") { | |
226 | rrdcreate("${rrdfile}.${field}", | |
227 | "${field}", | |
228 | $host->{'vars'}, | |
229 | (${start}-${ostep})); | |
230 | } | |
231 | } | |
21377f43 MG |
232 | |
233 | my $pos = $start; | |
234 | foreach my $line (@$data) { | |
6c1071ee MG |
235 | foreach my $field (@$names) { |
236 | my $val = shift (@$line); | |
21377f43 | 237 | $val = 'U' if (!defined($val)); |
21377f43 | 238 | |
6c1071ee MG |
239 | RRDs::update("${rrdfile}.${field}", "${pos}:${val}"); |
240 | if (RRDs::error) { | |
241 | print "Can't insert data: " . RRDs::error . "\n"; | |
242 | exit 1; | |
243 | } | |
244 | ||
21377f43 | 245 | } |
6c1071ee | 246 | |
21377f43 MG |
247 | $pos += $ostep; |
248 | ||
249 | if ((($pos-$start)/$ostep) == $#$data) { | |
250 | last; | |
251 | } | |
252 | } | |
253 | ||
6c1071ee MG |
254 | rename("${rrdfile}", "${rrdfile}.old") or die "Can't rename old file: $!\n"; |
255 | } | |
21377f43 | 256 | |
6c1071ee MG |
257 | foreach my $field (@{$host->{'fields'}}) { |
258 | if (! -e "${rrdfile}.${field}") { | |
259 | print "Creating ${rrdfile}.${field}...\n"; | |
260 | rrdcreate("${rrdfile}.${field}", | |
261 | "${field}", | |
262 | $host->{'vars'}); | |
263 | } | |
264 | ||
265 | my $rrdinfo = RRDs::info("${rrdfile}.${field}"); | |
21377f43 MG |
266 | if (RRDs::error) { |
267 | print "Error while getting info: " . RRDs::error . "\n"; | |
268 | exit 1; | |
269 | } | |
270 | ||
178e4778 MG |
271 | if (defined($rrdinfo->{"ds[${field}].min"})) { |
272 | if ($rrdinfo->{"ds[${field}].min"} ne $host->{'vars'}->{$field}->{'min'}) { | |
273 | RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'}); | |
274 | } | |
275 | } else { | |
276 | if ($host->{'vars'}->{$field}->{'min'} ne 'U') { | |
277 | RRDs::tune("${rrdfile}.${field}","-i",$field.":".$host->{'vars'}->{$field}->{'min'}); | |
278 | } | |
279 | } | |
280 | ||
281 | if (RRDs::error) { | |
282 | print "Error while setting min: " . RRDs::error . "\n"; | |
283 | exit 1; | |
284 | } | |
285 | ||
286 | if (defined($rrdinfo->{"ds[${field}].max"})) { | |
287 | if ($rrdinfo->{"ds[${field}].max"} ne $host->{'vars'}->{$field}->{'max'}) { | |
178e4778 MG |
288 | RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'}); |
289 | } | |
290 | } else { | |
291 | if ($host->{'vars'}->{$field}->{'max'} ne 'U') { | |
292 | RRDs::tune("${rrdfile}.${field}","-a",$field.":".$host->{'vars'}->{$field}->{'max'}); | |
293 | } | |
294 | } | |
295 | ||
296 | if (RRDs::error) { | |
297 | print "Error while setting max: " . RRDs::error . "\n"; | |
298 | exit 1; | |
299 | } | |
300 | ||
3d7df03f BO |
301 | if ($rrdinfo->{'rra[0].rows'} != $keep || |
302 | !defined($rrdinfo->{'rra[1].rows'}) || $rrdinfo->{'rra[1].rows'} != $keepHours) { | |
303 | ||
6c1071ee MG |
304 | print "Resizing ${rrdfile}.${field} from " . $rrdinfo->{'rra[0].rows'} . |
305 | " to ${keep} samples.\n"; | |
e18c93b3 | 306 | |
6c1071ee MG |
307 | (my $start, my $ostep, my $names, my $data) = |
308 | RRDs::fetch("${rrdfile}.${field}", | |
309 | "-s " . (time() - ($rrdinfo->{'rra[0].rows'} * $rrdinfo->{'step'})), | |
310 | "AVERAGE"); | |
6aa53fc5 | 311 | |
6c1071ee MG |
312 | if (RRDs::error) { |
313 | print "Error while fetching data: " . RRDs::error . "\n"; | |
314 | exit 1; | |
315 | } | |
6aa53fc5 | 316 | |
6c1071ee MG |
317 | rrdcreate("${rrdfile}.${field}.new", |
318 | "${field}", | |
319 | $host->{'vars'}, | |
320 | (${start}-${ostep})); | |
6aa53fc5 | 321 | |
3d7df03f | 322 | print "Preserving data in file ${rrdfile}.${field} since " . localtime($start) . "\n"; |
e18c93b3 | 323 | |
6c1071ee MG |
324 | my $pos = $start; |
325 | foreach my $line (@$data) { | |
326 | my $vline = "${pos}"; | |
e18c93b3 | 327 | |
6c1071ee MG |
328 | foreach my $val (@$line) { |
329 | $val = 'U' if (!defined($val)); | |
330 | $vline .= ":${val}"; | |
331 | } | |
332 | RRDs::update("${rrdfile}.${field}.new", $vline) or die "Can't insert data\n"; | |
e18c93b3 | 333 | |
6c1071ee MG |
334 | if (RRDs::error) { |
335 | print "Error while updating: " . RRDs::error . "\n"; | |
336 | exit 1; | |
337 | } | |
338 | $pos += $ostep; | |
e18c93b3 | 339 | |
6c1071ee MG |
340 | if ((($pos-$start)/$ostep) == $#$data) { |
341 | last; | |
342 | } | |
343 | } | |
e18c93b3 | 344 | |
6c1071ee MG |
345 | rename("${rrdfile}.${field}", "${rrdfile}.${field}.old") or die "Can't rename old file: $!\n"; |
346 | rename("${rrdfile}.${field}.new", "${rrdfile}.${field}") or die "Can't rename new file: $!\n"; | |
e18c93b3 | 347 | |
6c1071ee MG |
348 | $rrdinfo = RRDs::info("${rrdfile}.${field}"); |
349 | if (RRDs::error) { | |
350 | print "Error while getting info: " . RRDs::error . "\n"; | |
351 | exit 1; | |
352 | } | |
e18c93b3 | 353 | |
6c1071ee MG |
354 | if ($rrdinfo->{'rra[0].rows'} != $keep) { |
355 | print "Failed!\n"; | |
356 | exit 1; | |
357 | } | |
e18c93b3 | 358 | } |
e18c93b3 | 359 | } |
6c1071ee MG |
360 | } |
361 | ||
362 | my $child = fork(); | |
e18c93b3 | 363 | |
6c1071ee MG |
364 | die "fork failed!" if (!defined($child)); |
365 | ||
366 | exit 0 if ($child != 0); | |
367 | ||
368 | while(1) { | |
e18c93b3 MG |
369 | open(HTML, ">${outdir}/index.html.new"); |
370 | ||
2c148a8e | 371 | 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>'; |
e18c93b3 MG |
372 | print HTML '<body bgcolor="#ffffff">'; |
373 | ||
6c1071ee | 374 | foreach my $host (@$hosts) { |
2c148a8e MG |
375 | print HTML "[<a href=\"#".${host}->{'name'}."\">".${host}->{'name'}."</a>] "; |
376 | } | |
377 | print HTML "<br>\n"; | |
378 | ||
379 | foreach my $host (@$hosts) { | |
380 | print HTML "<br>\n"; | |
381 | print HTML "<a name=\"".${host}->{'name'}."\"></a>\n"; | |
6c1071ee MG |
382 | my $vars = $host->{'vars'}; |
383 | my $rrdfile = $host->{'rrdfile'}; | |
384 | my $hostname = $host->{'name'}; | |
b57167a1 | 385 | my %multi_values = (); |
6c1071ee MG |
386 | |
387 | foreach my $var (@{$host->{'fields'}}) { | |
388 | delete $vars->{$var}->{'value'}; | |
e5da3876 | 389 | |
0e572cdc MG |
390 | my $result; |
391 | ||
392 | if ((!defined($vars->{$var}->{'proto'})) || | |
393 | ($vars->{$var}->{'proto'} eq '') || | |
394 | ($vars->{$var}->{'proto'} eq 'snmp')) { | |
395 | $result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'}); | |
396 | } elsif ($vars->{$var}->{'proto'} eq 'tcp') { | |
397 | $result = fetch_tcp($host->{'address'}, $vars->{$var}->{'port'}); | |
b57167a1 MG |
398 | } elsif ($vars->{$var}->{'proto'} eq 'tcp_multi') { |
399 | if (defined($multi_values{$vars->{$var}->{'multi_id'}})) { | |
400 | $result = $multi_values{$vars->{$var}->{'multi_id'}} | |
401 | } else { | |
402 | my %values = fetch_tcp_multi($host->{'address'}, $vars->{$var}->{'port'}, $vars->{$var}->{'multi_delimiter'}); | |
403 | @multi_values{keys %values} = values %values; | |
404 | $result = $multi_values{$vars->{$var}->{'multi_id'}}; | |
405 | } | |
0e572cdc MG |
406 | } |
407 | ||
6c1071ee MG |
408 | next unless (defined $result); |
409 | ||
0e572cdc | 410 | $vars->{$var}->{'value'} = $result; |
6c1071ee MG |
411 | if (defined($vars->{$var}->{'factor'})) { |
412 | $vars->{$var}->{'value'} *= $vars->{$var}->{'factor'}; | |
413 | } | |
414 | } | |
415 | ||
416 | foreach my $var (@{$host->{'fields'}}) { | |
417 | if (!(defined($vars->{$var}->{'value'}))) { | |
418 | $vars->{$var}->{'value'} = 'U'; | |
419 | } | |
f49c04f7 | 420 | rrd_update("${rrdfile}.${var}", "N:" . $vars->{$var}->{'value'}); |
6c1071ee | 421 | } |
f49c04f7 MG |
422 | if ($rrd_result) { |
423 | print "Error while updating: " . $rrd_result . "\n"; | |
e5da3876 MG |
424 | } |
425 | ||
6c1071ee | 426 | foreach my $var (@{$host->{'fields'}}) { |
de10ff59 | 427 | my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}, "DEF:${var}=${rrdfile}.${var}:${var}:AVERAGE", "LINE1:${var}#FF0000"); |
3d7df03f BO |
428 | |
429 | push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN", "LINE1:${var}-min#0000FF"; | |
430 | push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX", "LINE1:${var}-max#00FF00"; | |
0e74e3d8 | 431 | push @graphdef, "VDEF:cur=${var},LAST"; |
de10ff59 | 432 | push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r'; |
52259377 MG |
433 | |
434 | my $mtime; | |
435 | $mtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9]; | |
436 | ||
6c1071ee | 437 | (my $averages, my $width, my $height) = |
f49c04f7 | 438 | rrd_graph("${outdir}/${hostname}.${var}.png.work", |
6c1071ee | 439 | "-w", "720", @graphdef); |
e5da3876 | 440 | |
0e74e3d8 MG |
441 | pop @graphdef; |
442 | pop @graphdef; | |
443 | ||
f49c04f7 MG |
444 | if ($rrd_result) { |
445 | print "Error while graphing: " . $rrd_result . "\n"; | |
6c1071ee | 446 | } else { |
52259377 | 447 | my $newmtime=(stat("${outdir}/${hostname}.${var}.png.work"))[9]; |
f004592a | 448 | if ((!defined($mtime)) || ($newmtime != $mtime)) { |
52259377 MG |
449 | copy("${outdir}/${hostname}.${var}.png.work", "${outdir}/${hostname}.${var}.png.new"); |
450 | rename("${outdir}/${hostname}.${var}.png.new", "${outdir}/${hostname}.${var}.png"); | |
451 | } | |
6c1071ee | 452 | } |
e5da3876 | 453 | |
2c148a8e | 454 | print HTML "<a href=\"${hostname}.${var}.html\"><img src=\"${hostname}.${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a><br>\n"; |
58c56c83 | 455 | |
6c1071ee | 456 | open (HTML2, ">${outdir}/${hostname}.${var}.html.new"); |
41cfd723 | 457 | 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>'; |
6c1071ee | 458 | print HTML2 '<body bgcolor="#ffffff">'; |
58c56c83 | 459 | |
3d7df03f | 460 | push @graphdef, "VDEF:min=${var}-min,MINIMUM"; |
6c1071ee | 461 | push @graphdef, "GPRINT:min:Minimum\\: %.2lf"; |
58c56c83 | 462 | |
6c1071ee MG |
463 | push @graphdef, "VDEF:avg=${var},AVERAGE"; |
464 | push @graphdef, "GPRINT:avg:Average\\: %.2lf"; | |
58c56c83 | 465 | |
3d7df03f | 466 | push @graphdef, "VDEF:max=${var}-max,MAXIMUM"; |
6c1071ee | 467 | push @graphdef, "GPRINT:max:Maximum\\: %.2lf"; |
e5da3876 | 468 | |
6c1071ee MG |
469 | push @graphdef, "VDEF:cur=${var},LAST"; |
470 | push @graphdef, "GPRINT:cur:Current\\: %.2lf"; | |
e5da3876 | 471 | |
52259377 | 472 | $mtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9]; |
6c1071ee | 473 | ($averages, $width, $height) = |
f49c04f7 | 474 | rrd_graph("${outdir}/${hostname}.${var}.long.png.work", |
6c1071ee | 475 | "-w", "1008", @graphdef); |
e5da3876 | 476 | |
f49c04f7 MG |
477 | if ($rrd_result) { |
478 | print "Error while graphing: " . $rrd_result . "\n"; | |
6c1071ee | 479 | } else { |
52259377 | 480 | my $newmtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9]; |
f004592a | 481 | if ((!defined($mtime)) || ($newmtime != $mtime)) { |
52259377 MG |
482 | copy("${outdir}/${hostname}.${var}.long.png.work", "${outdir}/${hostname}.${var}.long.png.new"); |
483 | rename("${outdir}/${hostname}.${var}.long.png.new", "${outdir}/${hostname}.${var}.long.png"); | |
484 | } | |
6c1071ee | 485 | } |
e5da3876 | 486 | |
1c46ea61 | 487 | print HTML2 "<img src=\"${hostname}.${var}.long.png\" width=\"${width}\" height=\"${height}\"><br>\n"; |
6c1071ee | 488 | |
52259377 | 489 | $mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; |
6c1071ee | 490 | ($averages, $width, $height) = |
f49c04f7 | 491 | rrd_graph("${outdir}/${hostname}.${var}.week.png.work", |
6c1071ee MG |
492 | "-w", "1008", "-e", "now", "-s", "end-1w", @graphdef); |
493 | ||
f49c04f7 MG |
494 | if ($rrd_result) { |
495 | print "Error while graphing: " . $rrd_result . "\n"; | |
6c1071ee | 496 | } else { |
52259377 | 497 | my $newmtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9]; |
f004592a | 498 | if ((!defined($mtime)) || ($newmtime != $mtime)) { |
52259377 MG |
499 | copy("${outdir}/${hostname}.${var}.week.png.work", "${outdir}/${hostname}.${var}.week.png.new"); |
500 | rename("${outdir}/${hostname}.${var}.week.png.new", "${outdir}/${hostname}.${var}.week.png"); | |
501 | } | |
6c1071ee | 502 | } |
e5da3876 | 503 | |
1c46ea61 | 504 | print HTML2 "<img src=\"${hostname}.${var}.week.png\" width=\"${width}\" height=\"${height}\"><br>\n"; |
e5da3876 | 505 | |
52259377 | 506 | $mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; |
6c1071ee | 507 | ($averages, $width, $height) = |
f49c04f7 | 508 | rrd_graph("${outdir}/${hostname}.${var}.year.png.work", |
6c1071ee | 509 | "-w", "1008", "-e", "now", "-s", "end-1y", @graphdef); |
e5da3876 | 510 | |
f49c04f7 MG |
511 | if ($rrd_result) { |
512 | print "Error while graphing: " . $rrd_result . "\n"; | |
6c1071ee | 513 | } else { |
52259377 | 514 | my $newmtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9]; |
f004592a | 515 | if ((!defined($mtime)) || ($newmtime != $mtime)) { |
52259377 MG |
516 | copy("${outdir}/${hostname}.${var}.year.png.work", "${outdir}/${hostname}.${var}.year.png.new"); |
517 | rename("${outdir}/${hostname}.${var}.year.png.new", "${outdir}/${hostname}.${var}.year.png"); | |
518 | } | |
6c1071ee | 519 | } |
e18c93b3 | 520 | |
1c46ea61 | 521 | print HTML2 "<img src=\"${hostname}.${var}.year.png\" width=\"${width}\" height=\"${height}\"><br>\n"; |
e18c93b3 | 522 | |
6c1071ee MG |
523 | print HTML2 "</body></html>\n"; |
524 | close(HTML2); | |
525 | rename("${outdir}/${hostname}.${var}.html.new", "${outdir}/${hostname}.${var}.html"); | |
526 | } | |
e18c93b3 MG |
527 | } |
528 | ||
529 | print HTML "</body></html>\n"; | |
530 | print HTML "<br>Generated on: " . localtime(time()); | |
863e62dc | 531 | print HTML ' by <a href="http://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph">upsgraph</a>.'; |
e18c93b3 MG |
532 | |
533 | close(HTML); | |
534 | ||
535 | rename("${outdir}/index.html.new", "${outdir}/index.html"); | |
536 | ||
537 | sleep(${step}/2); | |
538 | } |