]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Hinzugefuegt:
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
CommitLineData
cd1a2927
MT
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############################################################################
60cbd6e7 24
cd1a2927
MT
25use strict;
26#use warnings;
27
28use RRDs;
986e08d9 29require "/var/ipfire/general-functions.pl";
cd1a2927
MT
30require "${General::swroot}/lang.pl";
31
32my (%settings, @ipacsum, $iface, $ERROR);
33&General::readhash("${General::swroot}/ethernet/settings", \%settings);
34
35# Added for conversion of utf-8 characters
36use Encode 'from_to';
37my %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
42if ((${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
55my $rrdlog = "/var/log/rrd";
56my $graphs = "/home/httpd/html/graphs";
57$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
60cbd6e7 58my $hdd_device = "/dev/harddisk";
cd1a2927
MT
59
60sub gettraffic {
61 my $interface = $_[0];
62
63 my $bytesin=0;
64 my $bytesout=0;
65
66 foreach (@ipacsum)
67 {
68 # Incoming...
69 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
70
71 # Forwarded Incoming...
72 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
73
74 # Outgoing...
75 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
76
77 # Forwarded Outgoing...
78 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
79 }
80 return "$bytesin:$bytesout";
81}
82
83sub updatecpugraph {
84 my $period = $_[0];
85
86 RRDs::graph ("$graphs/cpu-$period.png",
87 "--start", "-1$period", "-aPNG", "-i", "-z",
88 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
89 "--color", "SHADEA#EAE9EE",
90 "--color", "SHADEB#EAE9EE",
39a7cc11 91 "--color", "BACK#FFFFFF",
cd1a2927
MT
92 "-t $tr{'cpu usage per'} $tr{$period}",
93 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
94 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
95 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
96 "CDEF:total=user,system,idle,+,+",
97 "CDEF:userpct=100,user,total,/,*",
98 "CDEF:systempct=100,system,total,/,*",
99 "CDEF:idlepct=100,idle,total,/,*",
100 "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j",
101 "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j",
102 "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j",
103 "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%",
104 "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%",
105 "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j",
106 "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%",
107 "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%",
108 "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j",
109 "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%",
110 "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%",
111 "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j");
112 $ERROR = RRDs::error;
113 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
114}
115
116sub updatecpudata {
117 if ( ! -e "$rrdlog/cpu.rrd") {
118 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
119 "DS:user:COUNTER:600:0:500000000",
120 "DS:system:COUNTER:600:0:500000000",
121 "DS:idle:COUNTER:600:0:500000000",
122 "RRA:AVERAGE:0.5:1:576",
123 "RRA:AVERAGE:0.5:6:672",
124 "RRA:AVERAGE:0.5:24:732",
125 "RRA:AVERAGE:0.5:144:1460");
126 $ERROR = RRDs::error;
127 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
128 }
129
130 my ($cpu, $user, $nice, $system, $idle);
131
132 open STAT, "/proc/stat";
133 while(<STAT>) {
134 chomp;
135 /^cpu\s/ or next;
136 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
137 last;
138 }
139 close STAT;
140 $user += $nice;
141
142 RRDs::update ("$rrdlog/cpu.rrd",
143 "-t", "user:system:idle",
144 "N:$user:$system:$idle");
145 $ERROR = RRDs::error;
146 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
147
148}
149
150sub updatememgraph {
151 my $period = $_[0];
152
153 RRDs::graph ("$graphs/memory-$period.png",
154 "--start", "-1$period", "-aPNG", "-i", "-z",
155 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
156 "--color", "SHADEA#EAE9EE",
157 "--color", "SHADEB#EAE9EE",
39a7cc11 158 "--color", "BACK#FFFFFF",
cd1a2927
MT
159 "-t $tr{'memory usage per'} $tr{$period}",
160 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
161 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
162 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
163 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
164 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
165 "CDEF:total=used,free,+",
166 "CDEF:used2=used,buffer,cache,shared,+,+,-",
167 "CDEF:usedpct=100,used2,total,/,*",
168 "CDEF:sharedpct=100,shared,total,/,*",
169 "CDEF:bufferpct=100,buffer,total,/,*",
170 "CDEF:cachepct=100,cache,total,/,*",
171 "CDEF:freepct=100,free,total,/,*",
172 "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
173 "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
174 "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
175 "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
176 "STACK:freepct#00FF00:$tr{'free memory'}\\j",
177 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
178 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
179 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
180 "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
181 "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
182 "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
183 "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
184 "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
185 "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
186 "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
187 "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
188 "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
189 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
190 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
191 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
192 $ERROR = RRDs::error;
193 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
194
195 RRDs::graph ("$graphs/swap-$period.png",
196 "--start", "-1$period", "-aPNG", "-i", "-z",
197 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
198 "--color", "SHADEA#EAE9EE",
199 "--color", "SHADEB#EAE9EE",
39a7cc11 200 "--color", "BACK#FFFFFF",
cd1a2927
MT
201 "-t $tr{'swap usage per'} $tr{$period}",
202 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
203 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
204 "CDEF:total=used,free,+",
205 "CDEF:usedpct=100,used,total,/,*",
206 "CDEF:freepct=100,free,total,/,*",
207 "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
208 "STACK:freepct#00FF00:$tr{'free swap'}\\j",
209 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
210 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
211 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
212 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
213 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
214 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
215 $ERROR = RRDs::error;
216 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
217}
218
219sub updatememdata {
220 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
221 if ( ! -e "$rrdlog/mem.rrd") {
222 RRDs::create ("$rrdlog/mem.rrd", "--step=300",
223 "DS:memused:ABSOLUTE:600:0:5000000000",
224 "DS:memfree:ABSOLUTE:600:0:5000000000",
225 "DS:memshared:ABSOLUTE:600:0:5000000000",
226 "DS:membuffers:ABSOLUTE:600:0:5000000000",
227 "DS:memcache:ABSOLUTE:600:0:5000000000",
228 "DS:swapused:ABSOLUTE:600:0:5000000000",
229 "DS:swapfree:ABSOLUTE:600:0:5000000000",
230 "RRA:AVERAGE:0.5:1:576",
231 "RRA:AVERAGE:0.5:6:672",
232 "RRA:AVERAGE:0.5:24:732",
233 "RRA:AVERAGE:0.5:144:1460");
234 $ERROR = RRDs::error;
235 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
236 }
237
238 open MEM, "/proc/meminfo";
239 while(<MEM>) {
240 chomp;
241 if ($_ =~ /^Mem:/) {
242 my @temp = split (/\s+/, $_);
243 $memused = $temp[2];
244 $memfree = $temp[3];
245 $memshared = $temp[4];
246 $membuffers = $temp[5];
247 $memcache = $temp[6];
248 } elsif ($_ =~ /^Swap:/) {
249 my @temp = split (/\s+/, $_);
250 $swapused = $temp[2];
251 $swapfree = $temp[3];
252 }
253 }
254 close MEM;
255
256 RRDs::update ("$rrdlog/mem.rrd",
257 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
258 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
259 $ERROR = RRDs::error;
260 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
261}
262
263sub updatediskgraph {
264 my $period = $_[0];
265
266 RRDs::graph ("$graphs/disk-$period.png",
267 "--start", "-1$period", "-aPNG", "-i", "-z",
268 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
269 "--color", "SHADEA#EAE9EE",
270 "--color", "SHADEB#EAE9EE",
39a7cc11 271 "--color", "BACK#FFFFFF",
cd1a2927
MT
272 "-t $tr{'disk access per'} $tr{$period}",
273 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
274 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
275 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
276 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
277 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
278 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
279 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
280 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
281 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
282 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
283 $ERROR = RRDs::error;
284 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
285}
286
287sub updatediskdata {
288 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
289 if ( ! -e "$rrdlog/disk.rrd") {
290 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
291 "DS:readsect:COUNTER:600:0:5000000000",
292 "DS:writesect:COUNTER:600:0:5000000000",
293 "RRA:AVERAGE:0.5:1:576",
294 "RRA:AVERAGE:0.5:6:672",
295 "RRA:AVERAGE:0.5:24:732",
296 "RRA:AVERAGE:0.5:144:1460");
297 $ERROR = RRDs::error;
298 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
299 }
300
301 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
302 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
303
304 my $major = $rdev >> 8;
305 my $minor = $rdev & 0xFF;
306
307 open STAT, "/proc/stat";
308 my @diskstat = <STAT>;
309 close (STAT);
310 foreach my $line (@diskstat)
311 {
312 chomp ($line);
313 my @temp = split(/\:\ /,$line);
314 if ($temp[1]) {
315 my @devicestat = split(/\ /,$temp[1]);
316 foreach my $stats (@devicestat)
317 {
318 chomp ($stats);
319 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
320 if ($major eq $fields[1] and $minor eq $fields[2])
321 {
322 $readwritereq = $fields[3];
323 $readreq = $fields[4];
324 $readsect = $fields[5];
325 $writereq = $fields[6];
326 $writesect = $fields[7];
327 }
328 }
329 }
330 }
331
332 if ($readsect && $writesect) {
333 RRDs::update ("$rrdlog/disk.rrd",
334 "-t", "readsect:writesect",
335 "N:$readsect:$writesect");
336 $ERROR = RRDs::error;
337 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
338 } else {
339 print "Error in RRD::update for disk: no data available\n";
340 }
341}
342
6c666a3b
MT
343sub updatediskgraphnew {
344 my $disk = $_[0];
345 my $period = $_[1];
346
347 RRDs::graph ("$graphs/disk-$disk-$period.png",
348 "--start", "-1$period", "-aPNG", "-i", "-z",
349 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
350 "--color", "SHADEA#EAE9EE",
351 "--color", "SHADEB#EAE9EE",
352 "--color", "BACK#FFFFFF",
353 "-t $tr{'disk access per'} $tr{$period}",
354 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
355 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
356 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
357 "CDEF:sl_state=sleep,INF,*",
358
359 "AREA:sl_state#a0a0a0:disk standby\\j",
360 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
361 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
362
363 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
364 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
365 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
366 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
367 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
368 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
369 $ERROR = RRDs::error;
370 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
371}
372
373sub updatediskdatanew {
374 my $disk = $_[0];
375
376 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
377 if ( ! -e "$rrdlog/disk-$disk.rrd") {
378 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
379 "DS:readsect:COUNTER:600:0:5000000000",
380 "DS:writesect:COUNTER:600:0:5000000000",
381 "DS:sleeping:GAUGE:600:0:1",
382 "RRA:AVERAGE:0.5:1:576",
383 "RRA:AVERAGE:0.5:6:672",
384 "RRA:AVERAGE:0.5:24:732",
385 "RRA:AVERAGE:0.5:144:1460");
386 $ERROR = RRDs::error;
387 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
388 }
389
390 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
391 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
392
393 my $major = $rdev >> 8;
394 my $minor = ($rdev & 0xFF) >>6;
395
396 open STAT, "/proc/stat";
397 my @diskstat = <STAT>;
398 close (STAT);
399 foreach my $line (@diskstat)
400 {
401 chomp ($line);
402 my @temp = split(/\:\ /,$line);
403 if ($temp[1]) {
404 my @devicestat = split(/\ /,$temp[1]);
405 foreach my $stats (@devicestat)
406 {
407 chomp ($stats);
408 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
409 if ($major eq $fields[1] and $minor eq $fields[2])
410 {
411 $readwritereq = $fields[3];
412 $readreq = $fields[4];
413 $readsect = $fields[5];
414 $writereq = $fields[6];
415 $writesect = $fields[7];
416 }
417 }
418 }
419 }
420
421 my $sleeping=0;
422 my $lastsleepstate=0;
423
424 if ( -e "/tmp/hddshutdown-$disk" ) {
425 open STAT,"/tmp/hddshutdown-$disk";
426 $lastsleepstate = <STAT>;
427 close (STAT);
428 if ($lastsleepstate==$readwritereq) {
429 $sleeping=1;
430 }
431 }
432
433 if ($readsect && $writesect) {
434 RRDs::update ("$rrdlog/disk-$disk.rrd",
435 "-t", "readsect:writesect:sleeping",
436 "N:$readsect:$writesect:$sleeping");
437 $ERROR = RRDs::error;
438 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
439 } else {
440 print "Error in RRD::update for disk-$disk: no data available\n";
441 }
442}
443
cd1a2927
MT
444sub updateifgraph {
445 my $interface = $_[0];
446 my $period = $_[1];
447
448 RRDs::graph ("$graphs/$interface-$period.png",
449 "--start", "-1$period", "-aPNG", "-i", "-z",
450 "--alt-y-grid", "-w 600", "-h 100",
451 "--color", "SHADEA#EAE9EE",
452 "--color", "SHADEB#EAE9EE",
39a7cc11 453 "--color", "BACK#FFFFFF",
cd1a2927
MT
454 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
455 "-v$tr{'bytes per second'}",
456 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
457 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
458 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
459 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
460 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
461 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
462 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
463 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
464 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
465 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
466 $ERROR = RRDs::error;
467 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
468}
469
470sub updateifdata {
471 my $interface = $_[0];
472
473 if ( ! -e "$rrdlog/$interface.rrd") {
474 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
475 "DS:incoming:ABSOLUTE:600:0:12500000",
476 "DS:outgoing:ABSOLUTE:600:0:12500000",
477 "RRA:AVERAGE:0.5:1:576",
478 "RRA:AVERAGE:0.5:6:672",
479 "RRA:AVERAGE:0.5:24:732",
480 "RRA:AVERAGE:0.5:144:1460");
481 $ERROR = RRDs::error;
482 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
483 }
484
485 my $traffic = gettraffic ($interface);
486 RRDs::update ("$rrdlog/$interface.rrd",
487 "-t", "incoming:outgoing",
488 "N:$traffic");
489 $ERROR = RRDs::error;
490 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
491}
492
df8c7810
MT
493sub updatefwhitsgraph {
494 my $interval = $_[0];
495
496 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
497 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 498 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
499 "--color", "SHADEA#EAE9EE",
500 "--color", "SHADEB#EAE9EE",
39a7cc11 501 "--color", "BACK#FFFFFF",
df8c7810
MT
502 "-t firewall hits over the last $interval",
503 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
504 "AREA:amount#6464FF:firewallhits",
505 "GPRINT:amount:MAX: Max\\: %2.2lf %S",
506 "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S",
507 "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n",
508 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
509 "AREA:portamount#FF6464:portscans",
510 "GPRINT:portamount:MAX: Max\\: %2.2lf %S",
511 "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S",
512 "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min");
513 $ERROR = RRDs::error;
514 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
515
516 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
517 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 518 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
519 "--color", "SHADEA#EAE9EE",
520 "--color", "SHADEB#EAE9EE",
39a7cc11 521 "--color", "BACK#FFFFFF",
df8c7810
MT
522 "-t firewall hits over the last $interval",
523 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
524 "LINE2:amount#6464FF:firewallhits",
525 "GPRINT:amount:MAX: Max\\: %2.2lf %S",
526 "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S",
527 "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n",
528 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
529 "LINE2:portamount#FF6464:portscans",
530 "GPRINT:portamount:MAX: Max\\: %2.2lf %S",
531 "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S",
532 "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min");
533 $ERROR = RRDs::error;
534 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
535}
536
537sub updatefwhitsdata {
538 my $portamount=0;
539 my $alertaktuell=0;
540 my $aktuell=0;
541 my $portaktuell=0;
542 my $skip=0;
543
544 if (! -e "$rrdlog/firewallhits.rrd")
545 {
546 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
547 "DS:amount:GAUGE:600:0:U",
548 "DS:portamount:GAUGE:600:0:U",
549 "RRA:AVERAGE:0.5:1:576",
550 "RRA:AVERAGE:0.5:6:672",
551 "RRA:AVERAGE:0.5:24:732",
552 "RRA:AVERAGE:0.5:144:1460");
553 $ERROR = RRDs::error;
554 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
555 }
556
557 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
558 if (!(open (FILE,'/tmp/messages.fwhits'))) {
559 $skip=1;
560 }
561 $aktuell = 0;
562 if (!$skip) {
563 while (<FILE>) {
564 if (/kernel:.*(IN=.*)$/) {
565 $aktuell++;
566 }
567 }
568 close (FILE);
569 }
570
571 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
572 if (!(open (FILE,'/tmp/snort.fwhits'))) {
573 $skip=1;
574 }
575 $alertaktuell = 0;
576 if (!$skip) {
577 while (<FILE>) {
578 if (/scan.*$/) {
579 $alertaktuell++;
580 }
581 }
582 close (FILE);
583 }
584
585 if (!(open (FILE,'/tmp/messages.fwhits'))) {
586 $skip=1;
587 }
588 $portaktuell = 0;
589 if (!$skip) {
590 while (<FILE>) {
591 if (/kernel:.*(Scan.*)$/) {
592 $portaktuell++;
593 }
594 }
595 close (FILE);
596 }
597
598 system("rm /tmp/messages.fwhits");
599 system("rm /tmp/snort.fwhits");
600
601 $portamount = $portaktuell + $alertaktuell;
602 chomp($portamount);
603 RRDs::update ("$rrdlog/firewallhits.rrd",
604 "N:$aktuell:$portamount");
605 $ERROR = RRDs::error;
606 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
607}
608
072cd997
MT
609# Creates and updates a link quality database
610# -------------------------------------------
611sub updatelq {
612 if ( ! -e "$rrdlog/lq.rrd") {
613 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
614 "DS:loss:GAUGE:600:0:100",
615 "DS:roundtrip:GAUGE:600:0:10000",
616 "RRA:AVERAGE:0.5:1:576",
617 "RRA:AVERAGE:0.5:6:672",
618 "RRA:AVERAGE:0.5:24:732",
619 "RRA:AVERAGE:0.5:144:1460");
620 $ERROR = RRDs::error;
621 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
622 }
623 my $packetloss=0;
624 my $roundtrip=0;
625 my $test=0;
626# LQ_GATEWAY is the ip of your isp's public ip facing you
986e08d9 627 my $LQ_GATEWAY='www.heise.de';
072cd997
MT
628 my $NUMPINGS=10;
629 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
630 chomp;
631 my @temp = split (/\/|\%|\s/, $pingoutput);
632 $packetloss = $temp[17];
633 $roundtrip = $temp[28];
634 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
635 $ERROR = RRDs::error;
636 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
637}
638
639sub updatelqgraph {
640 my $period = $_[0];
641 RRDs::graph ("$graphs/lq-$period.png",
642 "--start", "-1$period", "-aPNG", "-i", "-z",
643 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
644 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
645 "--lazy",
646 "--color", "SHADEA#EAE9EE",
647 "--color", "SHADEB#EAE9EE",
39a7cc11 648 "--color", "BACK#FFFFFF",
072cd997
MT
649 "-v ms / pkts (% x10)",
650 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
651 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
652 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
653 "CDEF:loss10=loss,10,*",
654 "CDEF:r0=roundtrip,30,MIN",
655 "CDEF:r1=roundtrip,70,MIN",
656 "CDEF:r2=roundtrip,150,MIN",
657 "CDEF:r3=roundtrip,300,MIN",
658 "AREA:roundtrip#EE7000:>300 ms",
659 "AREA:r3#D88E1B:150-300 ms",
660 "AREA:r2#B9B63F:70-150 ms",
661 "AREA:r1#99E064:30-70 ms",
662 "AREA:r0#80FF80:<30 ms",
663 "AREA:loss10#800000:Packet loss (x10)",
664 "LINE1:roundtrip#707070:",
665 "GPRINT:roundtrip:MAX:$tr{'maximal'} $tr{'linkq'}\\:%3.2lf ms",
666 "GPRINT:roundtrip:AVERAGE:$tr{'average'} $tr{'linkq'}\\:%3.2lf ms",
667 "GPRINT:roundtrip:LAST:$tr{'current'} $tr{'linkq'}\\:%3.2lf ms\\j",
668 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
669 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
670 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
671 );
672 $ERROR = RRDs::error;
673 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
674}
675
60cbd6e7
MT
676sub updatehdddata
677{
678 if ( ! -e "$rrdlog/hddtemp.rrd")
679 {
680 # database did not exist -> create
681 RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
682 "DS:temperature:GAUGE:600:0:100",
683 "RRA:AVERAGE:0.5:1:576",
684 "RRA:AVERAGE:0.5:6:672",
685 "RRA:AVERAGE:0.5:24:732",
686 "RRA:AVERAGE:0.5:144:1460");
687 $ERROR = RRDs::error;
688 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
689 }
690
691 my $hdd_output = `/usr/sbin/hddtemp -qn $hdd_device`;
692
693 # I know 4 response possible responses:
694 #
695 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
696 # /dev/harddisk: harddisk type: no sensor
697