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