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