]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/makegraphs
HinzugefĆ¼gt:
[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
35 # Added for conversion of utf-8 characters
36 use Encode 'from_to';
37 my %tr=();
38
39 # Force language back to English (ugly hack!)
40 # Modified to only force if we are unable to convert charset
41 # from utf-8
42 if ((${Lang::language} eq 'el') ||
43 (${Lang::language} eq 'fa') ||
44 (${Lang::language} eq 'ru') ||
45 (${Lang::language} eq 'th') ||
46 (${Lang::language} eq 'vi') ||
47 (${Lang::language} eq 'zh') ||
48 (${Lang::language} eq 'zt')) {
49 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
50 } else {
51 %tr=%Lang::tr; # use translated version for other languages
52 }
53
54 # Settings
55 my $rrdlog = "/var/log/rrd";
56 my $graphs = "/home/httpd/html/graphs";
57 $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
58 my $hdd_device = "/dev/harddisk";
59 my $temp = '';
60
61 sub gettraffic {
62 my $interface = $_[0];
63
64 my $bytesin=0;
65 my $bytesout=0;
66
67 foreach (@ipacsum)
68 {
69 # Incoming...
70 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
71
72 # Forwarded Incoming...
73 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
74
75 # Outgoing...
76 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
77
78 # Forwarded Outgoing...
79 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
80 }
81 return "$bytesin:$bytesout";
82 }
83
84 sub updatecpugraph {
85 my $period = $_[0];
86
87 RRDs::graph ("$graphs/cpu-$period.png",
88 "--start", "-1$period", "-aPNG", "-i", "-z",
89 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
90 "--color", "SHADEA#EAE9EE",
91 "--color", "SHADEB#EAE9EE",
92 "--color", "BACK#FFFFFF",
93 "-t $tr{'cpu usage per'} $tr{$period}",
94 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
95 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
96 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
97 "CDEF:total=user,system,idle,+,+",
98 "CDEF:userpct=100,user,total,/,*",
99 "CDEF:systempct=100,system,total,/,*",
100 "CDEF:idlepct=100,idle,total,/,*",
101 "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j",
102 "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j",
103 "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j",
104 "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%",
105 "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%",
106 "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j",
107 "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%",
108 "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%",
109 "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j",
110 "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%",
111 "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%",
112 "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j");
113 $ERROR = RRDs::error;
114 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
115 }
116
117 sub updatecpudata {
118 if ( ! -e "$rrdlog/cpu.rrd") {
119 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
120 "DS:user:COUNTER:600:0:500000000",
121 "DS:system:COUNTER:600:0:500000000",
122 "DS:idle:COUNTER:600:0:500000000",
123 "RRA:AVERAGE:0.5:1:576",
124 "RRA:AVERAGE:0.5:6:672",
125 "RRA:AVERAGE:0.5:24:732",
126 "RRA:AVERAGE:0.5:144:1460");
127 $ERROR = RRDs::error;
128 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
129 }
130
131 my ($cpu, $user, $nice, $system, $idle);
132
133 open STAT, "/proc/stat";
134 while(<STAT>) {
135 chomp;
136 /^cpu\s/ or next;
137 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
138 last;
139 }
140 close STAT;
141 $user += $nice;
142
143 RRDs::update ("$rrdlog/cpu.rrd",
144 "-t", "user:system:idle",
145 "N:$user:$system:$idle");
146 $ERROR = RRDs::error;
147 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
148
149 }
150
151 sub updatememgraph {
152 my $period = $_[0];
153
154 RRDs::graph ("$graphs/memory-$period.png",
155 "--start", "-1$period", "-aPNG", "-i", "-z",
156 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
157 "--color", "SHADEA#EAE9EE",
158 "--color", "SHADEB#EAE9EE",
159 "--color", "BACK#FFFFFF",
160 "-t $tr{'memory usage per'} $tr{$period}",
161 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
162 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
163 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
164 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
165 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
166 "CDEF:total=used,free,+",
167 "CDEF:used2=used,buffer,cache,shared,+,+,-",
168 "CDEF:usedpct=100,used2,total,/,*",
169 "CDEF:sharedpct=100,shared,total,/,*",
170 "CDEF:bufferpct=100,buffer,total,/,*",
171 "CDEF:cachepct=100,cache,total,/,*",
172 "CDEF:freepct=100,free,total,/,*",
173 "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
174 "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
175 "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
176 "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
177 "STACK:freepct#00FF00:$tr{'free memory'}\\j",
178 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
179 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
180 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
181 "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
182 "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
183 "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
184 "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
185 "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
186 "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
187 "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
188 "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
189 "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
190 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
191 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
192 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
193 $ERROR = RRDs::error;
194 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
195
196 RRDs::graph ("$graphs/swap-$period.png",
197 "--start", "-1$period", "-aPNG", "-i", "-z",
198 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
199 "--color", "SHADEA#EAE9EE",
200 "--color", "SHADEB#EAE9EE",
201 "--color", "BACK#FFFFFF",
202 "-t $tr{'swap usage per'} $tr{$period}",
203 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
204 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
205 "CDEF:total=used,free,+",
206 "CDEF:usedpct=100,used,total,/,*",
207 "CDEF:freepct=100,free,total,/,*",
208 "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
209 "STACK:freepct#00FF00:$tr{'free swap'}\\j",
210 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
211 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
212 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
213 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
214 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
215 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
216 $ERROR = RRDs::error;
217 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
218 }
219
220 sub updatememdata {
221 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
222 if ( ! -e "$rrdlog/mem.rrd") {
223 RRDs::create ("$rrdlog/mem.rrd", "--step=300",
224 "DS:memused:ABSOLUTE:600:0:5000000000",
225 "DS:memfree:ABSOLUTE:600:0:5000000000",
226 "DS:memshared:ABSOLUTE:600:0:5000000000",
227 "DS:membuffers:ABSOLUTE:600:0:5000000000",
228 "DS:memcache:ABSOLUTE:600:0:5000000000",
229 "DS:swapused:ABSOLUTE:600:0:5000000000",
230 "DS:swapfree:ABSOLUTE:600:0:5000000000",
231 "RRA:AVERAGE:0.5:1:576",
232 "RRA:AVERAGE:0.5:6:672",
233 "RRA:AVERAGE:0.5:24:732",
234 "RRA:AVERAGE:0.5:144:1460");
235 $ERROR = RRDs::error;
236 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
237 }
238
239 open MEM, "/proc/meminfo";
240 while(<MEM>) {
241 chomp;
242 if ($_ =~ /^Mem:/) {
243 my @temp = split (/\s+/, $_);
244 $memused = $temp[2];
245 $memfree = $temp[3];
246 $memshared = $temp[4];
247 $membuffers = $temp[5];
248 $memcache = $temp[6];
249 } elsif ($_ =~ /^Swap:/) {
250 my @temp = split (/\s+/, $_);
251 $swapused = $temp[2];
252 $swapfree = $temp[3];
253 }
254 }
255 close MEM;
256
257 RRDs::update ("$rrdlog/mem.rrd",
258 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
259 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
260 $ERROR = RRDs::error;
261 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
262 }
263
264 sub updatediskgraph {
265 my $period = $_[0];
266
267 RRDs::graph ("$graphs/disk-$period.png",
268 "--start", "-1$period", "-aPNG", "-i", "-z",
269 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
270 "--color", "SHADEA#EAE9EE",
271 "--color", "SHADEB#EAE9EE",
272 "--color", "BACK#FFFFFF",
273 "-t $tr{'disk access per'} $tr{$period}",
274 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
275 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
276 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
277 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
278 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
279 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
280 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
281 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
282 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
283 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
284 $ERROR = RRDs::error;
285 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
286 }
287
288 sub updatediskdata {
289 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
290 if ( ! -e "$rrdlog/disk.rrd") {
291 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
292 "DS:readsect:COUNTER:600:0:5000000000",
293 "DS:writesect:COUNTER:600:0:5000000000",
294 "RRA:AVERAGE:0.5:1:576",
295 "RRA:AVERAGE:0.5:6:672",
296 "RRA:AVERAGE:0.5:24:732",
297 "RRA:AVERAGE:0.5:144:1460");
298 $ERROR = RRDs::error;
299 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
300 }
301
302 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
303 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
304
305 my $major = $rdev >> 8;
306 my $minor = $rdev & 0xFF;
307
308 open STAT, "/proc/stat";
309 my @diskstat = <STAT>;
310 close (STAT);
311 foreach my $line (@diskstat)
312 {
313 chomp ($line);
314 my @temp = split(/\:\ /,$line);
315 if ($temp[1]) {
316 my @devicestat = split(/\ /,$temp[1]);
317 foreach my $stats (@devicestat)
318 {
319 chomp ($stats);
320 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
321 if ($major eq $fields[1] and $minor eq $fields[2])
322 {
323 $readwritereq = $fields[3];
324 $readreq = $fields[4];
325 $readsect = $fields[5];
326 $writereq = $fields[6];
327 $writesect = $fields[7];
328 }
329 }
330 }
331 }
332
333 if ($readsect && $writesect) {
334 RRDs::update ("$rrdlog/disk.rrd",
335 "-t", "readsect:writesect",
336 "N:$readsect:$writesect");
337 $ERROR = RRDs::error;
338 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
339 } else {
340 print "Error in RRD::update for disk: no data available\n";
341 }
342 }
343
344 sub updatediskgraphnew {
345 my $disk = $_[0];
346 my $period = $_[1];
347
348 RRDs::graph ("$graphs/disk-$disk-$period.png",
349 "--start", "-1$period", "-aPNG", "-i", "-z",
350 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
351 "--color", "SHADEA#EAE9EE",
352 "--color", "SHADEB#EAE9EE",
353 "--color", "BACK#FFFFFF",
354 "-t $tr{'disk access per'} $tr{$period}",
355 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
356 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
357 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
358 "CDEF:sl_state=sleep,INF,*",
359
360 "AREA:sl_state#a0a0a0:disk standby\\j",
361 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
362 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
363
364 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
365 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
366 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
367 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
368 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
369 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
370 $ERROR = RRDs::error;
371 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
372 }
373
374 sub updatediskdatanew {
375 my $disk = $_[0];
376
377 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
378 if ( ! -e "$rrdlog/disk-$disk.rrd") {
379 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
380 "DS:readsect:COUNTER:600:0:5000000000",
381 "DS:writesect:COUNTER:600:0:5000000000",
382 "DS:sleeping:GAUGE:600:0:1",
383 "RRA:AVERAGE:0.5:1:576",
384 "RRA:AVERAGE:0.5:6:672",
385 "RRA:AVERAGE:0.5:24:732",
386 "RRA:AVERAGE:0.5:144:1460");
387 $ERROR = RRDs::error;
388 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
389 }
390
391 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
392 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
393
394 my $major = $rdev >> 8;
395 my $minor = ($rdev & 0xFF) >>6;
396
397 open STAT, "/proc/stat";
398 my @diskstat = <STAT>;
399 close (STAT);
400 foreach my $line (@diskstat)
401 {
402 chomp ($line);
403 my @temp = split(/\:\ /,$line);
404 if ($temp[1]) {
405 my @devicestat = split(/\ /,$temp[1]);
406 foreach my $stats (@devicestat)
407 {
408 chomp ($stats);
409 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
410 if ($major eq $fields[1] and $minor eq $fields[2])
411 {
412 $readwritereq = $fields[3];
413 $readreq = $fields[4];
414 $readsect = $fields[5];
415 $writereq = $fields[6];
416 $writesect = $fields[7];
417 }
418 }
419 }
420 }
421
422 my $sleeping=0;
423 my $lastsleepstate=0;
424
425 if ( -e "/tmp/hddshutdown-$disk" ) {
426 open STAT,"/tmp/hddshutdown-$disk";
427 $lastsleepstate = <STAT>;
428 close (STAT);
429 if ($lastsleepstate==$readwritereq) {
430 $sleeping=1;
431 }
432 }
433
434 if ($readsect && $writesect) {
435 RRDs::update ("$rrdlog/disk-$disk.rrd",
436 "-t", "readsect:writesect:sleeping",
437 "N:$readsect:$writesect:$sleeping");
438 $ERROR = RRDs::error;
439 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
440 } else {
441 print "Error in RRD::update for disk-$disk: no data available\n";
442 }
443 }
444
445 sub updateifgraph {
446 my $interface = $_[0];
447 my $period = $_[1];
448
449 RRDs::graph ("$graphs/$interface-$period.png",
450 "--start", "-1$period", "-aPNG", "-i", "-z",
451 "--alt-y-grid", "-w 600", "-h 100",
452 "--color", "SHADEA#EAE9EE",
453 "--color", "SHADEB#EAE9EE",
454 "--color", "BACK#FFFFFF",
455 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
456 "-v$tr{'bytes per second'}",
457 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
458 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
459 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
460 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
461 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
462 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
463 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
464 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
465 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
466 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
467 $ERROR = RRDs::error;
468 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
469 }
470
471 sub updateifdata {
472 my $interface = $_[0];
473
474 if ( ! -e "$rrdlog/$interface.rrd") {
475 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
476 "DS:incoming:ABSOLUTE:600:0:12500000",
477 "DS:outgoing:ABSOLUTE:600:0:12500000",
478 "RRA:AVERAGE:0.5:1:576",
479 "RRA:AVERAGE:0.5:6:672",
480 "RRA:AVERAGE:0.5:24:732",
481 "RRA:AVERAGE:0.5:144:1460");
482 $ERROR = RRDs::error;
483 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
484 }
485
486 my $traffic = gettraffic ($interface);
487 RRDs::update ("$rrdlog/$interface.rrd",
488 "-t", "incoming:outgoing",
489 "N:$traffic");
490 $ERROR = RRDs::error;
491 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
492 }
493
494 sub updatefwhitsgraph {
495 my $interval = $_[0];
496
497 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
498 "--start", "-1$interval", "-aPNG", "-i", "-z",
499 "--alt-y-grid", "-w 600", "-h 200",
500 "--color", "SHADEA#EAE9EE",
501 "--color", "SHADEB#EAE9EE",
502 "--color", "BACK#FFFFFF",
503 "-t firewall hits over the last $interval",
504 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
505 "AREA:amount#6464FF:firewallhits",
506 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
507 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
508 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
509 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
510 "AREA:portamount#FF6464:portscans",
511 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
512 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
513 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
514 $ERROR = RRDs::error;
515 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
516
517 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
518 "--start", "-1$interval", "-aPNG", "-i", "-z",
519 "--alt-y-grid", "-w 600", "-h 200",
520 "--color", "SHADEA#EAE9EE",
521 "--color", "SHADEB#EAE9EE",
522 "--color", "BACK#FFFFFF",
523 "-t firewall hits over the last $interval",
524 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
525 "LINE2:amount#6464FF:firewallhits",
526 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
527 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
528 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
529 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
530 "LINE2:portamount#FF6464:portscans",
531 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
532 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
533 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
534 $ERROR = RRDs::error;
535 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
536 }
537
538 sub updatefwhitsdata {
539 my $portamount=0;
540 my $alertaktuell=0;
541 my $aktuell=0;
542 my $portaktuell=0;
543 my $skip=0;
544
545 if (! -e "$rrdlog/firewallhits.rrd")
546 {
547 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
548 "DS:amount:GAUGE:600:0:U",
549 "DS:portamount:GAUGE:600:0:U",
550 "RRA:AVERAGE:0.5:1:576",
551 "RRA:AVERAGE:0.5:6:672",
552 "RRA:AVERAGE:0.5:24:732",
553 "RRA:AVERAGE:0.5:144:1460");
554 $ERROR = RRDs::error;
555 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
556 }
557
558 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
559 if (!(open (FILE,'/tmp/messages.fwhits'))) {
560 $skip=1;
561 }
562 $aktuell = 0;
563 if (!$skip) {
564 while (<FILE>) {
565 if (/kernel:.*(IN=.*)$/) {
566 $aktuell++;
567 }
568 }
569 close (FILE);
570 }
571
572 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
573 if (!(open (FILE,'/tmp/snort.fwhits'))) {
574 $skip=1;
575 }
576 $alertaktuell = 0;
577 if (!$skip) {
578 while (<FILE>) {
579 if (/scan.*$/) {
580 $alertaktuell++;
581 }
582 }
583 close (FILE);
584 }
585
586 if (!(open (FILE,'/tmp/messages.fwhits'))) {
587 $skip=1;
588 }
589 $portaktuell = 0;
590 if (!$skip) {
591 while (<FILE>) {
592 if (/kernel:.*(Scan.*)$/) {
593 $portaktuell++;
594 }
595 }
596 close (FILE);
597 }
598
599 system("rm /tmp/messages.fwhits");
600 system("rm /tmp/snort.fwhits");
601
602 $portamount = $portaktuell + $alertaktuell;
603 chomp($portamount);
604 RRDs::update ("$rrdlog/firewallhits.rrd",
605 "N:$aktuell:$portamount");
606 $ERROR = RRDs::error;
607 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
608 }
609
610 # Creates and updates a link quality database
611 # -------------------------------------------
612 sub updatelq {
613 if ( ! -e "$rrdlog/lq.rrd") {
614 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
615 "DS:loss:GAUGE:600:0:100",
616 "DS:roundtrip:GAUGE:600:0:10000",
617 "RRA:AVERAGE:0.5:1:576",
618 "RRA:AVERAGE:0.5:6:672",
619 "RRA:AVERAGE:0.5:24:732",
620 "RRA:AVERAGE:0.5:144:1460");
621 $ERROR = RRDs::error;
622 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
623 }
624 my $packetloss=0;
625 my $roundtrip=0;
626 my $test=0;
627 # LQ_GATEWAY is the ip of your isp's public ip facing you
628 my $LQ_GATEWAY='www.heise.de';
629 my $NUMPINGS=10;
630 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
631 chomp;
632 my @temp = split (/\/|\%|\s/, $pingoutput);
633 $packetloss = $temp[17];
634 $roundtrip = $temp[28];
635 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
636 $ERROR = RRDs::error;
637 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
638 }
639
640 sub updatelqgraph {
641 my $period = $_[0];
642 RRDs::graph ("$graphs/lq-$period.png",
643 "--start", "-1$period", "-aPNG", "-i", "-z",
644 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
645 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
646 "--lazy",
647 "--color", "SHADEA#EAE9EE",
648 "--color", "SHADEB#EAE9EE",
649 "--color", "BACK#FFFFFF",
650 "-v ms / pkts (% x10)",
651 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
652 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
653 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
654 "CDEF:loss10=loss,10,*",
655 "CDEF:r0=roundtrip,30,MIN",
656 "CDEF:r1=roundtrip,70,MIN",
657 "CDEF:r2=roundtrip,150,MIN",
658 "CDEF:r3=roundtrip,300,MIN",
659 "AREA:roundtrip#EE7000:>300 ms",
660 "AREA:r3#D88E1B:150-300 ms",
661 "AREA:r2#B9B63F:70-150 ms",
662 "AREA:r1#99E064:30-70 ms",
663 "AREA:r0#80FF80:<30 ms",
664 "AREA:loss10#800000:Packet loss (x10)",
665 "LINE1:roundtrip#707070:",
666 "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
667 "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
668 "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
669 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
670 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
671 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
672 );
673 $ERROR = RRDs::error;
674 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
675 }
676
677 sub updatehdddata
678 {
679 if ( ! -e "$rrdlog/hddtemp.rrd")
680 {
681 # database did not exist -> create
682 RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
683 "DS:temperature:GAUGE:600:0:100",
684 "RRA:AVERAGE:0.5:1:576",
685 "RRA:AVERAGE:0.5:6:672",
686 "RRA:AVERAGE:0.5:24:732",
687 "RRA:AVERAGE:0.5:144:1460");
688 $ERROR = RRDs::error;
689 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
690 }
691
692 my $hdd_output = `/usr/sbin/hddtemp -qn $hdd_device`;
693
694 # I know 4 response possible responses:
695 #
696 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
697 # /dev/harddisk: harddisk type: no sensor
698 # /dev/harddisk: harddisk type: 37Ā°C or Ā°F
699 # 37
700
701 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
702 {
703 $temp = 0;
704 }
705 elsif ( index($hdd_output, "no sensor") != -1 )
706 {
707 $temp = 1;
708 }
709 elsif ( index($hdd_output, "$hdd_device") != -1 )
710 {
711 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
712 $temp = $1;
713 }
714 else
715 {
716 $hdd_output =~ /(\d+)\s/;
717 $temp = $1;
718 }
719
720 RRDs::update ("$rrdlog/hddtemp.rrd", "-t", "temperature", "N:$temp");
721
722 $ERROR = RRDs::error;
723 print "Error in RRD::update for hdd: $ERROR\n" if $ERROR;
724 }
725
726 sub updatehddgraph {
727 my $period = $_[0];
728
729 RRDs::graph ("$graphs/hddtemp-$period.png",
730 "--start", "-1$period", "-aPNG", "-i", "-z",
731 "--alt-y-grid", "-w 600", "-h 100",
732 "--color", "SHADEA#EAE9EE",
733 "--color", "SHADEB#EAE9EE",
734 "--color", "BACK#FFFFFF",
735 "-t $tr{'harddisk temperature'} ($tr{'graph per'} $tr{$period})",
736 "DEF:temperature=$rrdlog/hddtemp.rrd:temperature:AVERAGE",
737 "LINE2:temperature#0000FF:$tr{'hdd temperature in'} Ā°C",
738 "GPRINT:temperature:MAX:$tr{'maximal'}\\:%3.0lf Ā°C",
739 "GPRINT:temperature:AVERAGE:$tr{'average'}\\:%3.0lf Ā°C",
740 "GPRINT:temperature:LAST:$tr{'current'}\\:%3.0lf Ā°C",
741 );
742 $ERROR = RRDs::error;
743 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
744 }
745
746 ## Update ipac logs
747 system ('/usr/sbin/fetchipac');
748 sleep 8;
749
750 ###
751 ### Squid Graphs
752 ###
753 if ( -e "/var/log/squid/access.log") {
754 system ("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
755 }
756
757 ###
758 ### utf8 conversion
759 ###
760 if ((${Lang::language} eq 'cs') ||
761 (${Lang::language} eq 'hu') ||
762 (${Lang::language} eq 'pl') ||
763 (${Lang::language} eq 'sk')) {
764 # Czech, Hungarian, Polish and Slovak character set
765 foreach my $key(keys %Lang::tr) {
766 from_to($tr{$key}, "utf-8", "iso-8859-2");
767 }
768 } elsif (${Lang::language} eq 'tr') {
769 # Turkish
770 foreach my $key(keys %Lang::tr) {
771 from_to($tr{$key}, "utf-8", "iso-8859-9");
772 }
773 } else {
774 foreach my $key(keys %Lang::tr) {
775 from_to($tr{$key}, "utf-8", "iso-8859-1");
776 }
777 }
778
779 ###
780 ### System graphs
781 ###
782 updatecpudata();
783 updatecpugraph ("day");
784 updatecpugraph ("week");
785 updatecpugraph ("month");
786 updatecpugraph ("year");
787
788 updatememdata();
789 updatememgraph ("day");
790 updatememgraph ("week");
791 updatememgraph ("month");
792 updatememgraph ("year");
793
794 updatediskdata();
795 updatediskgraph ("day");
796 updatediskgraph ("week");
797 updatediskgraph ("month");
798 updatediskgraph ("year");
799
800 if (open STAT,"/dev/hda") {
801 close STAT;
802 updatediskdatanew ("hda");
803 updatediskgraphnew ("hda","day");
804 updatediskgraphnew ("hda","week");
805 updatediskgraphnew ("hda","month");
806 updatediskgraphnew ("hda","year");
807 } else {
808 if (-e "$graphs/disk-hda-day.png") {
809 system("rm $graphs/disk-hda-day.png");
810 }
811 }
812
813 if (open STAT,"/dev/hdb") {
814 close STAT;
815 updatediskdatanew ("hdb");
816 updatediskgraphnew ("hdb","day");
817 updatediskgraphnew ("hdb","week");
818 updatediskgraphnew ("hdb","month");
819 updatediskgraphnew ("hdb","year");
820 } else {
821 if (-e "$graphs/disk-hdb-day.png") {
822 system("rm $graphs/disk-hdb-day.png");
823 }
824 }
825
826 if (open STAT,"/dev/hdc") {
827 close STAT;
828 updatediskdatanew ("hdc");
829 updatediskgraphnew ("hdc","day");
830 updatediskgraphnew ("hdc","week");
831 updatediskgraphnew ("hdc","month");
832 updatediskgraphnew ("hdc","year");
833 } else {
834 if (-e "$graphs/disk-hdc-day.png") {
835 system("rm $graphs/disk-hdc-day.png");
836 }
837 }
838
839 if (open STAT,"/dev/hdd") {
840 close STAT;
841 updatediskdatanew ("hdd");
842 updatediskgraphnew ("hdd","day");
843 updatediskgraphnew ("hdd","week");
844 updatediskgraphnew ("hdd","month");
845 updatediskgraphnew ("hdd","year");
846 } else {
847 if (-e "$graphs/disk-hdd-day.png") {
848 system("rm $graphs/disk-hdd-day.png");
849 }
850 }
851
852 if (open STAT,"/dev/hde") {
853 close STAT;
854 updatediskdatanew ("hde");
855 updatediskgraphnew ("hde","day");
856 updatediskgraphnew ("hde","week");
857 updatediskgraphnew ("hde","month");
858 updatediskgraphnew ("hde","year");
859 } else {
860 if (-e "$graphs/disk-hde-day.png") {
861 system("rm $graphs/disk-hde-day.png");
862 }
863 }
864
865 if (open STAT,"/dev/hdf") {
866 close STAT;
867 updatediskdatanew ("hdf");
868 updatediskgraphnew ("hdf","day");
869 updatediskgraphnew ("hdf","week");
870 updatediskgraphnew ("hdf","month");
871 updatediskgraphnew ("hdf","year");
872 } else {
873 if (-e "$graphs/disk-hdf-day.png") {
874 system("rm $graphs/disk-hdf-day.png");
875 }
876 }
877
878 if (open STAT,"/dev/hdg") {
879 close STAT;
880 updatediskdatanew ("hdg");
881 updatediskgraphnew ("hdg","day");
882 updatediskgraphnew ("hdg","week");
883 updatediskgraphnew ("hdg","month");
884 updatediskgraphnew ("hdg","year");
885 } else {
886 if (-e "$graphs/disk-hdg-day.png") {
887 system("rm $graphs/disk-hdg-day.png");
888 }
889 }
890
891 if (open STAT,"/dev/hdh") {
892 close STAT;
893 updatediskdatanew ("hdh");
894 updatediskgraphnew ("hdh","day");
895 updatediskgraphnew ("hdh","week");
896 updatediskgraphnew ("hdh","month");
897 updatediskgraphnew ("hdh","year");
898 } else {
899 if (-e "$graphs/disk-hdh-day.png") {
900 system("rm $graphs/disk-hdh-day.png");
901 }
902 }
903
904 ###
905 ### Firewallhits
906 ###
907 updatefwhitsdata();
908 updatefwhitsgraph ("day");
909 updatefwhitsgraph ("week");
910 updatefwhitsgraph ("month");
911 updatefwhitsgraph ("year");
912
913 ###
914 ### Link Quality
915 ###
916 updatelq();
917 sleep 2;
918 updatelqgraph("day");
919 updatelqgraph("week");
920 updatelqgraph("month");
921 updatelqgraph("year");
922
923 ###
924 ### HDDTEMP-Graphs for /dev/harddisk
925 ###
926 updatehdddata();
927 updatehddgraph ("day");
928 updatehddgraph ("week");
929 updatehddgraph ("month");
930 updatehddgraph ("year");
931
932 ###
933 ### Network Graphs
934 ###
935 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
936 if (@ipacsum) {
937 updateifdata ("GREEN");
938 updateifdata ("RED");
939 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) {
940 updateifdata ("ORANGE");
941 }
942 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) {
943 updateifdata ("BLUE");
944 }
945 }
946 if ( -e "$rrdlog/GREEN.rrd") {
947 updateifgraph ("GREEN", "day");
948 updateifgraph ("GREEN", "week");
949 updateifgraph ("GREEN", "month");
950 updateifgraph ("GREEN", "year");
951 }
952
953 if ( -e "$rrdlog/RED.rrd") {
954 updateifgraph ("RED", "day");
955 updateifgraph ("RED", "week");
956 updateifgraph ("RED", "month");
957 updateifgraph ("RED", "year");
958 }
959
960 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e "$rrdlog/ORANGE.rrd") {
961 updateifgraph ("ORANGE", "day");
962 updateifgraph ("ORANGE", "week");
963 updateifgraph ("ORANGE", "month");
964 updateifgraph ("ORANGE", "year");
965 }
966
967 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e "$rrdlog/BLUE.rrd") {
968 updateifgraph ("BLUE", "day");
969 updateifgraph ("BLUE", "week");
970 updateifgraph ("BLUE", "month");
971 updateifgraph ("BLUE", "year");
972 }
973
974 #chmod 777 /home/httpd/html/{graphs,sgraph} -R
975 system("chmod -R 0777 /home/httpd/html/graphs");
976 system("chmod -R 0777 /home/httpd/html/sgraph");
977