]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/makegraphs
HDDTemp nun fuer jede Platte und nicht nur die erste :D
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
1 #!/usr/bin/perl
2
3 ############################################################################
4 # #
5 # This file is part of the IPCop Firewall. #
6 # #
7 # IPCop is free software; you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation; either version 2 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # IPCop is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with IPCop; if not, write to the Free Software #
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
20 # #
21 # Copyright (C) 2004-01-19 Mark Wormgoor <mark@wormgoor.com>. #
22 # #
23 ############################################################################
24
25 use strict;
26 #use warnings;
27
28 use RRDs;
29 require "/var/ipfire/general-functions.pl";
30 require "${General::swroot}/lang.pl";
31
32 my (%settings, @ipacsum, $iface, $ERROR);
33 &General::readhash("${General::swroot}/ethernet/settings", \%settings);
34 my %mbmon_settings = ();
35 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
36
37 # Added for conversion of utf-8 characters
38 use Encode 'from_to';
39 my %tr=();
40
41 # Force language back to English (ugly hack!)
42 # Modified to only force if we are unable to convert charset
43 # from utf-8
44 if ((${Lang::language} eq 'el') ||
45 (${Lang::language} eq 'fa') ||
46 (${Lang::language} eq 'ru') ||
47 (${Lang::language} eq 'th') ||
48 (${Lang::language} eq 'vi') ||
49 (${Lang::language} eq 'zh') ||
50 (${Lang::language} eq 'zt')) {
51 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
52 } else {
53 %tr=%Lang::tr; # use translated version for other languages
54 }
55
56 # Settings
57 my $rrdlog = "/var/log/rrd";
58 my $graphs = "/srv/web/ipfire/html/graphs";
59 $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
60 my $hdd_device = "/dev/harddisk";
61 my $temp = '';
62 my %mbmon_values = ();
63 my $key;
64 my $value;
65 my @args = ();
66 my $count = 0;
67 my $ERROR;
68 my $dbg = 0;
69 my $path_smartctl = "/usr/sbin/smartctl";
70 my $path_hddtemp = "/usr/sbin/hddtemp";
71
72 my %colors = ();
73 $colors{"1"} = "#0000FF";
74 $colors{"2"} = "#00FF00";
75 $colors{"3"} = "#FF0000";
76 $colors{"4"} = "#FFD700";
77 $colors{"5"} = "#CCCCCC";
78 $colors{"6"} = "#40E0D0";
79 $colors{"7"} = "#90EE90";
80 $colors{"8"} = "#F4A460";
81
82 open(MBMON_OUT, ">/var/log/mbmon-values");
83 open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
84
85 while( $_ = <FD> )
86 {
87 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
88 $key = $1 ;
89 $value = $2 ;
90 $key =~ y/A-Z/a-z/ ;
91 $mbmon_values{$key} = $value;
92 print(MBMON_OUT "$key=$value\n");
93 }
94 close(FD);
95 close(MBMON_OUT);
96
97 sub gettraffic {
98 my $interface = $_[0];
99
100 my $bytesin=0;
101 my $bytesout=0;
102
103 foreach (@ipacsum)
104 {
105 # Incoming...
106 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
107
108 # Forwarded Incoming...
109 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
110
111 # Outgoing...
112 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
113
114 # Forwarded Outgoing...
115 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
116 }
117 return "$bytesin:$bytesout";
118 }
119
120 sub updatecpugraph {
121 my $period = $_[0];
122
123 RRDs::graph ("$graphs/cpu-$period.png",
124 "--start", "-1$period", "-aPNG", "-i", "-z",
125 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
126 "--color", "SHADEA#EAE9EE",
127 "--color", "SHADEB#EAE9EE",
128 "--color", "BACK#FFFFFF",
129 "-t $tr{'cpu usage per'} $tr{$period}",
130 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
131 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
132 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
133 "CDEF:total=user,system,idle,+,+",
134 "CDEF:userpct=100,user,total,/,*",
135 "CDEF:systempct=100,system,total,/,*",
136 "CDEF:idlepct=100,idle,total,/,*",
137 "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j",
138 "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j",
139 "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j",
140 "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%",
141 "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%",
142 "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j",
143 "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%",
144 "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%",
145 "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j",
146 "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%",
147 "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%",
148 "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j");
149 $ERROR = RRDs::error;
150 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
151 }
152
153 sub updatecpudata {
154 if ( ! -e "$rrdlog/cpu.rrd") {
155 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
156 "DS:user:COUNTER:600:0:500000000",
157 "DS:system:COUNTER:600:0:500000000",
158 "DS:idle:COUNTER:600:0:500000000",
159 "RRA:AVERAGE:0.5:1:576",
160 "RRA:AVERAGE:0.5:6:672",
161 "RRA:AVERAGE:0.5:24:732",
162 "RRA:AVERAGE:0.5:144:1460");
163 $ERROR = RRDs::error;
164 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
165 }
166
167 my ($cpu, $user, $nice, $system, $idle);
168
169 open STAT, "/proc/stat";
170 while(<STAT>) {
171 chomp;
172 /^cpu\s/ or next;
173 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
174 last;
175 }
176 close STAT;
177 $user += $nice;
178
179 RRDs::update ("$rrdlog/cpu.rrd",
180 "-t", "user:system:idle",
181 "N:$user:$system:$idle");
182 $ERROR = RRDs::error;
183 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
184
185 }
186
187 sub updateloadgraph {
188 my $period = $_[0];
189
190 RRDs::graph ("$graphs/load-$period.png",
191 "--start", "-1$period", "-aPNG",
192 "-w 600", "-h 100", "-i", "-z", "-l 0", "-r", "--alt-y-grid",
193 "-t Load Average",
194 "--color", "SHADEA#EAE9EE",
195 "--color", "SHADEB#EAE9EE",
196 "--color", "BACK#FFFFFF",
197 "DEF:load1=$rrdlog/load.rrd:load1:AVERAGE",
198 "DEF:load5=$rrdlog/load.rrd:load5:AVERAGE",
199 "DEF:load15=$rrdlog/load.rrd:load15:AVERAGE",
200 "AREA:load1#ff0000:1 Minute, letzter\:",
201 "GPRINT:load1:LAST:%5.2lf\n",
202 "AREA:load5#ff9900:5 Minuten, letzter\:",
203 "GPRINT:load5:LAST:%5.2lf\n",
204 "AREA:load15#ffff00:15 Minuten, letzter\:",
205 "GPRINT:load15:LAST:%5.2lf",
206 "LINE1:load5#ff9900:",
207 "LINE1:load1#ff0000:");
208 $ERROR = RRDs::error;
209 print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
210 }
211
212 sub updateloaddata {
213 if ( ! -e "$rrdlog/load.rrd") {
214 RRDs::create ("$rrdlog/load.rrd", "--step=60",
215 "DS:load1:GAUGE:120:0:U",
216 "DS:load5:GAUGE:120:0:U",
217 "DS:load15:GAUGE:120:0:U",
218 "RRA:AVERAGE:0.5:1:2160",
219 "RRA:AVERAGE:0.5:5:2016",
220 "RRA:AVERAGE:0.5:15:2880",
221 "RRA:AVERAGE:0.5:60:8760");
222
223 $ERROR = RRDs::error;
224 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
225 }
226 }
227
228 sub updatememgraph {
229 my $period = $_[0];
230
231 RRDs::graph ("$graphs/memory-$period.png",
232 "--start", "-1$period", "-aPNG", "-i", "-z",
233 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
234 "--color", "SHADEA#EAE9EE",
235 "--color", "SHADEB#EAE9EE",
236 "--color", "BACK#FFFFFF",
237 "-t $tr{'memory usage per'} $tr{$period}",
238 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
239 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
240 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
241 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
242 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
243 "CDEF:total=used,free,+",
244 "CDEF:used2=used,buffer,cache,shared,+,+,-",
245 "CDEF:usedpct=100,used2,total,/,*",
246 "CDEF:sharedpct=100,shared,total,/,*",
247 "CDEF:bufferpct=100,buffer,total,/,*",
248 "CDEF:cachepct=100,cache,total,/,*",
249 "CDEF:freepct=100,free,total,/,*",
250 "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
251 "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
252 "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
253 "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
254 "STACK:freepct#00FF00:$tr{'free memory'}\\j",
255 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
256 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
257 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
258 "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
259 "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
260 "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
261 "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
262 "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
263 "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
264 "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
265 "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
266 "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
267 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
268 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
269 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
270 $ERROR = RRDs::error;
271 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
272
273 RRDs::graph ("$graphs/swap-$period.png",
274 "--start", "-1$period", "-aPNG", "-i", "-z",
275 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
276 "--color", "SHADEA#EAE9EE",
277 "--color", "SHADEB#EAE9EE",
278 "--color", "BACK#FFFFFF",
279 "-t $tr{'swap usage per'} $tr{$period}",
280 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
281 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
282 "CDEF:total=used,free,+",
283 "CDEF:usedpct=100,used,total,/,*",
284 "CDEF:freepct=100,free,total,/,*",
285 "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
286 "STACK:freepct#00FF00:$tr{'free swap'}\\j",
287 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
288 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
289 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
290 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
291 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
292 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
293 $ERROR = RRDs::error;
294 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
295 }
296
297 sub updatememdata {
298 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
299 if ( ! -e "$rrdlog/mem.rrd") {
300 RRDs::create ("$rrdlog/mem.rrd", "--step=300",
301 "DS:memused:ABSOLUTE:600:0:5000000000",
302 "DS:memfree:ABSOLUTE:600:0:5000000000",
303 "DS:memshared:ABSOLUTE:600:0:5000000000",
304 "DS:membuffers:ABSOLUTE:600:0:5000000000",
305 "DS:memcache:ABSOLUTE:600:0:5000000000",
306 "DS:swapused:ABSOLUTE:600:0:5000000000",
307 "DS:swapfree:ABSOLUTE:600:0:5000000000",
308 "RRA:AVERAGE:0.5:1:576",
309 "RRA:AVERAGE:0.5:6:672",
310 "RRA:AVERAGE:0.5:24:732",
311 "RRA:AVERAGE:0.5:144:1460");
312 $ERROR = RRDs::error;
313 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
314 }
315
316 open MEM, "/proc/meminfo";
317 while(<MEM>) {
318 chomp;
319 if ($_ =~ /^Mem:/) {
320 my @temp = split (/\s+/, $_);
321 $memused = $temp[2];
322 $memfree = $temp[3];
323 $memshared = $temp[4];
324 $membuffers = $temp[5];
325 $memcache = $temp[6];
326 } elsif ($_ =~ /^Swap:/) {
327 my @temp = split (/\s+/, $_);
328 $swapused = $temp[2];
329 $swapfree = $temp[3];
330 }
331 }
332 close MEM;
333
334 RRDs::update ("$rrdlog/mem.rrd",
335 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
336 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
337 $ERROR = RRDs::error;
338 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
339 }
340
341 sub updatediskgraph {
342 my $period = $_[0];
343
344 RRDs::graph ("$graphs/disk-$period.png",
345 "--start", "-1$period", "-aPNG", "-i", "-z",
346 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
347 "--color", "SHADEA#EAE9EE",
348 "--color", "SHADEB#EAE9EE",
349 "--color", "BACK#FFFFFF",
350 "-t $tr{'disk access per'} $tr{$period}",
351 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
352 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
353 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
354 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
355 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
356 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
357 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
358 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
359 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
360 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
361 $ERROR = RRDs::error;
362 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
363 }
364
365 sub updatediskdata {
366 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
367 if ( ! -e "$rrdlog/disk.rrd") {
368 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
369 "DS:readsect:COUNTER:600:0:5000000000",
370 "DS:writesect:COUNTER:600:0:5000000000",
371 "RRA:AVERAGE:0.5:1:576",
372 "RRA:AVERAGE:0.5:6:672",
373 "RRA:AVERAGE:0.5:24:732",
374 "RRA:AVERAGE:0.5:144:1460");
375 $ERROR = RRDs::error;
376 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
377 }
378
379 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
380 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
381
382 my $major = $rdev >> 8;
383 my $minor = $rdev & 0xFF;
384
385 open STAT, "/proc/stat";
386 my @diskstat = <STAT>;
387 close (STAT);
388 foreach my $line (@diskstat)
389 {
390 chomp ($line);
391 my @temp = split(/\:\ /,$line);
392 if ($temp[1]) {
393 my @devicestat = split(/\ /,$temp[1]);
394 foreach my $stats (@devicestat)
395 {
396 chomp ($stats);
397 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
398 if ($major eq $fields[1] and $minor eq $fields[2])
399 {
400 $readwritereq = $fields[3];
401 $readreq = $fields[4];
402 $readsect = $fields[5];
403 $writereq = $fields[6];
404 $writesect = $fields[7];
405 }
406 }
407 }
408 }
409
410 if ($readsect && $writesect) {
411 RRDs::update ("$rrdlog/disk.rrd",
412 "-t", "readsect:writesect",
413 "N:$readsect:$writesect");
414 $ERROR = RRDs::error;
415 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
416 } else {
417 print "Error in RRD::update for disk: no data available\n";
418 }
419 }
420
421 sub updatediskgraphnew {
422 my $disk = $_[0];
423 my $period = $_[1];
424
425 RRDs::graph ("$graphs/disk-$disk-$period.png",
426 "--start", "-1$period", "-aPNG", "-i", "-z",
427 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
428 "--color", "SHADEA#EAE9EE",
429 "--color", "SHADEB#EAE9EE",
430 "--color", "BACK#FFFFFF",
431 "-t $tr{'disk access per'} $tr{$period}",
432 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
433 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
434 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
435 "CDEF:sl_state=sleep,INF,*",
436
437 "AREA:sl_state#a0a0a0:disk standby\\j",
438 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
439 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
440
441 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
442 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
443 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
444 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
445 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
446 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
447 $ERROR = RRDs::error;
448 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
449 }
450
451 sub updatediskdatanew {
452 my $disk = $_[0];
453
454 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
455 if ( ! -e "$rrdlog/disk-$disk.rrd") {
456 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
457 "DS:readsect:COUNTER:600:0:5000000000",
458 "DS:writesect:COUNTER:600:0:5000000000",
459 "DS:sleeping:GAUGE:600:0:1",
460 "RRA:AVERAGE:0.5:1:576",
461 "RRA:AVERAGE:0.5:6:672",
462 "RRA:AVERAGE:0.5:24:732",
463 "RRA:AVERAGE:0.5:144:1460");
464 $ERROR = RRDs::error;
465 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
466 }
467
468 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
469 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
470
471 my $major = $rdev >> 8;
472 my $minor = ($rdev & 0xFF) >>6;
473
474 open STAT, "/proc/stat";
475 my @diskstat = <STAT>;
476 close (STAT);
477 foreach my $line (@diskstat)
478 {
479 chomp ($line);
480 my @temp = split(/\:\ /,$line);
481 if ($temp[1]) {
482 my @devicestat = split(/\ /,$temp[1]);
483 foreach my $stats (@devicestat)
484 {
485 chomp ($stats);
486 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
487 if ($major eq $fields[1] and $minor eq $fields[2])
488 {
489 $readwritereq = $fields[3];
490 $readreq = $fields[4];
491 $readsect = $fields[5];
492 $writereq = $fields[6];
493 $writesect = $fields[7];
494 }
495 }
496 }
497 }
498
499 my $sleeping=0;
500 my $lastsleepstate=0;
501
502 if ( -e "/tmp/hddshutdown-$disk" ) {
503 open STAT,"/tmp/hddshutdown-$disk";
504 $lastsleepstate = <STAT>;
505 close (STAT);
506 if ($lastsleepstate==$readwritereq) {
507 $sleeping=1;
508 }
509 }
510
511 if ($readsect && $writesect) {
512 RRDs::update ("$rrdlog/disk-$disk.rrd",
513 "-t", "readsect:writesect:sleeping",
514 "N:$readsect:$writesect:$sleeping");
515 $ERROR = RRDs::error;
516 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
517 } else {
518 print "Error in RRD::update for disk-$disk: no data available\n";
519 }
520 }
521
522 sub updateifgraph {
523 my $interface = $_[0];
524 my $period = $_[1];
525
526 RRDs::graph ("$graphs/$interface-$period.png",
527 "--start", "-1$period", "-aPNG", "-i", "-z",
528 "--alt-y-grid", "-w 600", "-h 100",
529 "--color", "SHADEA#EAE9EE",
530 "--color", "SHADEB#EAE9EE",
531 "--color", "BACK#FFFFFF",
532 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
533 "-v$tr{'bytes per second'}",
534 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
535 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
536 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
537 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
538 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
539 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
540 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
541 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
542 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
543 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
544 $ERROR = RRDs::error;
545 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
546 }
547
548 sub updateifdata {
549 my $interface = $_[0];
550
551 if ( ! -e "$rrdlog/$interface.rrd") {
552 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
553 "DS:incoming:ABSOLUTE:600:0:12500000",
554 "DS:outgoing:ABSOLUTE:600:0:12500000",
555 "RRA:AVERAGE:0.5:1:576",
556 "RRA:AVERAGE:0.5:6:672",
557 "RRA:AVERAGE:0.5:24:732",
558 "RRA:AVERAGE:0.5:144:1460");
559 $ERROR = RRDs::error;
560 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
561 }
562
563 my $traffic = gettraffic ($interface);
564 RRDs::update ("$rrdlog/$interface.rrd",
565 "-t", "incoming:outgoing",
566 "N:$traffic");
567 $ERROR = RRDs::error;
568 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
569 }
570
571 sub updatefwhitsgraph {
572 my $interval = $_[0];
573
574 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
575 "--start", "-1$interval", "-aPNG", "-i", "-z",
576 "--alt-y-grid", "-w 600", "-h 200",
577 "--color", "SHADEA#EAE9EE",
578 "--color", "SHADEB#EAE9EE",
579 "--color", "BACK#FFFFFF",
580 "-t firewall hits over the last $interval",
581 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
582 "AREA:amount#6464FF:firewallhits",
583 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
584 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
585 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
586 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
587 "AREA:portamount#FF6464:portscans",
588 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
589 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
590 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
591 $ERROR = RRDs::error;
592 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
593
594 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
595 "--start", "-1$interval", "-aPNG", "-i", "-z",
596 "--alt-y-grid", "-w 600", "-h 200",
597 "--color", "SHADEA#EAE9EE",
598 "--color", "SHADEB#EAE9EE",
599 "--color", "BACK#FFFFFF",
600 "-t firewall hits over the last $interval",
601 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
602 "LINE2:amount#6464FF:firewallhits",
603 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
604 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
605 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
606 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
607 "LINE2:portamount#FF6464:portscans",
608 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
609 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
610 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
611 $ERROR = RRDs::error;
612 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
613 }
614
615 sub updatefwhitsdata {
616 my $portamount=0;
617 my $alertaktuell=0;
618 my $aktuell=0;
619 my $portaktuell=0;
620 my $skip=0;
621
622 if (! -e "$rrdlog/firewallhits.rrd")
623 {
624 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
625 "DS:amount:GAUGE:600:0:U",
626 "DS:portamount:GAUGE:600:0:U",
627 "RRA:AVERAGE:0.5:1:576",
628 "RRA:AVERAGE:0.5:6:672",
629 "RRA:AVERAGE:0.5:24:732",
630 "RRA:AVERAGE:0.5:144:1460");
631 $ERROR = RRDs::error;
632 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
633 }
634
635 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
636 if (!(open (FILE,'/tmp/messages.fwhits'))) {
637 $skip=1;
638 }
639 $aktuell = 0;
640 if (!$skip) {
641 while (<FILE>) {
642 if (/kernel:.*(IN=.*)$/) {
643 $aktuell++;
644 }
645 }
646 close (FILE);
647 }
648
649 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
650 if (!(open (FILE,'/tmp/snort.fwhits'))) {
651 $skip=1;
652 }
653 $alertaktuell = 0;
654 if (!$skip) {
655 while (<FILE>) {
656 if (/scan.*$/) {
657 $alertaktuell++;
658 }
659 }
660 close (FILE);
661 }
662
663 if (!(open (FILE,'/tmp/messages.fwhits'))) {
664 $skip=1;
665 }
666 $portaktuell = 0;
667 if (!$skip) {
668 while (<FILE>) {
669 if (/kernel:.*(Scan.*)$/) {
670 $portaktuell++;
671 }
672 }
673 close (FILE);
674 }
675
676 system("rm /tmp/messages.fwhits");
677 system("rm /tmp/snort.fwhits");
678
679 $portamount = $portaktuell + $alertaktuell;
680 chomp($portamount);
681 RRDs::update ("$rrdlog/firewallhits.rrd",
682 "N:$aktuell:$portamount");
683 $ERROR = RRDs::error;
684 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
685 }
686
687 # Creates and updates a link quality database
688 # -------------------------------------------
689 sub updatelq {
690 if ( ! -e "$rrdlog/lq.rrd") {
691 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
692 "DS:loss:GAUGE:600:0:100",
693 "DS:roundtrip:GAUGE:600:0:10000",
694 "RRA:AVERAGE:0.5:1:576",
695 "RRA:AVERAGE:0.5:6:672",
696 "RRA:AVERAGE:0.5:24:732",
697 "RRA:AVERAGE:0.5:144:1460");
698 $ERROR = RRDs::error;
699 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
700 }
701 my $packetloss=0;
702 my $roundtrip=0;
703 my $test=0;
704 # LQ_GATEWAY is the ip of your isp's public ip facing you
705 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
706 my $NUMPINGS=10;
707 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
708 chomp;
709 my @temp = split (/\/|\%|\s/, $pingoutput);
710 $packetloss = $temp[17];
711 $roundtrip = $temp[28];
712 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
713 $ERROR = RRDs::error;
714 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
715 }
716
717 sub updatelqgraph {
718 my $period = $_[0];
719 RRDs::graph ("$graphs/lq-$period.png",
720 "--start", "-1$period", "-aPNG", "-i", "-z",
721 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
722 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
723 "--lazy",
724 "--color", "SHADEA#EAE9EE",
725 "--color", "SHADEB#EAE9EE",
726 "--color", "BACK#FFFFFF",
727 "-v ms / pkts (% x10)",
728 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
729 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
730 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
731 "CDEF:loss10=loss,10,*",
732 "CDEF:r0=roundtrip,30,MIN",
733 "CDEF:r1=roundtrip,70,MIN",
734 "CDEF:r2=roundtrip,150,MIN",
735 "CDEF:r3=roundtrip,300,MIN",
736 "AREA:roundtrip#EE7000:>300 ms",
737 "AREA:r3#D88E1B:150-300 ms",
738 "AREA:r2#B9B63F:70-150 ms",
739 "AREA:r1#99E064:30-70 ms",
740 "AREA:r0#80FF80:<30 ms",
741 "AREA:loss10#800000:Packet loss (x10)",
742 "LINE1:roundtrip#707070:",
743 "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
744 "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
745 "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
746 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
747 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
748 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
749 );
750 $ERROR = RRDs::error;
751 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
752 }
753
754 sub updatehdddata
755 {
756 my $disk = $_[0];
757 if ( ! -e "$rrdlog/hddtemp-$disk.rrd")
758 {
759 # database did not exist -> create
760 RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300",
761 "DS:temperature:GAUGE:600:0:100",
762 "RRA:AVERAGE:0.5:1:576",
763 "RRA:AVERAGE:0.5:6:672",
764 "RRA:AVERAGE:0.5:24:732",
765 "RRA:AVERAGE:0.5:144:1460");
766 $ERROR = RRDs::error;
767 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
768 }
769
770 $temp = 0;
771 my $hdd_output = '';
772 my $smart_output = '';
773
774 if ( -e "$path_smartctl" )
775 {
776 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
777 }
778
779 if ( -e "$path_hddtemp" )
780 {
781 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
782
783 # I know 4 response possible responses:
784 #
785 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
786 # /dev/harddisk: harddisk type: no sensor
787 # /dev/harddisk: harddisk type: 37°C or °F
788 # 37
789
790 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
791 {
792 $temp = 0;
793 }
794 elsif ( index($hdd_output, "no sensor") != -1 )
795 {
796 $temp = 1;
797 }
798 elsif ( index($hdd_output, "$disk") != -1 )
799 {
800 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
801 $temp = $1;
802 }
803 else
804 {
805 $hdd_output =~ /(\d+)\s/;
806 $temp = $1;
807 }
808 }
809 elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
810 {
811 $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
812 my @t = split(/\s+/,$hdd_output);
813 $temp = $t[9];
814 }
815 else
816 {
817 $temp = 0;
818 }
819
820 # print "hdd $hdd_output \n";
821 # print "temp $temp \n";
822
823 RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
824
825 $ERROR = RRDs::error;
826 print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
827 }
828
829 sub updatehddgraph {
830 my $disk = $_[0];
831 my $period = $_[1];
832
833 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
834 "--start", "-1$period", "-aPNG", "-i", "-z",
835 "--alt-y-grid", "-w 600", "-h 100",
836 "--color", "SHADEA#EAE9EE",
837 "--color", "SHADEB#EAE9EE",
838 "--color", "BACK#FFFFFF",
839 "-t $tr{'harddisk temperature'} ($tr{'graph per'} $tr{$period})",
840 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
841 "LINE2:temperature#0000FF:$tr{'hdd temperature in'} °C",
842 "GPRINT:temperature:MAX:$tr{'maximal'}\\:%3.0lf °C",
843 "GPRINT:temperature:AVERAGE:$tr{'average'}\\:%3.0lf °C",
844 "GPRINT:temperature:LAST:$tr{'current'}\\:%3.0lf °C",
845 );
846 $ERROR = RRDs::error;
847 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
848 }
849
850 sub updatembmondata
851 {
852 if ( ! -e "$rrdlog/mbmon.rrd" )
853 {
854 # database did not exist -> create
855
856 @args = ("$rrdlog/mbmon.rrd");
857
858 push(@args, "--step=300");
859 foreach $key ( sort(keys %mbmon_values) )
860 {
861 push(@args, "DS:$key:GAUGE:600:U:U");
862 }
863 push(@args, "RRA:AVERAGE:0.5:1:576");
864 push(@args, "RRA:AVERAGE:0.5:6:672");
865 push(@args, "RRA:AVERAGE:0.5:24:732");
866 push(@args, "RRA:AVERAGE:0.5:144:1460");
867
868 print("create ". join( ", ", @args)) if ( $dbg );
869
870 RRDs::create (@args);
871 $ERROR = RRDs::error;
872 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
873 }
874
875 my @ds;
876 my @val;
877 my $template;
878
879 foreach $key ( sort(keys %mbmon_values) )
880 {
881 push(@ds, $key);
882 push(@val, $mbmon_values{$key});
883 }
884
885 $template = join(':', @ds);
886 $value = "N:".join(':', @val);
887
888 print("update template = '$template'\n") if ( $dbg );
889 print("update value = '$value'\n") if ( $dbg );
890
891 RRDs::update("$rrdlog/mbmon.rrd", "-t", $template, $value);
892 $ERROR = RRDs::error;
893 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
894 }
895
896 sub updatetempgraph
897 {
898 my $type = "temp";
899 my $period = $_[0];
900
901 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
902 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
903 "--color", "SHADEA#EAE9EE",
904 "--color", "SHADEB#EAE9EE",
905 "--color", "BACK#FFFFFF",
906 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
907
908 $count = 1;
909 foreach $key ( sort(keys %mbmon_values) )
910 {
911 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
912 {
913 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
914 {
915 $mbmon_settings{'LABEL-'.$key} = $key;
916 }
917
918 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
919 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon temp in'} °C");
920 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.1lf °C");
921 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.1lf °C");
922 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.1lf °C\\j");
923
924 $count++;
925 }
926 }
927
928 if ( $count > 1 )
929 {
930 RRDs::graph ( @args );
931 $ERROR = RRDs::error;
932 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
933 }
934 }
935
936 sub updatefangraph
937 {
938 my $type = "fan";
939 my $period = $_[0];
940
941 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
942 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
943 "--color", "SHADEA#EAE9EE",
944 "--color", "SHADEB#EAE9EE",
945 "--color", "BACK#FFFFFF",
946 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
947
948 $count = 1;
949 foreach $key ( sort(keys %mbmon_values) )
950 {
951 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
952 {
953 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
954 {
955 $mbmon_settings{'LABEL-'.$key} = $key;
956 }
957
958 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
959 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon fan in'} rpm");
960 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.0lf rpm");
961 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.0lf rpm");
962 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.0lf rpm\\j");
963
964 $count++;
965 }
966 }
967
968 if ( $count > 1 )
969 {
970 RRDs::graph ( @args );
971 $ERROR = RRDs::error;
972 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
973 }
974 }
975
976 sub updatevoltgraph
977 {
978 my $type = "volt";
979 my $period = $_[0];
980
981 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
982 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
983 "--color", "SHADEA#EAE9EE",
984 "--color", "SHADEB#EAE9EE",
985 "--color", "BACK#FFFFFF",
986 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
987
988 $count = 1;
989 foreach $key ( sort(keys %mbmon_values) )
990 {
991 my $v = substr($key,0,1);
992 if ( ($v eq 'v') && ($mbmon_settings{'LINE-'.$key} eq 'on') )
993 {
994 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
995 {
996 $mbmon_settings{'LABEL-'.$key} = $key;
997 }
998
999 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
1000 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} V");
1001 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.2lf V");
1002 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.2lf V");
1003 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.2lf V\\j");
1004
1005 $count++;
1006 }
1007 }
1008
1009 if ( $count > 1 )
1010 {
1011 RRDs::graph ( @args );
1012 $ERROR = RRDs::error;
1013 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
1014 }
1015 }
1016
1017 ## Update ipac logs
1018 system ('/usr/sbin/fetchipac');
1019 sleep 8;
1020
1021 ###
1022 ### Squid Graphs
1023 ###
1024 if ( -e "/var/log/squid/access.log") {
1025 system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
1026 }
1027
1028 ###
1029 ### utf8 conversion
1030 ###
1031 if ((${Lang::language} eq 'cs') ||
1032 (${Lang::language} eq 'hu') ||
1033 (${Lang::language} eq 'pl') ||
1034 (${Lang::language} eq 'sk')) {
1035 # Czech, Hungarian, Polish and Slovak character set
1036 foreach my $key(keys %Lang::tr) {
1037 from_to($tr{$key}, "utf-8", "iso-8859-2");
1038 }
1039 } elsif (${Lang::language} eq 'tr') {
1040 # Turkish
1041 foreach my $key(keys %Lang::tr) {
1042 from_to($tr{$key}, "utf-8", "iso-8859-9");
1043 }
1044 } else {
1045 foreach my $key(keys %Lang::tr) {
1046 from_to($tr{$key}, "utf-8", "iso-8859-1");
1047 }
1048 }
1049
1050 ###
1051 ### System graphs
1052 ###
1053 updatecpudata();
1054 updatecpugraph ("day");
1055 updatecpugraph ("week");
1056 updatecpugraph ("month");
1057 updatecpugraph ("year");
1058
1059 updateloaddata();
1060 updateloadgraph ("day");
1061 updateloadgraph ("week");
1062 updateloadgraph ("month");
1063 updateloadgraph ("year");
1064
1065 updatememdata();
1066 updatememgraph ("day");
1067 updatememgraph ("week");
1068 updatememgraph ("month");
1069 updatememgraph ("year");
1070
1071 updatediskdata();
1072 updatediskgraph ("day");
1073 updatediskgraph ("week");
1074 updatediskgraph ("month");
1075 updatediskgraph ("year");
1076
1077 if (open STAT,"/dev/hda") {
1078 close STAT;
1079 updatediskdatanew ("hda");
1080 updatediskgraphnew ("hda","day");
1081 updatediskgraphnew ("hda","week");
1082 updatediskgraphnew ("hda","month");
1083 updatediskgraphnew ("hda","year");
1084 } else {
1085 if (-e "$graphs/disk-hda-day.png") {
1086 system("rm $graphs/disk-hda-day.png");
1087 }
1088 }
1089
1090 if (open STAT,"/dev/hdb") {
1091 close STAT;
1092 updatediskdatanew ("hdb");
1093 updatediskgraphnew ("hdb","day");
1094 updatediskgraphnew ("hdb","week");
1095 updatediskgraphnew ("hdb","month");
1096 updatediskgraphnew ("hdb","year");
1097 } else {
1098 if (-e "$graphs/disk-hdb-day.png") {
1099 system("rm $graphs/disk-hdb-day.png");
1100 }
1101 }
1102
1103 if (open STAT,"/dev/hdc") {
1104 close STAT;
1105 updatediskdatanew ("hdc");
1106 updatediskgraphnew ("hdc","day");
1107 updatediskgraphnew ("hdc","week");
1108 updatediskgraphnew ("hdc","month");
1109 updatediskgraphnew ("hdc","year");
1110 } else {
1111 if (-e "$graphs/disk-hdc-day.png") {
1112 system("rm $graphs/disk-hdc-day.png");
1113 }
1114 }
1115
1116 if (open STAT,"/dev/hdd") {
1117 close STAT;
1118 updatediskdatanew ("hdd");
1119 updatediskgraphnew ("hdd","day");
1120 updatediskgraphnew ("hdd","week");
1121 updatediskgraphnew ("hdd","month");
1122 updatediskgraphnew ("hdd","year");
1123 } else {
1124 if (-e "$graphs/disk-hdd-day.png") {
1125 system("rm $graphs/disk-hdd-day.png");
1126 }
1127 }
1128
1129 if (open STAT,"/dev/hde") {
1130 close STAT;
1131 updatediskdatanew ("hde");
1132 updatediskgraphnew ("hde","day");
1133 updatediskgraphnew ("hde","week");
1134 updatediskgraphnew ("hde","month");
1135 updatediskgraphnew ("hde","year");
1136 } else {
1137 if (-e "$graphs/disk-hde-day.png") {
1138 system("rm $graphs/disk-hde-day.png");
1139 }
1140 }
1141
1142 if (open STAT,"/dev/hdf") {
1143 close STAT;
1144 updatediskdatanew ("hdf");
1145 updatediskgraphnew ("hdf","day");
1146 updatediskgraphnew ("hdf","week");
1147 updatediskgraphnew ("hdf","month");
1148 updatediskgraphnew ("hdf","year");
1149 } else {
1150 if (-e "$graphs/disk-hdf-day.png") {
1151 system("rm $graphs/disk-hdf-day.png");
1152 }
1153 }
1154
1155 if (open STAT,"/dev/hdg") {
1156 close STAT;
1157 updatediskdatanew ("hdg");
1158 updatediskgraphnew ("hdg","day");
1159 updatediskgraphnew ("hdg","week");
1160 updatediskgraphnew ("hdg","month");
1161 updatediskgraphnew ("hdg","year");
1162 } else {
1163 if (-e "$graphs/disk-hdg-day.png") {
1164 system("rm $graphs/disk-hdg-day.png");
1165 }
1166 }
1167
1168 if (open STAT,"/dev/hdh") {
1169 close STAT;
1170 updatediskdatanew ("hdh");
1171 updatediskgraphnew ("hdh","day");
1172 updatediskgraphnew ("hdh","week");
1173 updatediskgraphnew ("hdh","month");
1174 updatediskgraphnew ("hdh","year");
1175 } else {
1176 if (-e "$graphs/disk-hdh-day.png") {
1177 system("rm $graphs/disk-hdh-day.png");
1178 }
1179 }
1180
1181 ###
1182 ### Firewallhits
1183 ###
1184 updatefwhitsdata();
1185 updatefwhitsgraph ("day");
1186 updatefwhitsgraph ("week");
1187 updatefwhitsgraph ("month");
1188 updatefwhitsgraph ("year");
1189
1190 ###
1191 ### Link Quality
1192 ###
1193 updatelq();
1194 sleep 2;
1195 updatelqgraph("day");
1196 updatelqgraph("week");
1197 updatelqgraph("month");
1198 updatelqgraph("year");
1199
1200 ###
1201 ### HDDTEMP-Graphs for /dev/harddisk
1202 ###
1203 if (open STAT,"/dev/hda") {
1204 close STAT;
1205 updatehdddata ("hda");
1206 updatehddgraph ("hda","day");
1207 updatehddgraph ("hda","week");
1208 updatehddgraph ("hda","month");
1209 updatehddgraph ("hda","year");
1210 } else {
1211 if (-e "$graphs/hddtemp-hda-day.png") {
1212 system("rm $graphs/hddtemp-hda-day.png");
1213 }
1214 }
1215
1216 if (open STAT,"/dev/hdb") {
1217 close STAT;
1218 updatehdddata ("hdb");
1219 updatehddgraph ("hdb","day");
1220 updatehddgraph ("hdb","week");
1221 updatehddgraph ("hdb","month");
1222 updatehddgraph ("hdb","year");
1223 } else {
1224 if (-e "$graphs/hddtemp-hdb-day.png") {
1225 system("rm $graphs/hddtemp-hdb-day.png");
1226 }
1227 }
1228
1229 if (open STAT,"/dev/hdc") {
1230 close STAT;
1231 updatehdddata ("hdc");
1232 updatehddgraph ("hdc","day");
1233 updatehddgraph ("hdc","week");
1234 updatehddgraph ("hdc","month");
1235 updatehddgraph ("hdc","year");
1236 } else {
1237 if (-e "$graphs/hddtemp-hdc-day.png") {
1238 system("rm $graphs/hddtemp-hdc-day.png");
1239 }
1240 }
1241
1242 if (open STAT,"/dev/hdd") {
1243 close STAT;
1244 updatehdddata ("hdd");
1245 updatehddgraph ("hdd","day");
1246 updatehddgraph ("hdd","week");
1247 updatehddgraph ("hdd","month");
1248 updatehddgraph ("hdd","year");
1249 } else {
1250 if (-e "$graphs/hddtemp-hdd-day.png") {
1251 system("rm $graphs/hddtemp-hdd-day.png");
1252 }
1253 }
1254
1255 if (open STAT,"/dev/hde") {
1256 close STAT;
1257 updatehdddata ("hde");
1258 updatehddgraph ("hde","day");
1259 updatehddgraph ("hde","week");
1260 updatehddgraph ("hde","month");
1261 updatehddgraph ("hde","year");
1262 } else {
1263 if (-e "$graphs/hddtemp-hde-day.png") {
1264 system("rm $graphs/hddtemp-hde-day.png");
1265 }
1266 }
1267
1268 if (open STAT,"/dev/hdf") {
1269 close STAT;
1270 updatehdddata ("hdf");
1271 updatehddgraph ("hdf","day");
1272 updatehddgraph ("hdf","week");
1273 updatehddgraph ("hdf","month");
1274 updatehddgraph ("hdf","year");
1275 } else {
1276 if (-e "$graphs/hddtemp-hdf-day.png") {
1277 system("rm $graphs/hddtemp-hdf-day.png");
1278 }
1279 }
1280
1281 if (open STAT,"/dev/hdg") {
1282 close STAT;
1283 updatehdddata ("hdg");
1284 updatehddgraph ("hdg","day");
1285 updatehddgraph ("hdg","week");
1286 updatehddgraph ("hdg","month");
1287 updatehddgraph ("hdg","year");
1288 } else {
1289 if (-e "$graphs/hddtemp-hdg-day.png") {
1290 system("rm $graphs/hddtemp-hdg-day.png");
1291 }
1292 }
1293
1294 if (open STAT,"/dev/hdh") {
1295 close STAT;
1296 updatehdddata ("hdh");
1297 updatehddgraph ("hdh","day");
1298 updatehddgraph ("hdh","week");
1299 updatehddgraph ("hdh","month");
1300 updatehddgraph ("hdh","year");
1301 } else {
1302 if (-e "$graphs/hddtemp-hdh-day.png") {
1303 system("rm $graphs/hddtemp-hdh-day.png");
1304 }
1305 }
1306
1307 updatembmondata();
1308
1309 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
1310 {
1311 updatetempgraph ("day");
1312 updatetempgraph ("week");
1313 updatetempgraph ("month");
1314 updatetempgraph ("year");
1315 }
1316 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
1317 {
1318 updatefangraph ("day");
1319 updatefangraph ("week");
1320 updatefangraph ("month");
1321 updatefangraph ("year");
1322 }
1323 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
1324 {
1325 updatevoltgraph ("day");
1326 updatevoltgraph ("week");
1327 updatevoltgraph ("month");
1328 updatevoltgraph ("year");
1329 }
1330
1331 ###
1332 ### Network Graphs
1333 ###
1334 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
1335 if (@ipacsum) {
1336 updateifdata ("GREEN");
1337 updateifdata ("RED");
1338 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) {
1339 updateifdata ("ORANGE");
1340 }
1341 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) {
1342 updateifdata ("BLUE");
1343 }
1344 }
1345 if ( -e "$rrdlog/GREEN.rrd") {
1346 updateifgraph ("GREEN", "day");
1347 updateifgraph ("GREEN", "week");
1348 updateifgraph ("GREEN", "month");
1349 updateifgraph ("GREEN", "year");
1350 }
1351
1352 if ( -e "$rrdlog/RED.rrd") {
1353 updateifgraph ("RED", "day");
1354 updateifgraph ("RED", "week");
1355 updateifgraph ("RED", "month");
1356 updateifgraph ("RED", "year");
1357 }
1358
1359 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e "$rrdlog/ORANGE.rrd") {
1360 updateifgraph ("ORANGE", "day");
1361 updateifgraph ("ORANGE", "week");
1362 updateifgraph ("ORANGE", "month");
1363 updateifgraph ("ORANGE", "year");
1364 }
1365
1366 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e "$rrdlog/BLUE.rrd") {
1367 updateifgraph ("BLUE", "day");
1368 updateifgraph ("BLUE", "week");
1369 updateifgraph ("BLUE", "month");
1370 updateifgraph ("BLUE", "year");
1371 }
1372
1373 system("chmod -R 0777 /srv/web/ipfire/html/graphs");
1374 system("chmod -R 0777 /srv/web/ipfire/html/sgraph");
1375