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