Noch ein paar kleine Aenderungen wegen dem mkinitcpio...
[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 71
4b4aec3a
CS
72my %color = ();
73my %mainsettings = ();
74&General::readhash("${General::swroot}/main/settings", \%mainsettings);
75&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
52345790
MT
76
77open(MBMON_OUT, ">/var/log/mbmon-values");
78open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
79
80while( $_ = <FD> )
81{
82 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
83 $key = $1 ;
84 $value = $2 ;
85 $key =~ y/A-Z/a-z/ ;
86 $mbmon_values{$key} = $value;
87 print(MBMON_OUT "$key=$value\n");
88}
89close(FD);
90close(MBMON_OUT);
cd1a2927
MT
91
92sub gettraffic {
93 my $interface = $_[0];
94
95 my $bytesin=0;
96 my $bytesout=0;
97
98 foreach (@ipacsum)
99 {
100 # Incoming...
101 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
102
103 # Forwarded Incoming...
104 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
105
106 # Outgoing...
107 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
108
109 # Forwarded Outgoing...
110 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
111 }
112 return "$bytesin:$bytesout";
113}
114
115sub updatecpugraph {
116 my $period = $_[0];
117
118 RRDs::graph ("$graphs/cpu-$period.png",
119 "--start", "-1$period", "-aPNG", "-i", "-z",
120 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
4b4aec3a 121 "--color", "SHADEA".$color{"color19"},
44052f4b 122 "--color", "SHADEB".$color{"color19"},
4b4aec3a 123 "--color", "BACK".$color{"color21"},
cd1a2927
MT
124 "-t $tr{'cpu usage per'} $tr{$period}",
125 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
126 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
127 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
128 "CDEF:total=user,system,idle,+,+",
129 "CDEF:userpct=100,user,total,/,*",
130 "CDEF:systempct=100,system,total,/,*",
131 "CDEF:idlepct=100,idle,total,/,*",
44052f4b
CS
132 "AREA:userpct".$color{"color11"}.":$tr{'user cpu usage'}",
133 "STACK:systempct".$color{"color13"}.":$tr{'system cpu usage'}",
4b4aec3a 134 "STACK:idlepct".$color{"color12"}.":$tr{'idle cpu usage'}\\j",
44052f4b
CS
135 "COMMENT: \\j",
136 "COMMENT:$tr{'maximal'}",
137 "COMMENT:$tr{'average'}",
138 "COMMENT:$tr{'current'}\\j",
139 "GPRINT:userpct:MAX:$tr{'user cpu'}\\:%3.2lf%%",
140 "GPRINT:userpct:AVERAGE:$tr{'user cpu'}\\:%3.2lf%%",
141 "GPRINT:userpct:LAST:$tr{'user cpu'}\\:%3.2lf%%\\j",
142 "GPRINT:systempct:MAX:$tr{'system cpu'}\\:%3.2lf%%",
143 "GPRINT:systempct:AVERAGE:$tr{'system cpu'}\\:%3.2lf%%",
144 "GPRINT:systempct:LAST:$tr{'system cpu'}\\:%3.2lf%%\\j",
145 "GPRINT:idlepct:MAX:$tr{'idle cpu'}\\:%3.2lf%%",
146 "GPRINT:idlepct:AVERAGE:$tr{'idle cpu'}\\:%3.2lf%%",
147 "GPRINT:idlepct:LAST:$tr{'idle cpu'}\\:%3.2lf%%\\j");
cd1a2927
MT
148 $ERROR = RRDs::error;
149 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
150}
151
152sub updatecpudata {
153 if ( ! -e "$rrdlog/cpu.rrd") {
154 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
155 "DS:user:COUNTER:600:0:500000000",
156 "DS:system:COUNTER:600:0:500000000",
157 "DS:idle:COUNTER:600:0:500000000",
158 "RRA:AVERAGE:0.5:1:576",
159 "RRA:AVERAGE:0.5:6:672",
160 "RRA:AVERAGE:0.5:24:732",
161 "RRA:AVERAGE:0.5:144:1460");
162 $ERROR = RRDs::error;
163 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
164 }
165
166 my ($cpu, $user, $nice, $system, $idle);
167
168 open STAT, "/proc/stat";
169 while(<STAT>) {
170 chomp;
171 /^cpu\s/ or next;
172 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
173 last;
174 }
175 close STAT;
176 $user += $nice;
177
178 RRDs::update ("$rrdlog/cpu.rrd",
179 "-t", "user:system:idle",
180 "N:$user:$system:$idle");
181 $ERROR = RRDs::error;
182 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
183
184}
185
207cc1cf
MT
186sub updateloadgraph {
187 my $period = $_[0];
188
189 RRDs::graph ("$graphs/load-$period.png",
190 "--start", "-1$period", "-aPNG",
191 "-w 600", "-h 100", "-i", "-z", "-l 0", "-r", "--alt-y-grid",
192 "-t Load Average",
4b4aec3a 193 "--color", "SHADEA".$color{"color19"},
44052f4b 194 "--color", "SHADEB".$color{"color19"},
4b4aec3a 195 "--color", "BACK".$color{"color21"},
207cc1cf
MT
196 "DEF:load1=$rrdlog/load.rrd:load1:AVERAGE",
197 "DEF:load5=$rrdlog/load.rrd:load5:AVERAGE",
198 "DEF:load15=$rrdlog/load.rrd:load15:AVERAGE",
44052f4b
CS
199 "AREA:load1".$color{"color13"}.":1 Minute, letzter:",
200 "GPRINT:load1:LAST:%5.2lf",
201 "AREA:load5".$color{"color18"}.":5 Minuten, letzter:",
202 "GPRINT:load5:LAST:%5.2lf",
203 "AREA:load15".$color{"color14"}.":15 Minuten, letzter:",
c6aa4ac1 204 "GPRINT:load15:LAST:%5.2lf\\j",
4b4aec3a
CS
205 "LINE1:load5".$color{"color13"},
206 "LINE1:load1".$color{"color18"});
207cc1cf
MT
207 $ERROR = RRDs::error;
208 print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
209}
210
211sub updateloaddata {
212 if ( ! -e "$rrdlog/load.rrd") {
213 RRDs::create ("$rrdlog/load.rrd", "--step=60",
214 "DS:load1:GAUGE:120:0:U",
215 "DS:load5:GAUGE:120:0:U",
216 "DS:load15:GAUGE:120:0:U",
217 "RRA:AVERAGE:0.5:1:2160",
218 "RRA:AVERAGE:0.5:5:2016",
219 "RRA:AVERAGE:0.5:15:2880",
220 "RRA:AVERAGE:0.5:60:8760");
221
222 $ERROR = RRDs::error;
223 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
224 }
225}
226
cd1a2927
MT
227sub updatememgraph {
228 my $period = $_[0];
229
230 RRDs::graph ("$graphs/memory-$period.png",
231 "--start", "-1$period", "-aPNG", "-i", "-z",
232 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
4b4aec3a 233 "--color", "SHADEA".$color{"color19"},
44052f4b 234 "--color", "SHADEB".$color{"color19"},
4b4aec3a 235 "--color", "BACK".$color{"color21"},
cd1a2927
MT
236 "-t $tr{'memory usage per'} $tr{$period}",
237 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
238 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
239 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
240 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
241 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
242 "CDEF:total=used,free,+",
243 "CDEF:used2=used,buffer,cache,shared,+,+,-",
244 "CDEF:usedpct=100,used2,total,/,*",
245 "CDEF:sharedpct=100,shared,total,/,*",
246 "CDEF:bufferpct=100,buffer,total,/,*",
247 "CDEF:cachepct=100,cache,total,/,*",
248 "CDEF:freepct=100,free,total,/,*",
44052f4b
CS
249 "AREA:usedpct".$color{"color11"}.":$tr{'used memory'}",
250 "STACK:sharedpct".$color{"color13"}.":$tr{'shared memory'}",
251 "STACK:bufferpct".$color{"color23"}.":$tr{'buffered memory'}",
252 "STACK:cachepct".$color{"color14"}.":$tr{'cached memory'}",
4b4aec3a 253 "STACK:freepct".$color{"color12"}.":$tr{'free memory'}\\j",
44052f4b
CS
254 "COMMENT: \\j",
255 "COMMENT:$tr{'maximal'}",
256 "COMMENT:$tr{'average'}",
257 "COMMENT:$tr{'current'}\\j",
258 "GPRINT:usedpct:MAX:$tr{'used memory'}\\:%3.2lf%%",
259 "GPRINT:usedpct:AVERAGE:$tr{'used memory'}\\:%3.2lf%%",
260 "GPRINT:usedpct:LAST:$tr{'used memory'}\\:%3.2lf%%\\j",
261 "GPRINT:sharedpct:MAX:$tr{'shared memory'}\\:%3.2lf%%",
262 "GPRINT:sharedpct:AVERAGE:$tr{'shared memory'}\\:%3.2lf%%",
263 "GPRINT:sharedpct:LAST:$tr{'shared memory'}\\:%3.2lf%%\\j",
264 "GPRINT:bufferpct:MAX:$tr{'buffered memory'}\\:%3.2lf%%",
265 "GPRINT:bufferpct:AVERAGE:$tr{'buffered memory'}\\:%3.2lf%%",
266 "GPRINT:bufferpct:LAST:$tr{'buffered memory'}\\:%3.2lf%%\\j",
267 "GPRINT:cachepct:MAX:$tr{'cached memory'}\\:%3.2lf%%",
268 "GPRINT:cachepct:AVERAGE:$tr{'cached memory'}\\:%3.2lf%%",
269 "GPRINT:cachepct:LAST:$tr{'cached memory'}\\:%3.2lf%%\\j",
270 "GPRINT:freepct:MAX:$tr{'free memory'}\\:%3.2lf%%",
271 "GPRINT:freepct:AVERAGE:$tr{'free memory'}\\:%3.2lf%%",
272 "GPRINT:freepct:LAST:$tr{'free memory'}\\:%3.2lf%%\\j");
cd1a2927
MT
273 $ERROR = RRDs::error;
274 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
275
276 RRDs::graph ("$graphs/swap-$period.png",
277 "--start", "-1$period", "-aPNG", "-i", "-z",
278 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
4b4aec3a 279 "--color", "SHADEA".$color{"color19"},
44052f4b 280 "--color", "SHADEB".$color{"color19"},
4b4aec3a 281 "--color", "BACK".$color{"color21"},
cd1a2927
MT
282 "-t $tr{'swap usage per'} $tr{$period}",
283 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
284 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
285 "CDEF:total=used,free,+",
286 "CDEF:usedpct=100,used,total,/,*",
287 "CDEF:freepct=100,free,total,/,*",
44052f4b 288 "AREA:usedpct".$color{"color11"}.":$tr{'used swap'}",
4b4aec3a 289 "STACK:freepct".$color{"color12"}.":$tr{'free swap'}\\j",
44052f4b
CS
290 "COMMENT: \\j",
291 "COMMENT:$tr{'maximal'}",
292 "COMMENT:$tr{'average'}",
293 "COMMENT:$tr{'current'}\\j",
294 "GPRINT:usedpct:MAX:$tr{'used swap'}\\:%3.2lf%%",
295 "GPRINT:usedpct:AVERAGE:$tr{'used swap'}\\:%3.2lf%%",
296 "GPRINT:usedpct:LAST:$tr{'used swap'}\\:%3.2lf%%\\j",
297 "GPRINT:freepct:MAX:$tr{'free swap'}\\:%3.2lf%%",
298 "GPRINT:freepct:AVERAGE:$tr{'free swap'}\\:%3.2lf%%",
299 "GPRINT:freepct:LAST:$tr{'free swap'}\\:%3.2lf%%\\j");
cd1a2927
MT
300 $ERROR = RRDs::error;
301 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
302}
303
304sub updatememdata {
4b4aec3a 305 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
cd1a2927
MT
306 if ( ! -e "$rrdlog/mem.rrd") {
307 RRDs::create ("$rrdlog/mem.rrd", "--step=300",
308 "DS:memused:ABSOLUTE:600:0:5000000000",
309 "DS:memfree:ABSOLUTE:600:0:5000000000",
310 "DS:memshared:ABSOLUTE:600:0:5000000000",
311 "DS:membuffers:ABSOLUTE:600:0:5000000000",
312 "DS:memcache:ABSOLUTE:600:0:5000000000",
313 "DS:swapused:ABSOLUTE:600:0:5000000000",
314 "DS:swapfree:ABSOLUTE:600:0:5000000000",
315 "RRA:AVERAGE:0.5:1:576",
316 "RRA:AVERAGE:0.5:6:672",
317 "RRA:AVERAGE:0.5:24:732",
318 "RRA:AVERAGE:0.5:144:1460");
319 $ERROR = RRDs::error;
320 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
321 }
322
323 open MEM, "/proc/meminfo";
324 while(<MEM>) {
325 chomp;
c6aa4ac1 326 if ($_ =~ /^MemTotal:/) {
cd1a2927 327 my @temp = split (/\s+/, $_);
c6aa4ac1
MT
328 $memused = $temp[1];
329 } elsif ($_ =~ /^MemFree:/) {
cd1a2927 330 my @temp = split (/\s+/, $_);
c6aa4ac1
MT
331 $memfree = $temp[1];
332 } elsif ($_ =~ /^Cached:/) {
333 my @temp = split (/\s+/, $_);
334 $memcache = $temp[1];
335 } elsif ($_ =~ /^Buffers:/) {
336 my @temp = split (/\s+/, $_);
337 $membuffers = $temp[1];
338 } elsif ($_ =~ /^SwapTotal:/) {
339 my @temp = split (/\s+/, $_);
4b4aec3a 340 $swaptotal = $temp[1];
c6aa4ac1
MT
341 } elsif ($_ =~ /^SwapFree:/) {
342 my @temp = split (/\s+/, $_);
343 $swapfree = $temp[1];
cd1a2927
MT
344 }
345 }
346 close MEM;
347
c6aa4ac1
MT
348 system("/bin/df > /tmp/diskfree");
349 open DF, "/tmp/diskfree";
350 while(<DF>) {
351 chomp;
352 if ($_ =~ /^shm/) {
353 my @temp = split (/\s+/, $_);
354 $memshared = $temp[2];
355 }
356 }
357 close DF;
358 system("/bin/rm -f /tmp/diskfree");
4b4aec3a
CS
359
360 $swapused = $swaptotal-$swapfree;
cd1a2927
MT
361 RRDs::update ("$rrdlog/mem.rrd",
362 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
363 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
364 $ERROR = RRDs::error;
365 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
366}
367
368sub updatediskgraph {
369 my $period = $_[0];
370
371 RRDs::graph ("$graphs/disk-$period.png",
372 "--start", "-1$period", "-aPNG", "-i", "-z",
373 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
4b4aec3a 374 "--color", "SHADEA".$color{"color19"},
44052f4b 375 "--color", "SHADEB".$color{"color19"},
4b4aec3a 376 "--color", "BACK".$color{"color21"},
cd1a2927
MT
377 "-t $tr{'disk access per'} $tr{$period}",
378 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
379 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
44052f4b 380 "AREA:read".$color{"color11"}.":$tr{'sectors read from disk per second'}",
4b4aec3a 381 "STACK:write".$color{"color12"}.":$tr{'sectors written to disk per second'}\\j",
44052f4b
CS
382 "COMMENT: \\j",
383 "COMMENT:$tr{'maximal'}",
384 "COMMENT:$tr{'average'}",
385 "COMMENT:$tr{'current'}\\j",
386 "GPRINT:read:MAX:$tr{'read sectors'}\\:%8.0lf",
387 "GPRINT:read:AVERAGE:$tr{'read sectors'}\\:%8.0lf",
388 "GPRINT:read:LAST:$tr{'read sectors'}\\:%8.0lf\\j",
389 "GPRINT:write:MAX:$tr{'written sectors'}\\:%8.0lf",
390 "GPRINT:write:AVERAGE:$tr{'written sectors'}\\:%8.0lf",
391 "GPRINT:write:LAST:$tr{'written sectors'}\\:%8.0lf\\j");
cd1a2927
MT
392 $ERROR = RRDs::error;
393 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
394}
395
396sub updatediskdata {
397 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
398 if ( ! -e "$rrdlog/disk.rrd") {
399 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
400 "DS:readsect:COUNTER:600:0:5000000000",
401 "DS:writesect:COUNTER:600:0:5000000000",
402 "RRA:AVERAGE:0.5:1:576",
403 "RRA:AVERAGE:0.5:6:672",
404 "RRA:AVERAGE:0.5:24:732",
405 "RRA:AVERAGE:0.5:144:1460");
406 $ERROR = RRDs::error;
407 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
408 }
409
410 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
411 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
412
413 my $major = $rdev >> 8;
414 my $minor = $rdev & 0xFF;
415
416 open STAT, "/proc/stat";
417 my @diskstat = <STAT>;
418 close (STAT);
419 foreach my $line (@diskstat)
420 {
421 chomp ($line);
422 my @temp = split(/\:\ /,$line);
423 if ($temp[1]) {
424 my @devicestat = split(/\ /,$temp[1]);
425 foreach my $stats (@devicestat)
426 {
427 chomp ($stats);
428 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
429 if ($major eq $fields[1] and $minor eq $fields[2])
430 {
431 $readwritereq = $fields[3];
432 $readreq = $fields[4];
433 $readsect = $fields[5];
434 $writereq = $fields[6];
435 $writesect = $fields[7];
436 }
437 }
438 }
439 }
440
441 if ($readsect && $writesect) {
442 RRDs::update ("$rrdlog/disk.rrd",
443 "-t", "readsect:writesect",
444 "N:$readsect:$writesect");
445 $ERROR = RRDs::error;
446 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
447 } else {
448 print "Error in RRD::update for disk: no data available\n";
449 }
450}
451
6c666a3b
MT
452sub updatediskgraphnew {
453 my $disk = $_[0];
454 my $period = $_[1];
455
456 RRDs::graph ("$graphs/disk-$disk-$period.png",
457 "--start", "-1$period", "-aPNG", "-i", "-z",
458 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
4b4aec3a 459 "--color", "SHADEA".$color{"color19"},
44052f4b 460 "--color", "SHADEB".$color{"color19"},
4b4aec3a 461 "--color", "BACK".$color{"color21"},
6c666a3b
MT
462 "-t $tr{'disk access per'} $tr{$period}",
463 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
464 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
465 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
466 "CDEF:sl_state=sleep,INF,*",
467
468 "AREA:sl_state#a0a0a0:disk standby\\j",
44052f4b 469 "AREA:read".$color{"color11"}.":$tr{'sectors read from disk per second'}",
4b4aec3a 470 "STACK:write".$color{"color12"}.":$tr{'sectors written to disk per second'}\\j",
44052f4b
CS
471 "COMMENT: \\j",
472 "COMMENT:$tr{'maximal'}",
473 "COMMENT:$tr{'average'}",
474 "COMMENT:$tr{'current'}\\j",
475 "GPRINT:read:MAX:$tr{'read sectors'}\\:%8.0lf",
476 "GPRINT:read:AVERAGE:$tr{'read sectors'}\\:%8.0lf",
477 "GPRINT:read:LAST:$tr{'read sectors'}\\:%8.0lf\\j",
478 "GPRINT:write:MAX:$tr{'written sectors'}\\:%8.0lf",
479 "GPRINT:write:AVERAGE:$tr{'written sectors'}\\:%8.0lf",
480 "GPRINT:write:LAST:$tr{'written sectors'}\\:%8.0lf\\j");
6c666a3b
MT
481 $ERROR = RRDs::error;
482 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
483}
484
485sub updatediskdatanew {
486 my $disk = $_[0];
487
488 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
489 if ( ! -e "$rrdlog/disk-$disk.rrd") {
490 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
491 "DS:readsect:COUNTER:600:0:5000000000",
492 "DS:writesect:COUNTER:600:0:5000000000",
493 "DS:sleeping:GAUGE:600:0:1",
494 "RRA:AVERAGE:0.5:1:576",
495 "RRA:AVERAGE:0.5:6:672",
496 "RRA:AVERAGE:0.5:24:732",
497 "RRA:AVERAGE:0.5:144:1460");
498 $ERROR = RRDs::error;
499 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
500 }
501
502 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
503 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
504
c6aa4ac1
MT
505 print "\n\n$dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks\n\n";
506
6c666a3b
MT
507 my $major = $rdev >> 8;
508 my $minor = ($rdev & 0xFF) >>6;
509
510 open STAT, "/proc/stat";
511 my @diskstat = <STAT>;
512 close (STAT);
513 foreach my $line (@diskstat)
514 {
515 chomp ($line);
516 my @temp = split(/\:\ /,$line);
517 if ($temp[1]) {
518 my @devicestat = split(/\ /,$temp[1]);
519 foreach my $stats (@devicestat)
520 {
521 chomp ($stats);
522 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
523 if ($major eq $fields[1] and $minor eq $fields[2])
524 {
525 $readwritereq = $fields[3];
526 $readreq = $fields[4];
527 $readsect = $fields[5];
528 $writereq = $fields[6];
529 $writesect = $fields[7];
530 }
531 }
532 }
533 }
534
535 my $sleeping=0;
536 my $lastsleepstate=0;
537
538 if ( -e "/tmp/hddshutdown-$disk" ) {
539 open STAT,"/tmp/hddshutdown-$disk";
540 $lastsleepstate = <STAT>;
541 close (STAT);
542 if ($lastsleepstate==$readwritereq) {
543 $sleeping=1;
544 }
c6aa4ac1 545 }
6c666a3b
MT
546
547 if ($readsect && $writesect) {
548 RRDs::update ("$rrdlog/disk-$disk.rrd",
549 "-t", "readsect:writesect:sleeping",
550 "N:$readsect:$writesect:$sleeping");
551 $ERROR = RRDs::error;
552 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
553 } else {
554 print "Error in RRD::update for disk-$disk: no data available\n";
555 }
556}
557
cd1a2927
MT
558sub updateifgraph {
559 my $interface = $_[0];
560 my $period = $_[1];
561
562 RRDs::graph ("$graphs/$interface-$period.png",
563 "--start", "-1$period", "-aPNG", "-i", "-z",
564 "--alt-y-grid", "-w 600", "-h 100",
4b4aec3a 565 "--color", "SHADEA".$color{"color19"},
44052f4b 566 "--color", "SHADEB".$color{"color19"},
4b4aec3a 567 "--color", "BACK".$color{"color21"},
cd1a2927
MT
568 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
569 "-v$tr{'bytes per second'}",
570 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
571 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
44052f4b 572 "AREA:incoming".$color{"color11"}.":$tr{'incoming traffic in bytes per second'}",
4b4aec3a 573 "LINE1:outgoing".$color{"color12"}.":$tr{'outgoing traffic in bytes per second'}\\j",
44052f4b
CS
574 "COMMENT: \\j",
575 "COMMENT:$tr{'maximal'}",
576 "COMMENT:$tr{'average'}",
577 "COMMENT:$tr{'current'}\\j",
578 "GPRINT:incoming:MAX:$tr{'in'}\\:%8.3lf %sBps",
579 "GPRINT:incoming:AVERAGE:$tr{'in'}\\:%8.3lf %sBps",
580 "GPRINT:incoming:LAST:$tr{'in'}\\:%8.3lf %sBps\\j",
581 "GPRINT:outgoing:MAX:$tr{'out'}\\:%8.3lf %sBps",
582 "GPRINT:outgoing:AVERAGE:$tr{'out'}\\:%8.3lf %sBps",
583 "GPRINT:outgoing:LAST:$tr{'out'}\\:%8.3lf %sBps\\j");
cd1a2927
MT
584 $ERROR = RRDs::error;
585 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
586}
587
588sub updateifdata {
589 my $interface = $_[0];
590
591 if ( ! -e "$rrdlog/$interface.rrd") {
592 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
593 "DS:incoming:ABSOLUTE:600:0:12500000",
594 "DS:outgoing:ABSOLUTE:600:0:12500000",
595 "RRA:AVERAGE:0.5:1:576",
596 "RRA:AVERAGE:0.5:6:672",
597 "RRA:AVERAGE:0.5:24:732",
598 "RRA:AVERAGE:0.5:144:1460");
599 $ERROR = RRDs::error;
600 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
601 }
602
603 my $traffic = gettraffic ($interface);
604 RRDs::update ("$rrdlog/$interface.rrd",
605 "-t", "incoming:outgoing",
606 "N:$traffic");
607 $ERROR = RRDs::error;
608 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
609}
610
df8c7810
MT
611sub updatefwhitsgraph {
612 my $interval = $_[0];
613
614 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
615 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 616 "--alt-y-grid", "-w 600", "-h 200",
4b4aec3a 617 "--color", "SHADEA".$color{"color19"},
44052f4b 618 "--color", "SHADEB".$color{"color19"},
4b4aec3a 619 "--color", "BACK".$color{"color21"},
df8c7810
MT
620 "-t firewall hits over the last $interval",
621 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
4b4aec3a 622 "AREA:amount".$color{"color24"}.":firewallhits",
c7acba4a
MT
623 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
624 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
625 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810 626 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
4b4aec3a 627 "AREA:portamount".$color{"color25"}.":portscans",
c7acba4a
MT
628 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
629 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
630 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
631 $ERROR = RRDs::error;
632 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
633
634 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
635 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 636 "--alt-y-grid", "-w 600", "-h 200",
4b4aec3a 637 "--color", "SHADEA".$color{"color19"},
44052f4b 638 "--color", "SHADEB".$color{"color19"},
4b4aec3a 639 "--color", "BACK".$color{"color21"},
df8c7810
MT
640 "-t firewall hits over the last $interval",
641 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
4b4aec3a 642 "LINE2:amount".$color{"color24"}.":firewallhits",
c7acba4a
MT
643 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
644 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
894c6feb 645 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810 646 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
4b4aec3a 647 "LINE2:portamount".$color{"color25"}.":portscans",
c7acba4a
MT
648 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
649 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
650 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
651 $ERROR = RRDs::error;
652 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
653}
654
655sub updatefwhitsdata {
656 my $portamount=0;
657 my $alertaktuell=0;
658 my $aktuell=0;
659 my $portaktuell=0;
660 my $skip=0;
661
662 if (! -e "$rrdlog/firewallhits.rrd")
663 {
664 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
665 "DS:amount:GAUGE:600:0:U",
666 "DS:portamount:GAUGE:600:0:U",
667 "RRA:AVERAGE:0.5:1:576",
668 "RRA:AVERAGE:0.5:6:672",
669 "RRA:AVERAGE:0.5:24:732",
670 "RRA:AVERAGE:0.5:144:1460");
671 $ERROR = RRDs::error;
672 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
673 }
674
675 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
676 if (!(open (FILE,'/tmp/messages.fwhits'))) {
677 $skip=1;
678 }
679 $aktuell = 0;
680 if (!$skip) {
681 while (<FILE>) {
682 if (/kernel:.*(IN=.*)$/) {
683 $aktuell++;
684 }
685 }
686 close (FILE);
687 }
688
689 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
690 if (!(open (FILE,'/tmp/snort.fwhits'))) {
691 $skip=1;
692 }
693 $alertaktuell = 0;
694 if (!$skip) {
695 while (<FILE>) {
696 if (/scan.*$/) {
697 $alertaktuell++;
698 }
699 }
700 close (FILE);
701 }
702
703 if (!(open (FILE,'/tmp/messages.fwhits'))) {
704 $skip=1;
705 }
706 $portaktuell = 0;
707 if (!$skip) {
708 while (<FILE>) {
709 if (/kernel:.*(Scan.*)$/) {
710 $portaktuell++;
711 }
712 }
713 close (FILE);
714 }
715
716 system("rm /tmp/messages.fwhits");
717 system("rm /tmp/snort.fwhits");
718
719 $portamount = $portaktuell + $alertaktuell;
720 chomp($portamount);
721 RRDs::update ("$rrdlog/firewallhits.rrd",
722 "N:$aktuell:$portamount");
723 $ERROR = RRDs::error;
724 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
725}
726
072cd997
MT
727# Creates and updates a link quality database
728# -------------------------------------------
729sub updatelq {
730 if ( ! -e "$rrdlog/lq.rrd") {
731 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
732 "DS:loss:GAUGE:600:0:100",
733 "DS:roundtrip:GAUGE:600:0:10000",
734 "RRA:AVERAGE:0.5:1:576",
735 "RRA:AVERAGE:0.5:6:672",
736 "RRA:AVERAGE:0.5:24:732",
737 "RRA:AVERAGE:0.5:144:1460");
738 $ERROR = RRDs::error;
739 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
740 }
741 my $packetloss=0;
742 my $roundtrip=0;
743 my $test=0;
744# LQ_GATEWAY is the ip of your isp's public ip facing you
66801d8b 745 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
072cd997
MT
746 my $NUMPINGS=10;
747 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
748 chomp;
749 my @temp = split (/\/|\%|\s/, $pingoutput);
750 $packetloss = $temp[17];
751 $roundtrip = $temp[28];
752 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
753 $ERROR = RRDs::error;
754 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
755}
756
757sub updatelqgraph {
758 my $period = $_[0];
759 RRDs::graph ("$graphs/lq-$period.png",
760 "--start", "-1$period", "-aPNG", "-i", "-z",
761 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
762 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
763 "--lazy",
4b4aec3a 764 "--color", "SHADEA".$color{"color19"},
44052f4b 765 "--color", "SHADEB".$color{"color19"},
4b4aec3a 766 "--color", "BACK".$color{"color21"},
072cd997
MT
767 "-v ms / pkts (% x10)",
768 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
769 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
770 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
771 "CDEF:loss10=loss,10,*",
772 "CDEF:r0=roundtrip,30,MIN",
773 "CDEF:r1=roundtrip,70,MIN",
774 "CDEF:r2=roundtrip,150,MIN",
775 "CDEF:r3=roundtrip,300,MIN",
4b4aec3a
CS
776 "AREA:roundtrip".$color{"color25"}.":>300 ms",
777 "AREA:r3".$color{"color18"}.":150-300 ms",
778 "AREA:r2".$color{"color14"}.":70-150 ms",
779 "AREA:r1".$color{"color17"}.":30-70 ms",
780 "AREA:r0".$color{"color12"}.":<30 ms",
781 "AREA:loss10".$color{"color13"}.":Packet loss (x10)",
072cd997 782 "LINE1:roundtrip#707070:",
c7acba4a
MT
783 "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
784 "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
785 "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
072cd997
MT
786 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
787 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
788 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
789 );
790 $ERROR = RRDs::error;
791 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
792}
793
60cbd6e7
MT
794sub updatehdddata
795{
9217f236
MT
796 my $disk = $_[0];
797 if ( ! -e "$rrdlog/hddtemp-$disk.rrd")
60cbd6e7
MT
798 {
799 # database did not exist -> create
9217f236 800 RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300",
60cbd6e7
MT
801 "DS:temperature:GAUGE:600:0:100",
802 "RRA:AVERAGE:0.5:1:576",
803 "RRA:AVERAGE:0.5:6:672",
804 "RRA:AVERAGE:0.5:24:732",
805 "RRA:AVERAGE:0.5:144:1460");
806 $ERROR = RRDs::error;
9217f236 807 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
60cbd6e7
MT
808 }
809
52345790
MT
810 $temp = 0;
811 my $hdd_output = '';
812 my $smart_output = '';
60cbd6e7 813
52345790 814 if ( -e "$path_smartctl" )
60cbd6e7 815 {
9217f236 816 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
60cbd6e7 817 }
52345790
MT
818
819 if ( -e "$path_hddtemp" )
60cbd6e7 820 {
9217f236 821 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
52345790
MT
822
823 # I know 4 response possible responses:
824 #
825 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
826 # /dev/harddisk: harddisk type: no sensor
827