Hinzugefuegt:
[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 = "/home/httpd/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='www.heise.de';
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 if ( ! -e "$rrdlog/hddtemp.rrd")
757 {
758 # database did not exist -> create
759 RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
760 "DS:temperature:GAUGE:600:0:100",
761 "RRA:AVERAGE:0.5:1:576",
762 "RRA:AVERAGE:0.5:6:672",
763 "RRA:AVERAGE:0.5:24:732",
764 "RRA:AVERAGE:0.5:144:1460");
765 $ERROR = RRDs::error;
766 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
767 }
768
769 $temp = 0;
770 my $hdd_output = '';
771 my $smart_output = '';
772
773 if ( -e "$path_smartctl" )
774 {
775 system("$path_smartctl -iHA $hdd_device > /var/log/hddgraph_smartctl_out");
776 }
777
778 if ( -e "$path_hddtemp" )
779 {
780 $hdd_output = `$path_hddtemp -qn $hdd_device`;
781
782 # I know 4 response possible responses:
783 #
784 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
785 # /dev/harddisk: harddisk type: no sensor
786 # /dev/harddisk: harddisk type: 37°C or °F
787 # 37
788
789 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
790 {
791 $temp = 0;
792 }
793 elsif ( index($hdd_output, "no sensor") != -1 )
794 {
795 $temp = 1;
796 }
797 elsif ( index($hdd_output, "$hdd_device") != -1 )
798 {
799 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
800 $temp = $1;
801 }
802 else
803 {
804 $hdd_output =~ /(\d+)\s/;
805 $temp = $1;
806 }
807 }
808 elsif ( -e "/var/log/hddgraph_smartctl_out" )
809 {
810 $hdd_output = `cat /var/log/hddgraph_smartctl_out | grep Temperature_`;
811 my @t = split(/\s+/,$hdd_output);
812 $temp = $t[9];
813 }
814 else
815 {
816 $temp = 0;
817 }
818
819 # print "hdd $hdd_output \n";
820 # print "temp $temp \n";
821
822 RRDs::update ("$rrdlog/hddtemp.rrd", "-t", "temperature", "N:$temp");
823
824 $ERROR = RRDs::error;
825 print "Error in RRD::update for hdd: $ERROR\n" if $ERROR;
826 }
827
828 sub updatehddgraph {
829 my $period = $_[0];
830
831 RRDs::graph ("$graphs/hddtemp-$period.png",
832 "--start", "-1$period", "-aPNG", "-i", "-z",
833 "--alt-y-grid", "-w 600", "-h 100",
834 "--color", "SHADEA#EAE9EE",
835 "--color", "SHADEB#EAE9EE",
836 "--color", "BACK#FFFFFF",
837 "-t $tr{'harddisk temperature'} ($tr{'graph per'} $tr{$period})",
838 "DEF:temperature=$rrdlog/hddtemp.rrd:temperature:AVERAGE",
839 "LINE2:temperature#0000FF:$tr{'hdd temperature in'} °C",
840 "GPRINT:temperature:MAX:$tr{'maximal'}\\:%3.0lf °C",
841 "GPRINT:temperature:AVERAGE:$tr{'average'}\\:%3.0lf °C",
842 "GPRINT:temperature:LAST:$tr{'current'}\\:%3.0lf °C",
843 );
844 $ERROR = RRDs::error;
845 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
846 }
847
848 sub updatembmondata
849 {
850 if ( ! -e "$rrdlog/mbmon.rrd" )
851 {
852 # database did not exist -> create
853
854 @args = ("$rrdlog/mbmon.rrd");
855
856 push(@args, "--step=300");
857 foreach $key ( sort(keys %mbmon_values) )
858 {
859 push(@args, "DS:$key:GAUGE:600:U:U");
860 }
861 push(@args, "RRA:AVERAGE:0.5:1:576");
862 push(@args, "RRA:AVERAGE:0.5:6:672");
863 push(@args, "RRA:AVERAGE:0.5:24:732");
864 push(@args, "RRA:AVERAGE:0.5:144:1460");
865
866 print("create ". join( ", ", @args)) if ( $dbg );
867
868 RRDs::create (@args);
869 $ERROR = RRDs::error;
870 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
871 }
872
873 my @ds;
874 my @val;
875 my $template;
876
877 foreach $key ( sort(keys %mbmon_values) )
878 {
879 push(@ds, $key);
880 push(@val, $mbmon_values{$key});
881 }
882
883 $template = join(':', @ds);
884 $value = "N:".join(':', @val);
885
886 print("update template = '$template'\n") if ( $dbg );
887 print("update value = '$value'\n") if ( $dbg );
888
889 RRDs::update("$rrdlog/mbmon.rrd", "-t", $template, $value);
890 $ERROR = RRDs::error;
891 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
892 }
893
894 sub updatetempgraph
895 {
896 my $type = "temp";
897 my $period = $_[0];
898
899 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
900 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
901 "--color", "SHADEA#EAE9EE",
902 "--color", "SHADEB#EAE9EE",
903 "--color", "BACK#FFFFFF",
904 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
905
906 $count = 1;
907 foreach $key ( sort(keys %mbmon_values) )
908 {
909 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
910 {
911 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
912 {
913 $mbmon_settings{'LABEL-'.$key} = $key;
914 }
915
916 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
917 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon temp in'} °C");
918 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.1lf °C");
919 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.1lf °C");
920 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.1lf °C\\j");
921
922 $count++;
923 }
924 }
925
926 if ( $count > 1 )
927 {
928 RRDs::graph ( @args );
929 $ERROR = RRDs::error;
930 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
931 }
932 }
933
934 sub updatefangraph
935 {
936 my $type = "fan";
937 my $period = $_[0];
938
939 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
940 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
941 "--color", "SHADEA#EAE9EE",
942 "--color", "SHADEB#EAE9EE",
943 "--color", "BACK#FFFFFF",
944 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
945
946 $count = 1;
947 foreach $key ( sort(keys %mbmon_values) )
948 {
949 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
950 {
951 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
952 {
953 $mbmon_settings{'LABEL-'.$key} = $key;
954 }
955
956 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
957 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon fan in'} rpm");
958 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.0lf rpm");
959 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.0lf rpm");
960 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.0lf rpm\\j");
961
962 $count++;
963 }
964 }
965
966 if ( $count > 1 )
967 {
968 RRDs::graph ( @args );
969 $ERROR = RRDs::error;
970 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
971 }
972 }
973
974 sub updatevoltgraph
975 {
976 my $type = "volt";
977 my $period = $_[0];
978
979 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
980 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
981 "--color", "SHADEA#EAE9EE",
982 "--color", "SHADEB#EAE9EE",
983 "--color", "BACK#FFFFFF",
984 "-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
985
986 $count = 1;
987 foreach $key ( sort(keys %mbmon_values) )
988 {
989 my $v = substr($key,0,1);
990 if ( ($v eq 'v') && ($mbmon_settings{'LINE-'.$key} eq 'on') )
991 {
992 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
993 {
994 $mbmon_settings{'LABEL-'.$key} = $key;
995 }
996
997 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
998 push(@args, "LINE2:$key$colors{$count}:$mbmon_settings{'LABEL-'.$key} V");
999 push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.2lf V");
1000 push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.2lf V");
1001 push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.2lf V\\j");
1002
1003 $count++;
1004 }
1005 }
1006
1007 if ( $count > 1 )
1008 {
1009 RRDs::graph ( @args );
1010 $ERROR = RRDs::error;
1011 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
1012 }
1013 }
1014
1015 ## Update ipac logs
1016 system ('/usr/sbin/fetchipac');
1017 sleep 8;
1018
1019 ###
1020 ### Squid Graphs
1021 ###
1022 if ( -e "/var/log/squid/access.log") {
1023 system ("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
1024 }
1025
1026 ###
1027 ### utf8 conversion
1028 ###
1029 if ((${Lang::language} eq 'cs') ||
1030 (${Lang::language} eq 'hu') ||
1031 (${Lang::language} eq 'pl') ||
1032 (${Lang::language} eq 'sk')) {
1033 # Czech, Hungarian, Polish and Slovak character set
1034 foreach my $key(keys %Lang::tr) {
1035 from_to($tr{$key}, "utf-8", "iso-8859-2");
1036 }
1037 } elsif (${Lang::language} eq 'tr') {
1038 # Turkish
1039 foreach my $key(keys %Lang::tr) {
1040 from_to($tr{$key}, "utf-8", "iso-8859-9");
1041 }
1042 } else {
1043 foreach my $key(keys %Lang::tr) {
1044 from_to($tr{$key}, "utf-8", "iso-8859-1");
1045 }
1046 }
1047
1048 ###
1049 ### System graphs
1050 ###
1051 updatecpudata();
1052 updatecpugraph ("day");
1053 updatecpugraph ("week");
1054 updatecpugraph ("month");
1055 updatecpugraph ("year");
1056
1057 updateloaddata();
1058 updateloadgraph ("day");
1059 updateloadgraph ("week");
1060 updateloadgraph ("month");
1061 updateloadgraph ("year");
1062
1063 updatememdata();
1064 updatememgraph ("day");
1065 updatememgraph ("week");
1066 updatememgraph ("month");
1067 updatememgraph ("year");
1068
1069 updatediskdata();
1070 updatediskgraph ("day");
1071 updatediskgraph ("week");
1072 updatediskgraph ("month");
1073 updatediskgraph ("year");
1074
1075 if (open STAT,"/dev/hda") {
1076 close STAT;
1077 updatediskdatanew ("hda");
1078 updatediskgraphnew ("hda","day");
1079 updatediskgraphnew ("hda","week");
1080 updatediskgraphnew ("hda","month");
1081 updatediskgraphnew ("hda","year");
1082 } else {
1083 if (-e "$graphs/disk-hda-day.png") {
1084 system("rm $graphs/disk-hda-day.png");
1085 }
1086 }
1087
1088 if (open STAT,"/dev/hdb") {
1089 close STAT;
1090 updatediskdatanew ("hdb");
1091 updatediskgraphnew ("hdb","day");
1092 updatediskgraphnew ("hdb","week");
1093 updatediskgraphnew ("hdb","month");
1094 updatediskgraphnew ("hdb","year");
1095 } else {
1096 if (-e "$graphs/disk-hdb-day.png") {
1097 system("rm $graphs/disk-hdb-day.png");
1098 }
1099 }
1100
1101 if (open STAT,"/dev/hdc") {
1102 close STAT;
1103 updatediskdatanew ("hdc");
1104 updatediskgraphnew ("hdc","day");
1105 updatediskgraphnew ("hdc","week");
1106 updatediskgraphnew ("hdc","month");
1107 updatediskgraphnew ("hdc","year");
1108 } else {
1109 if (-e "$graphs/disk-hdc-day.png") {
1110 system("rm $graphs/disk-hdc-day.png");
1111 }
1112 }
1113
1114 if (open STAT,"/dev/hdd") {
1115 close STAT;
1116 updatediskdatanew ("hdd");
1117 updatediskgraphnew ("hdd","day");
1118 updatediskgraphnew ("hdd","week");
1119 updatediskgraphnew ("hdd","month");
1120 updatediskgraphnew ("hdd","year");
1121 } else {
1122 if (-e "$graphs/disk-hdd-day.png") {
1123 system("rm $graphs/disk-hdd-day.png");
1124 }
1125 }
1126
1127 if (open STAT,"/dev/hde") {
1128 close STAT;
1129 updatediskdatanew ("hde");
1130 updatediskgraphnew ("hde","day");
1131 updatediskgraphnew ("hde","week");
1132 updatediskgraphnew ("hde","month");
1133 updatediskgraphnew ("hde","year");
1134 } else {
1135 if (-e "$graphs/disk-hde-day.png") {
1136 system("rm $graphs/disk-hde-day.png");
1137 }
1138 }
1139
1140 if (open STAT,"/dev/hdf") {
1141 close STAT;
1142 updatediskdatanew ("hdf");
1143 updatediskgraphnew ("hdf","day");
1144 updatediskgraphnew ("hdf","week");
1145 updatediskgraphnew ("hdf","month");
1146 updatediskgraphnew ("hdf","year");
1147 } else {
1148 if (-e "$graphs/disk-hdf-day.png") {
1149 system("rm $graphs/disk-hdf-day.png");
1150 }
1151 }
1152
1153 if (open STAT,"/dev/hdg") {
1154 close STAT;
1155 updatediskdatanew ("hdg");
1156 updatediskgraphnew ("hdg","day");
1157 updatediskgraphnew ("hdg","week");
1158 updatediskgraphnew ("hdg","month");
1159 updatediskgraphnew ("hdg","year");
1160 } else {
1161 if (-e "$graphs/disk-hdg-day.png") {
1162 system("rm $graphs/disk-hdg-day.png");
1163 }
1164 }
1165
1166 if (open STAT,"/dev/hdh") {
1167 close STAT;
1168 updatediskdatanew ("hdh");
1169 updatediskgraphnew ("hdh","day");
1170 updatediskgraphnew ("hdh","week");
1171 updatediskgraphnew ("hdh","month");
1172 updatediskgraphnew ("hdh","year");
1173 } else {
1174 if (-e "$graphs/disk-hdh-day.png") {
1175 system("rm $graphs/disk-hdh-day.png");
1176 }
1177 }
1178
1179 ###
1180 ### Firewallhits
1181 ###
1182 updatefwhitsdata();
1183 updatefwhitsgraph ("day");
1184 updatefwhitsgraph ("week");
1185 updatefwhitsgraph ("month");
1186 updatefwhitsgraph ("year");
1187
1188 ###
1189 ### Link Quality
1190 ###
1191 updatelq();
1192 sleep 2;
1193 updatelqgraph("day");
1194 updatelqgraph("week");
1195 updatelqgraph("month");
1196 updatelqgraph("year");
1197
1198 ###
1199 ### HDDTEMP-Graphs for /dev/harddisk
1200 ###
1201 updatehdddata();
1202 updatehddgraph ("day");
1203 updatehddgraph ("week");
1204 updatehddgraph ("month");
1205 updatehddgraph ("year");
1206
1207 updatembmondata();
1208
1209 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
1210 {
1211 updatetempgraph ("day");
1212 updatetempgraph ("week");
1213 updatetempgraph ("month");
1214 updatetempgraph ("year");
1215 }
1216 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
1217 {
1218 updatefangraph ("day");
1219 updatefangraph ("week");
1220 updatefangraph ("month");
1221 updatefangraph ("year");
1222 }
1223 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
1224 {
1225 updatevoltgraph ("day");
1226 updatevoltgraph ("week");
1227 updatevoltgraph ("month");
1228 updatevoltgraph ("year");
1229 }
1230
1231 ###
1232 ### Network Graphs
1233 ###
1234 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
1235 if (@ipacsum) {
1236 updateifdata ("GREEN");
1237 updateifdata ("RED");
1238 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) {
1239 updateifdata ("ORANGE");
1240 }
1241 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) {
1242 updateifdata ("BLUE");
1243 }
1244 }
1245 if ( -e "$rrdlog/GREEN.rrd") {
1246 updateifgraph ("GREEN", "day");
1247 updateifgraph ("GREEN", "week");
1248 updateifgraph ("GREEN", "month");
1249 updateifgraph ("GREEN", "year");
1250 }
1251
1252 if ( -e "$rrdlog/RED.rrd") {
1253 updateifgraph ("RED", "day");
1254 updateifgraph ("RED", "week");
1255 updateifgraph ("RED", "month");
1256 updateifgraph ("RED", "year");
1257 }
1258
1259 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e "$rrdlog/ORANGE.rrd") {
1260 updateifgraph ("ORANGE", "day");
1261 updateifgraph ("ORANGE", "week");
1262 updateifgraph ("ORANGE", "month");
1263 updateifgraph ("ORANGE", "year");
1264 }
1265
1266 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e "$rrdlog/BLUE.rrd") {
1267 updateifgraph ("BLUE", "day");
1268 updateifgraph ("BLUE", "week");
1269 updateifgraph ("BLUE", "month");
1270 updateifgraph ("BLUE", "year");
1271 }
1272
1273 system("chmod -R 0777 /home/httpd/html/graphs");
1274 system("chmod -R 0777 /home/httpd/html/sgraph");
1275