HinzugefĆ¼gt:
[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";
a68fedca 59my $temp = '';
cd1a2927
MT
60
61sub 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
84sub 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",
39a7cc11 92 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
117sub 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
151sub 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",
39a7cc11 159 "--color", "BACK#FFFFFF",
cd1a2927
MT
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",
39a7cc11 201 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
220sub 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
264sub 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",
39a7cc11 272 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
288sub 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
6c666a3b
MT
344sub 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
374sub 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
cd1a2927
MT
445sub 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",
39a7cc11 454 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
471sub 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
df8c7810
MT
494sub updatefwhitsgraph {
495 my $interval = $_[0];
496
497 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
498 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 499 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
500 "--color", "SHADEA#EAE9EE",
501 "--color", "SHADEB#EAE9EE",
39a7cc11 502 "--color", "BACK#FFFFFF",
df8c7810
MT
503 "-t firewall hits over the last $interval",
504 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
505 "AREA:amount#6464FF:firewallhits",
c7acba4a
MT
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",
df8c7810
MT
509 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
510 "AREA:portamount#FF6464:portscans",
c7acba4a
MT
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");
df8c7810
MT
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",
072cd997 519 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
520 "--color", "SHADEA#EAE9EE",
521 "--color", "SHADEB#EAE9EE",
39a7cc11 522 "--color", "BACK#FFFFFF",
df8c7810
MT
523 "-t firewall hits over the last $interval",
524 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
525 "LINE2:amount#6464FF:firewallhits",
c7acba4a
MT
526 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
527 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
894c6feb 528 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
529 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
530 "LINE2:portamount#FF6464:portscans",
c7acba4a
MT
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");
df8c7810
MT
534 $ERROR = RRDs::error;
535 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
536}
537
538sub 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
072cd997
MT
610# Creates and updates a link quality database
611# -------------------------------------------
612sub 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
986e08d9 628 my $LQ_GATEWAY='www.heise.de';
072cd997
MT
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
640sub 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",
39a7cc11 649 "--color", "BACK#FFFFFF",
072cd997
MT
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:",
c7acba4a
MT
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",
072cd997
MT
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
60cbd6e7
MT
677sub 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