FritzCard-Module installiert.
[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",
200 "AREA:load1#ff0000:1 Minute, letzter\:",
201 "GPRINT:load1:LAST:%5.2lf\n",
202 "AREA:load5#ff9900:5 Minuten, letzter\:",
203 "GPRINT:load5:LAST:%5.2lf\n",
204 "AREA:load15#ffff00:15 Minuten, letzter\:",
205 "GPRINT:load15:LAST:%5.2lf",
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;
319 if ($_ =~ /^Mem:/) {
320 my @temp = split (/\s+/, $_);
321 $memused = $temp[2];
322 $memfree = $temp[3];
323 $memshared = $temp[4];
324 $membuffers = $temp[5];
325 $memcache = $temp[6];
326 } elsif ($_ =~ /^Swap:/) {
327 my @temp = split (/\s+/, $_);
328 $swapused = $temp[2];
329 $swapfree = $temp[3];
330 }
331 }
332 close MEM;
333
334 RRDs::update ("$rrdlog/mem.rrd",
335 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
336 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
337 $ERROR = RRDs::error;
338 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
339}
340
341sub updatediskgraph {
342 my $period = $_[0];
343
344 RRDs::graph ("$graphs/disk-$period.png",
345 "--start", "-1$period", "-aPNG", "-i", "-z",
346 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
347 "--color", "SHADEA#EAE9EE",
348 "--color", "SHADEB#EAE9EE",
39a7cc11 349 "--color", "BACK#FFFFFF",
cd1a2927
MT
350 "-t $tr{'disk access per'} $tr{$period}",
351 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
352 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
353 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
354 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
355 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
356 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
357 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
358 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
359 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
360 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
361 $ERROR = RRDs::error;
362 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
363}
364
365sub updatediskdata {
366 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
367 if ( ! -e "$rrdlog/disk.rrd") {
368 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
369 "DS:readsect:COUNTER:600:0:5000000000",
370 "DS:writesect:COUNTER:600:0:5000000000",
371 "RRA:AVERAGE:0.5:1:576",
372 "RRA:AVERAGE:0.5:6:672",
373 "RRA:AVERAGE:0.5:24:732",
374 "RRA:AVERAGE:0.5:144:1460");
375 $ERROR = RRDs::error;
376 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
377 }
378
379 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
380 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
381
382 my $major = $rdev >> 8;
383 my $minor = $rdev & 0xFF;
384
385 open STAT, "/proc/stat";
386 my @diskstat = <STAT>;
387 close (STAT);
388 foreach my $line (@diskstat)
389 {
390 chomp ($line);
391 my @temp = split(/\:\ /,$line);
392 if ($temp[1]) {
393 my @devicestat = split(/\ /,$temp[1]);
394 foreach my $stats (@devicestat)
395 {
396 chomp ($stats);
397 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
398 if ($major eq $fields[1] and $minor eq $fields[2])
399 {
400 $readwritereq = $fields[3];
401 $readreq = $fields[4];
402 $readsect = $fields[5];
403 $writereq = $fields[6];
404 $writesect = $fields[7];
405 }
406 }
407 }
408 }
409
410 if ($readsect && $writesect) {
411 RRDs::update ("$rrdlog/disk.rrd",
412 "-t", "readsect:writesect",
413 "N:$readsect:$writesect");
414 $ERROR = RRDs::error;
415 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
416 } else {
417 print "Error in RRD::update for disk: no data available\n";
418 }
419}
420
6c666a3b
MT
421sub updatediskgraphnew {
422 my $disk = $_[0];
423 my $period = $_[1];
424
425 RRDs::graph ("$graphs/disk-$disk-$period.png",
426 "--start", "-1$period", "-aPNG", "-i", "-z",
427 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
428 "--color", "SHADEA#EAE9EE",
429 "--color", "SHADEB#EAE9EE",
430 "--color", "BACK#FFFFFF",
431 "-t $tr{'disk access per'} $tr{$period}",
432 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
433 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
434 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
435 "CDEF:sl_state=sleep,INF,*",
436
437 "AREA:sl_state#a0a0a0:disk standby\\j",
438 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
439 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
440
441 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
442 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
443 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
444 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
445 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
446 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
447 $ERROR = RRDs::error;
448 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
449}
450
451sub updatediskdatanew {
452 my $disk = $_[0];
453
454 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
455 if ( ! -e "$rrdlog/disk-$disk.rrd") {
456 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
457 "DS:readsect:COUNTER:600:0:5000000000",
458 "DS:writesect:COUNTER:600:0:5000000000",
459 "DS:sleeping:GAUGE:600:0:1",
460 "RRA:AVERAGE:0.5:1:576",
461 "RRA:AVERAGE:0.5:6:672",
462 "RRA:AVERAGE:0.5:24:732",
463 "RRA:AVERAGE:0.5:144:1460");
464 $ERROR = RRDs::error;
465 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
466 }
467
468 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
469 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
470
471 my $major = $rdev >> 8;
472 my $minor = ($rdev & 0xFF) >>6;
473
474 open STAT, "/proc/stat";
475 my @diskstat = <STAT>;
476 close (STAT);
477 foreach my $line (@diskstat)
478 {
479 chomp ($line);
480 my @temp = split(/\:\ /,$line);
481 if ($temp[1]) {
482 my @devicestat = split(/\ /,$temp[1]);
483 foreach my $stats (@devicestat)
484 {
485 chomp ($stats);
486 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
487 if ($major eq $fields[1] and $minor eq $fields[2])
488 {
489 $readwritereq = $fields[3];
490 $readreq = $fields[4];
491 $readsect = $fields[5];
492 $writereq = $fields[6];
493 $writesect = $fields[7];
494 }
495 }
496 }
497 }
498
499 my $sleeping=0;
500 my $lastsleepstate=0;
501
502 if ( -e "/tmp/hddshutdown-$disk" ) {
503 open STAT,"/tmp/hddshutdown-$disk";
504 $lastsleepstate = <STAT>;
505 close (STAT);
506 if ($lastsleepstate==$readwritereq) {
507 $sleeping=1;
508 }
509 }
510
511 if ($readsect && $writesect) {
512 RRDs::update ("$rrdlog/disk-$disk.rrd",
513 "-t", "readsect:writesect:sleeping",
514 "N:$readsect:$writesect:$sleeping");
515 $ERROR = RRDs::error;
516 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
517 } else {
518 print "Error in RRD::update for disk-$disk: no data available\n";
519 }
520}
521
cd1a2927
MT
522sub updateifgraph {
523 my $interface = $_[0];
524 my $period = $_[1];
525
526 RRDs::graph ("$graphs/$interface-$period.png",
527 "--start", "-1$period", "-aPNG", "-i", "-z",
528 "--alt-y-grid", "-w 600", "-h 100",
529 "--color", "SHADEA#EAE9EE",
530 "--color", "SHADEB#EAE9EE",
39a7cc11 531 "--color", "BACK#FFFFFF",
cd1a2927
MT
532 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
533 "-v$tr{'bytes per second'}",
534 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
535 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
536 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
537 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
538 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
539 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
540 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
541 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
542 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
543 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
544 $ERROR = RRDs::error;
545 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
546}
547
548sub updateifdata {
549 my $interface = $_[0];
550
551 if ( ! -e "$rrdlog/$interface.rrd") {
552 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
553 "DS:incoming:ABSOLUTE:600:0:12500000",
554 "DS:outgoing:ABSOLUTE:600:0:12500000",
555 "RRA:AVERAGE:0.5:1:576",
556 "RRA:AVERAGE:0.5:6:672",
557 "RRA:AVERAGE:0.5:24:732",
558 "RRA:AVERAGE:0.5:144:1460");
559 $ERROR = RRDs::error;
560 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
561 }
562
563 my $traffic = gettraffic ($interface);
564 RRDs::update ("$rrdlog/$interface.rrd",
565 "-t", "incoming:outgoing",
566 "N:$traffic");
567 $ERROR = RRDs::error;
568 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
569}
570
df8c7810
MT
571sub updatefwhitsgraph {
572 my $interval = $_[0];
573
574 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
575 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 576 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
577 "--color", "SHADEA#EAE9EE",
578 "--color", "SHADEB#EAE9EE",
39a7cc11 579 "--color", "BACK#FFFFFF",
df8c7810
MT
580 "-t firewall hits over the last $interval",
581 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
582 "AREA:amount#6464FF:firewallhits",
c7acba4a
MT
583 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
584 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
585 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
586 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
587 "AREA:portamount#FF6464:portscans",
c7acba4a
MT
588 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
589 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
590 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
591 $ERROR = RRDs::error;
592 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
593
594 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
595 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 596 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
597 "--color", "SHADEA#EAE9EE",
598 "--color", "SHADEB#EAE9EE",
39a7cc11 599 "--color", "BACK#FFFFFF",
df8c7810
MT
600 "-t firewall hits over the last $interval",
601 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
602 "LINE2:amount#6464FF:firewallhits",
c7acba4a
MT
603 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
604 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
894c6feb 605 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
606 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
607 "LINE2:portamount#FF6464:portscans",
c7acba4a
MT
608 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
609 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
610 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
611 $ERROR = RRDs::error;
612 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
613}
614
615sub updatefwhitsdata {
616 my $portamount=0;
617 my $alertaktuell=0;
618 my $aktuell=0;
619 my $portaktuell=0;
620 my $skip=0;
621
622 if (! -e "$rrdlog/firewallhits.rrd")
623 {
624 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
625 "DS:amount:GAUGE:600:0:U",
626 "DS:portamount:GAUGE:600:0:U",
627 "RRA:AVERAGE:0.5:1:576",
628 "RRA:AVERAGE:0.5:6:672",
629 "RRA:AVERAGE:0.5:24:732",
630 "RRA:AVERAGE:0.5:144:1460");
631 $ERROR = RRDs::error;
632 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
633 }
634
635 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
636 if (!(open (FILE,'/tmp/messages.fwhits'))) {
637 $skip=1;
638 }
639 $aktuell = 0;
640 if (!$skip) {
641 while (<FILE>) {
642 if (/kernel:.*(IN=.*)$/) {
643 $aktuell++;
644 }
645 }
646 close (FILE);
647 }
648
649 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
650 if (!(open (FILE,'/tmp/snort.fwhits'))) {
651 $skip=1;
652 }
653 $alertaktuell = 0;
654 if (!$skip) {
655 while (<FILE>) {
656 if (/scan.*$/) {
657 $alertaktuell++;
658 }
659 }
660 close (FILE);
661 }
662
663 if (!(open (FILE,'/tmp/messages.fwhits'))) {
664 $skip=1;
665 }
666 $portaktuell = 0;
667 if (!$skip) {
668 while (<FILE>) {
669 if (/kernel:.*(Scan.*)$/) {
670 $portaktuell++;
671 }
672 }
673 close (FILE);
674 }
675
676 system("rm /tmp/messages.fwhits");
677 system("rm /tmp/snort.fwhits");
678
679 $portamount = $portaktuell + $alertaktuell;
680 chomp($portamount);
681 RRDs::update ("$rrdlog/firewallhits.rrd",
682 "N:$aktuell:$portamount");
683 $ERROR = RRDs::error;
684 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
685}
686
072cd997
MT
687# Creates and updates a link quality database
688# -------------------------------------------
689sub updatelq {
690 if ( ! -e "$rrdlog/lq.rrd") {
691 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
692 "DS:loss:GAUGE:600:0:100",
693 "DS:roundtrip:GAUGE:600:0:10000",
694 "RRA:AVERAGE:0.5:1:576",
695 "RRA:AVERAGE:0.5:6:672",
696 "RRA:AVERAGE:0.5:24:732",
697 "RRA:AVERAGE:0.5:144:1460");
698 $ERROR = RRDs::error;
699 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
700 }
701 my $packetloss=0;
702 my $roundtrip=0;
703 my $test=0;
704# LQ_GATEWAY is the ip of your isp's public ip facing you
66801d8b 705 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
072cd997
MT
706 my $NUMPINGS=10;
707 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
708 chomp;
709 my @temp = split (/\/|\%|\s/, $pingoutput);
710 $packetloss = $temp[17];
711 $roundtrip = $temp[28];
712 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
713 $ERROR = RRDs::error;
714 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
715}
716
717sub updatelqgraph {
718 my $period = $_[0];
719 RRDs::graph ("$graphs/lq-$period.png",
720 "--start", "-1$period", "-aPNG", "-i", "-z",
721 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
722 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
723 "--lazy",
724 "--color", "SHADEA#EAE9EE",
725 "--color", "SHADEB#EAE9EE",
39a7cc11 726 "--color", "BACK#FFFFFF",
072cd997
MT
727 "-v ms / pkts (% x10)",
728 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
729 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
730 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
731 "CDEF:loss10=loss,10,*",
732 "CDEF:r0=roundtrip,30,MIN",
733 "CDEF:r1=roundtrip,70,MIN",
734 "CDEF:r2=roundtrip,150,MIN",
735 "CDEF:r3=roundtrip,300,MIN",
736 "AREA:roundtrip#EE7000:>300 ms",
737 "AREA:r3#D88E1B:150-300 ms",
738 "AREA:r2#B9B63F:70-150 ms",
739 "AREA:r1#99E064:30-70 ms",
740 "AREA:r0#80FF80:<30 ms",
741 "AREA:loss10#800000:Packet loss (x10)",
742 "LINE1:roundtrip#707070:",
c7acba4a
MT
743 "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
744 "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
745 "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
072cd997
MT
746 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
747 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
748 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
749 );
750 $ERROR = RRDs::error;
751 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
752}
753
60cbd6e7
MT
754sub updatehdddata
755{
e3a8510a 756 if ( ! -e "$rrdlog/hddtemp.rrd")
60cbd6e7
MT
757 {
758 # database did not exist -> create
e3a8510a 759 RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
60cbd6e7
MT
760 "DS:temperature:GAUGE:600:0:100",
761 "RRA:AVERAGE:0.5:1:576",
762 "RRA:AVERAGE:0.5:6:672",
763 "RRA:AVERAGE:0.5:24:732",
764 "RRA:AVERAGE:0.5:144:1460");
765 $ERROR = RRDs::error;
766 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
767 }
768
52345790
MT
769 $temp = 0;
770 my $hdd_output = '';
771 my $smart_output = '';
60cbd6e7 772
52345790 773 if ( -e "$path_smartctl" )
60cbd6e7 774 {
52345790 775 system("$path_smartctl -iHA $hdd_device > /var/log/hddgraph_smartctl_out");
60cbd6e7 776 }
52345790
MT
777
778 if ( -e "$path_hddtemp" )
60cbd6e7 779 {
52345790
MT
780 $hdd_output = `$path_hddtemp -qn $hdd_device`;
781
782 # I know 4 response possible responses:
783 #
784 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
785 # /dev/harddisk: harddisk type: no sensor
786