]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Proxy Portrange beschraenkt Port darf nicht 444 222 81 oder 53 sein und muss zwischen...
[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);
52345790
MT
34my %mbmon_settings = ();
35&General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
36
cd1a2927
MT
37# Added for conversion of utf-8 characters
38use Encode 'from_to';
39my %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
44if ((${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
57my $rrdlog = "/var/log/rrd";
fd0763dc 58my $graphs = "/srv/web/ipfire/html/graphs";
cd1a2927 59$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
60cbd6e7 60my $hdd_device = "/dev/harddisk";
a68fedca 61my $temp = '';
52345790
MT
62my %mbmon_values = ();
63my $key;
64my $value;
65my @args = ();
66my $count = 0;
67my $ERROR;
68my $dbg = 0;
52345790 69my $path_smartctl = "/usr/sbin/smartctl";
e3a8510a 70my $path_hddtemp = "/usr/sbin/hddtemp";
52345790
MT
71
72my %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
82open(MBMON_OUT, ">/var/log/mbmon-values");
83open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
84
85while( $_ = <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}
94close(FD);
95close(MBMON_OUT);
cd1a2927
MT
96
97sub 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
120sub 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",
39a7cc11 128 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
153sub 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
207cc1cf
MT
187sub 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",
c6aa4ac1
MT
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",
207cc1cf
MT
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
212sub 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
cd1a2927
MT
228sub 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",
39a7cc11 236 "--color", "BACK#FFFFFF",
cd1a2927
MT
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",
39a7cc11 278 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
297sub 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;
c6aa4ac1 319 if ($_ =~ /^MemTotal:/) {
cd1a2927 320 my @temp = split (/\s+/, $_);
c6aa4ac1
MT
321 $memused = $temp[1];
322 } elsif ($_ =~ /^MemFree:/) {
cd1a2927 323 my @temp = split (/\s+/, $_);
c6aa4ac1
MT
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];
cd1a2927
MT
337 }
338 }
339 close MEM;
340
c6aa4ac1
MT
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
cd1a2927
MT
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
360sub 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",
39a7cc11 368 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
384sub 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
6c666a3b
MT
440sub 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
470sub 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
c6aa4ac1
MT
490 print "\n\n$dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks\n\n";
491
6c666a3b
MT
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 }
c6aa4ac1 530 }
6c666a3b
MT
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
cd1a2927
MT
543sub 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",
39a7cc11 552 "--color", "BACK#FFFFFF",
cd1a2927
MT
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
569sub 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
df8c7810
MT
592sub updatefwhitsgraph {
593 my $interval = $_[0];
594
595 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
596 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 597 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
598 "--color", "SHADEA#EAE9EE",
599 "--color", "SHADEB#EAE9EE",
39a7cc11 600 "--color", "BACK#FFFFFF",
df8c7810
MT
601 "-t firewall hits over the last $interval",
602 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
603 "AREA:amount#6464FF:firewallhits",
c7acba4a
MT
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",
df8c7810
MT
607 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
608 "AREA:portamount#FF6464:portscans",
c7acba4a
MT
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");
df8c7810
MT
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",
072cd997 617 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
618 "--color", "SHADEA#EAE9EE",
619 "--color", "SHADEB#EAE9EE",
39a7cc11 620 "--color", "BACK#FFFFFF",
df8c7810
MT
621 "-t firewall hits over the last $interval",
622 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
623 "LINE2:amount#6464FF:firewallhits",
c7acba4a
MT
624 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
625 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
894c6feb 626 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
627 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
628 "LINE2:portamount#FF6464:portscans",
c7acba4a
MT
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");
df8c7810
MT
632 $ERROR = RRDs::error;
633 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
634}
635
636sub 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
072cd997
MT
708# Creates and updates a link quality database
709# -------------------------------------------
710sub 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
66801d8b 726 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
072cd997
MT
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
738sub 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",
39a7cc11 747 "--color", "BACK#FFFFFF",
072cd997
MT
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:",
c7acba4a
MT
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",
072cd997
MT
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
60cbd6e7
MT
775sub updatehdddata
776{
9217f236
MT
777 my $disk = $_[0];
778 if ( ! -e "$rrdlog/hddtemp-$disk.rrd")
60cbd6e7
MT
779 {
780 # database did not exist -> create
9217f236 781 RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300",
60cbd6e7
MT
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;
9217f236 788 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
60cbd6e7
MT
789 }
790
52345790
MT
791 $temp = 0;
792 my $hdd_output = '';
793 my $smart_output = '';
60cbd6e7 794
52345790 795 if ( -e "$path_smartctl" )
60cbd6e7 796 {
9217f236 797 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
60cbd6e7 798 }
52345790
MT
799
800 if ( -e "$path_hddtemp" )
60cbd6e7 801 {
9217f236 802 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
52345790
MT
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