]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Hinzugefuegt:
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
CommitLineData
cd1a2927
MT
1#!/usr/bin/perl
2
3############################################################################
4# #
5# This file is part of the IPCop Firewall. #
6# #
7# IPCop is free software; you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation; either version 2 of the License, or #
10# (at your option) any later version. #
11# #
12# IPCop is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with IPCop; if not, write to the Free Software #
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
20# #
21# Copyright (C) 2004-01-19 Mark Wormgoor <mark@wormgoor.com>. #
22# #
23############################################################################
60cbd6e7 24
cd1a2927
MT
25use strict;
26#use warnings;
27
28use RRDs;
986e08d9 29require "/var/ipfire/general-functions.pl";
cd1a2927
MT
30require "${General::swroot}/lang.pl";
31
32my (%settings, @ipacsum, $iface, $ERROR);
33&General::readhash("${General::swroot}/ethernet/settings", \%settings);
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";
58my $graphs = "/home/httpd/html/graphs";
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
187sub updatememgraph {
188 my $period = $_[0];
189
190 RRDs::graph ("$graphs/memory-$period.png",
191 "--start", "-1$period", "-aPNG", "-i", "-z",
192 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
193 "--color", "SHADEA#EAE9EE",
194 "--color", "SHADEB#EAE9EE",
39a7cc11 195 "--color", "BACK#FFFFFF",
cd1a2927
MT
196 "-t $tr{'memory usage per'} $tr{$period}",
197 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
198 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
199 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
200 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
201 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
202 "CDEF:total=used,free,+",
203 "CDEF:used2=used,buffer,cache,shared,+,+,-",
204 "CDEF:usedpct=100,used2,total,/,*",
205 "CDEF:sharedpct=100,shared,total,/,*",
206 "CDEF:bufferpct=100,buffer,total,/,*",
207 "CDEF:cachepct=100,cache,total,/,*",
208 "CDEF:freepct=100,free,total,/,*",
209 "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
210 "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
211 "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
212 "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
213 "STACK:freepct#00FF00:$tr{'free memory'}\\j",
214 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
215 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
216 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
217 "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
218 "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
219 "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
220 "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
221 "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
222 "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
223 "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
224 "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
225 "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
226 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
227 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
228 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
229 $ERROR = RRDs::error;
230 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
231
232 RRDs::graph ("$graphs/swap-$period.png",
233 "--start", "-1$period", "-aPNG", "-i", "-z",
234 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
235 "--color", "SHADEA#EAE9EE",
236 "--color", "SHADEB#EAE9EE",
39a7cc11 237 "--color", "BACK#FFFFFF",
cd1a2927
MT
238 "-t $tr{'swap usage per'} $tr{$period}",
239 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
240 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
241 "CDEF:total=used,free,+",
242 "CDEF:usedpct=100,used,total,/,*",
243 "CDEF:freepct=100,free,total,/,*",
244 "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
245 "STACK:freepct#00FF00:$tr{'free swap'}\\j",
246 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
247 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
248 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
249 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
250 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
251 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
252 $ERROR = RRDs::error;
253 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
254}
255
256sub updatememdata {
257 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
258 if ( ! -e "$rrdlog/mem.rrd") {
259 RRDs::create ("$rrdlog/mem.rrd", "--step=300",
260 "DS:memused:ABSOLUTE:600:0:5000000000",
261 "DS:memfree:ABSOLUTE:600:0:5000000000",
262 "DS:memshared:ABSOLUTE:600:0:5000000000",
263 "DS:membuffers:ABSOLUTE:600:0:5000000000",
264 "DS:memcache:ABSOLUTE:600:0:5000000000",
265 "DS:swapused:ABSOLUTE:600:0:5000000000",
266 "DS:swapfree:ABSOLUTE:600:0:5000000000",
267 "RRA:AVERAGE:0.5:1:576",
268 "RRA:AVERAGE:0.5:6:672",
269 "RRA:AVERAGE:0.5:24:732",
270 "RRA:AVERAGE:0.5:144:1460");
271 $ERROR = RRDs::error;
272 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
273 }
274
275 open MEM, "/proc/meminfo";
276 while(<MEM>) {
277 chomp;
278 if ($_ =~ /^Mem:/) {
279 my @temp = split (/\s+/, $_);
280 $memused = $temp[2];
281 $memfree = $temp[3];
282 $memshared = $temp[4];
283 $membuffers = $temp[5];
284 $memcache = $temp[6];
285 } elsif ($_ =~ /^Swap:/) {
286 my @temp = split (/\s+/, $_);
287 $swapused = $temp[2];
288 $swapfree = $temp[3];
289 }
290 }
291 close MEM;
292
293 RRDs::update ("$rrdlog/mem.rrd",
294 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
295 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
296 $ERROR = RRDs::error;
297 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
298}
299
300sub updatediskgraph {
301 my $period = $_[0];
302
303 RRDs::graph ("$graphs/disk-$period.png",
304 "--start", "-1$period", "-aPNG", "-i", "-z",
305 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
306 "--color", "SHADEA#EAE9EE",
307 "--color", "SHADEB#EAE9EE",
39a7cc11 308 "--color", "BACK#FFFFFF",
cd1a2927
MT
309 "-t $tr{'disk access per'} $tr{$period}",
310 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
311 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
312 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
313 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
314 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
315 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
316 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
317 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
318 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
319 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
320 $ERROR = RRDs::error;
321 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
322}
323
324sub updatediskdata {
325 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
326 if ( ! -e "$rrdlog/disk.rrd") {
327 RRDs::create ("$rrdlog/disk.rrd", "--step=300",
328 "DS:readsect:COUNTER:600:0:5000000000",
329 "DS:writesect:COUNTER:600:0:5000000000",
330 "RRA:AVERAGE:0.5:1:576",
331 "RRA:AVERAGE:0.5:6:672",
332 "RRA:AVERAGE:0.5:24:732",
333 "RRA:AVERAGE:0.5:144:1460");
334 $ERROR = RRDs::error;
335 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
336 }
337
338 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
339 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
340
341 my $major = $rdev >> 8;
342 my $minor = $rdev & 0xFF;
343
344 open STAT, "/proc/stat";
345 my @diskstat = <STAT>;
346 close (STAT);
347 foreach my $line (@diskstat)
348 {
349 chomp ($line);
350 my @temp = split(/\:\ /,$line);
351 if ($temp[1]) {
352 my @devicestat = split(/\ /,$temp[1]);
353 foreach my $stats (@devicestat)
354 {
355 chomp ($stats);
356 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
357 if ($major eq $fields[1] and $minor eq $fields[2])
358 {
359 $readwritereq = $fields[3];
360 $readreq = $fields[4];
361 $readsect = $fields[5];
362 $writereq = $fields[6];
363 $writesect = $fields[7];
364 }
365 }
366 }
367 }
368
369 if ($readsect && $writesect) {
370 RRDs::update ("$rrdlog/disk.rrd",
371 "-t", "readsect:writesect",
372 "N:$readsect:$writesect");
373 $ERROR = RRDs::error;
374 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
375 } else {
376 print "Error in RRD::update for disk: no data available\n";
377 }
378}
379
6c666a3b
MT
380sub updatediskgraphnew {
381 my $disk = $_[0];
382 my $period = $_[1];
383
384 RRDs::graph ("$graphs/disk-$disk-$period.png",
385 "--start", "-1$period", "-aPNG", "-i", "-z",
386 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
387 "--color", "SHADEA#EAE9EE",
388 "--color", "SHADEB#EAE9EE",
389 "--color", "BACK#FFFFFF",
390 "-t $tr{'disk access per'} $tr{$period}",
391 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
392 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
393 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
394 "CDEF:sl_state=sleep,INF,*",
395
396 "AREA:sl_state#a0a0a0:disk standby\\j",
397 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
398 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
399
400 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
401 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
402 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
403 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
404 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
405 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
406 $ERROR = RRDs::error;
407 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
408}
409
410sub updatediskdatanew {
411 my $disk = $_[0];
412
413 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
414 if ( ! -e "$rrdlog/disk-$disk.rrd") {
415 RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
416 "DS:readsect:COUNTER:600:0:5000000000",
417 "DS:writesect:COUNTER:600:0:5000000000",
418 "DS:sleeping:GAUGE:600:0:1",
419 "RRA:AVERAGE:0.5:1:576",
420 "RRA:AVERAGE:0.5:6:672",
421 "RRA:AVERAGE:0.5:24:732",
422 "RRA:AVERAGE:0.5:144:1460");
423 $ERROR = RRDs::error;
424 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
425 }
426
427 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
428 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
429
430 my $major = $rdev >> 8;
431 my $minor = ($rdev & 0xFF) >>6;
432
433 open STAT, "/proc/stat";
434 my @diskstat = <STAT>;
435 close (STAT);
436 foreach my $line (@diskstat)
437 {
438 chomp ($line);
439 my @temp = split(/\:\ /,$line);
440 if ($temp[1]) {
441 my @devicestat = split(/\ /,$temp[1]);
442 foreach my $stats (@devicestat)
443 {
444 chomp ($stats);
445 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
446 if ($major eq $fields[1] and $minor eq $fields[2])
447 {
448 $readwritereq = $fields[3];
449 $readreq = $fields[4];
450 $readsect = $fields[5];
451 $writereq = $fields[6];
452 $writesect = $fields[7];
453 }
454 }
455 }
456 }
457
458 my $sleeping=0;
459 my $lastsleepstate=0;
460
461 if ( -e "/tmp/hddshutdown-$disk" ) {
462 open STAT,"/tmp/hddshutdown-$disk";
463 $lastsleepstate = <STAT>;
464 close (STAT);
465 if ($lastsleepstate==$readwritereq) {
466 $sleeping=1;
467 }
468 }
469
470 if ($readsect && $writesect) {
471 RRDs::update ("$rrdlog/disk-$disk.rrd",
472 "-t", "readsect:writesect:sleeping",
473 "N:$readsect:$writesect:$sleeping");
474 $ERROR = RRDs::error;
475 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
476 } else {
477 print "Error in RRD::update for disk-$disk: no data available\n";
478 }
479}
480
cd1a2927
MT
481sub updateifgraph {
482 my $interface = $_[0];
483 my $period = $_[1];
484
485 RRDs::graph ("$graphs/$interface-$period.png",
486 "--start", "-1$period", "-aPNG", "-i", "-z",
487 "--alt-y-grid", "-w 600", "-h 100",
488 "--color", "SHADEA#EAE9EE",
489 "--color", "SHADEB#EAE9EE",
39a7cc11 490 "--color", "BACK#FFFFFF",
cd1a2927
MT
491 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
492 "-v$tr{'bytes per second'}",
493 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
494 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
495 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
496 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
497 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
498 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
499 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
500 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
501 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
502 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
503 $ERROR = RRDs::error;
504 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
505}
506
507sub updateifdata {
508 my $interface = $_[0];
509
510 if ( ! -e "$rrdlog/$interface.rrd") {
511 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
512 "DS:incoming:ABSOLUTE:600:0:12500000",
513 "DS:outgoing:ABSOLUTE:600:0:12500000",
514 "RRA:AVERAGE:0.5:1:576",
515 "RRA:AVERAGE:0.5:6:672",
516 "RRA:AVERAGE:0.5:24:732",
517 "RRA:AVERAGE:0.5:144:1460");
518 $ERROR = RRDs::error;
519 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
520 }
521
522 my $traffic = gettraffic ($interface);
523 RRDs::update ("$rrdlog/$interface.rrd",
524 "-t", "incoming:outgoing",
525 "N:$traffic");
526 $ERROR = RRDs::error;
527 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
528}
529
df8c7810
MT
530sub updatefwhitsgraph {
531 my $interval = $_[0];
532
533 RRDs::graph ("$graphs/firewallhits-$interval-area.png",
534 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 535 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
536 "--color", "SHADEA#EAE9EE",
537 "--color", "SHADEB#EAE9EE",
39a7cc11 538 "--color", "BACK#FFFFFF",
df8c7810
MT
539 "-t firewall hits over the last $interval",
540 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
541 "AREA:amount#6464FF:firewallhits",
c7acba4a
MT
542 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
543 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
544 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
545 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
546 "AREA:portamount#FF6464:portscans",
c7acba4a
MT
547 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
548 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
549 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
550 $ERROR = RRDs::error;
551 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
552
553 RRDs::graph ("$graphs/firewallhits-$interval-line.png",
554 "--start", "-1$interval", "-aPNG", "-i", "-z",
072cd997 555 "--alt-y-grid", "-w 600", "-h 200",
df8c7810
MT
556 "--color", "SHADEA#EAE9EE",
557 "--color", "SHADEB#EAE9EE",
39a7cc11 558 "--color", "BACK#FFFFFF",
df8c7810
MT
559 "-t firewall hits over the last $interval",
560 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
561 "LINE2:amount#6464FF:firewallhits",
c7acba4a
MT
562 "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
563 "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
894c6feb 564 "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
df8c7810
MT
565 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
566 "LINE2:portamount#FF6464:portscans",
c7acba4a
MT
567 "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
568 "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
569 "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
df8c7810
MT
570 $ERROR = RRDs::error;
571 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
572}
573
574sub updatefwhitsdata {
575 my $portamount=0;
576 my $alertaktuell=0;
577 my $aktuell=0;
578 my $portaktuell=0;
579 my $skip=0;
580
581 if (! -e "$rrdlog/firewallhits.rrd")
582 {
583 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
584 "DS:amount:GAUGE:600:0:U",
585 "DS:portamount:GAUGE:600:0:U",
586 "RRA:AVERAGE:0.5:1:576",
587 "RRA:AVERAGE:0.5:6:672",
588 "RRA:AVERAGE:0.5:24:732",
589 "RRA:AVERAGE:0.5:144:1460");
590 $ERROR = RRDs::error;
591 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
592 }
593
594 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
595 if (!(open (FILE,'/tmp/messages.fwhits'))) {
596 $skip=1;
597 }
598 $aktuell = 0;
599 if (!$skip) {
600 while (<FILE>) {
601 if (/kernel:.*(IN=.*)$/) {
602 $aktuell++;
603 }
604 }
605 close (FILE);
606 }
607
608 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
609 if (!(open (FILE,'/tmp/snort.fwhits'))) {
610 $skip=1;
611 }
612 $alertaktuell = 0;
613 if (!$skip) {
614 while (<FILE>) {
615 if (/scan.*$/) {
616 $alertaktuell++;
617 }
618 }
619 close (FILE);
620 }
621
622 if (!(open (FILE,'/tmp/messages.fwhits'))) {
623 $skip=1;
624 }
625 $portaktuell = 0;
626 if (!$skip) {
627 while (<FILE>) {
628 if (/kernel:.*(Scan.*)$/) {
629 $portaktuell++;
630 }
631 }
632 close (FILE);
633 }
634
635 system("rm /tmp/messages.fwhits");
636 system("rm /tmp/snort.fwhits");
637
638 $portamount = $portaktuell + $alertaktuell;
639 chomp($portamount);
640 RRDs::update ("$rrdlog/firewallhits.rrd",
641 "N:$aktuell:$portamount");
642 $ERROR = RRDs::error;
643 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
644}
645
072cd997
MT
646# Creates and updates a link quality database
647# -------------------------------------------
648sub updatelq {
649 if ( ! -e "$rrdlog/lq.rrd") {
650 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
651 "DS:loss:GAUGE:600:0:100",
652 "DS:roundtrip:GAUGE:600:0:10000",
653 "RRA:AVERAGE:0.5:1:576",
654 "RRA:AVERAGE:0.5:6:672",
655 "RRA:AVERAGE:0.5:24:732",
656 "RRA:AVERAGE:0.5:144:1460");
657 $ERROR = RRDs::error;
658 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
659 }
660 my $packetloss=0;
661 my $roundtrip=0;
662 my $test=0;
663# LQ_GATEWAY is the ip of your isp's public ip facing you
986e08d9 664 my $LQ_GATEWAY='www.heise.de';
072cd997
MT
665 my $NUMPINGS=10;
666 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
667 chomp;
668 my @temp = split (/\/|\%|\s/, $pingoutput);
669 $packetloss = $temp[17];
670 $roundtrip = $temp[28];
671 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
672 $ERROR = RRDs::error;
673 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
674}
675
676sub updatelqgraph {
677 my $period = $_[0];
678 RRDs::graph ("$graphs/lq-$period.png",
679 "--start", "-1$period", "-aPNG", "-i", "-z",
680 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
681 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
682 "--lazy",
683 "--color", "SHADEA#EAE9EE",
684 "--color", "SHADEB#EAE9EE",
39a7cc11 685 "--color", "BACK#FFFFFF",
072cd997
MT
686 "-v ms / pkts (% x10)",
687 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
688 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
689 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
690 "CDEF:loss10=loss,10,*",
691 "CDEF:r0=roundtrip,30,MIN",
692 "CDEF:r1=roundtrip,70,MIN",
693 "CDEF:r2=roundtrip,150,MIN",
694 "CDEF:r3=roundtrip,300,MIN",
695 "AREA:roundtrip#EE7000:>300 ms",
696 "AREA:r3#D88E1B:150-300 ms",
697 "AREA:r2#B9B63F:70-150 ms",
698 "AREA:r1#99E064:30-70 ms",
699 "AREA:r0#80FF80:<30 ms",
700 "AREA:loss10#800000:Packet loss (x10)",
701 "LINE1:roundtrip#707070:",
c7acba4a
MT
702 "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
703 "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
704 "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
072cd997
MT
705 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
706 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
707 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
708 );
709 $ERROR = RRDs::error;
710 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
711}
712
60cbd6e7
MT
713sub updatehdddata
714{
e3a8510a 715 if ( ! -e "$rrdlog/hddtemp.rrd")
60cbd6e7
MT
716 {
717 # database did not exist -> create
e3a8510a 718 RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
60cbd6e7
MT
719 "DS:temperature:GAUGE:600:0:100",
720 "RRA:AVERAGE:0.5:1:576",
721 "RRA:AVERAGE:0.5:6:672",
722 "RRA:AVERAGE:0.5:24:732",
723 "RRA:AVERAGE:0.5:144:1460");
724 $ERROR = RRDs::error;
725 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
726 }
727
52345790
MT
728 $temp = 0;
729 my $hdd_output = '';
730 my $smart_output = '';
60cbd6e7 731
52345790 732 if ( -e "$path_smartctl" )
60cbd6e7 733 {
52345790 734 system("$path_smartctl -iHA $hdd_device > /var/log/hddgraph_smartctl_out");
60cbd6e7 735 }
52345790
MT
736
737 if ( -e "$path_hddtemp" )
60cbd6e7 738 {
52345790
MT
739 $hdd_output = `$path_hddtemp -qn $hdd_device`;
740
741 # I know 4 response possible responses:
742 #
743 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
744 # /dev/harddisk: harddisk type: no sensor
745