]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/makegraphs
3 ############################################################################
5 # This file is part of the IPCop Firewall. #
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. #
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. #
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 #
21 # Copyright (C) 2004-01-19 Mark Wormgoor <mark@wormgoor.com>. #
23 ############################################################################
29 require "/var/ipfire/general-functions.pl";
30 require "${General::swroot}/lang.pl";
32 my (%settings, @ipacsum, $iface, $ERROR);
33 &General
::readhash
("${General::swroot}/ethernet/settings", \
%settings);
34 my %mbmon_settings = ();
35 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
37 # Added for conversion of utf-8 characters
41 # Force language back to English (ugly hack!)
42 # Modified to only force if we are unable to convert charset
44 if ((${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"`;
53 %tr=%Lang::tr
; # use translated version for other languages
57 my $rrdlog = "/var/log/rrd";
58 my $graphs = "/srv/web/ipfire/html/graphs";
59 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
60 my $hdd_device = "/dev/harddisk";
62 my %mbmon_values = ();
69 my $path_smartctl = "/usr/sbin/smartctl";
70 my $path_hddtemp = "/usr/sbin/hddtemp";
73 my %mainsettings = ();
74 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
75 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
77 open(MBMON_OUT
, ">/var/log/mbmon-values");
78 open(FD
, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
82 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
86 $mbmon_values{$key} = $value;
87 print(MBMON_OUT
"$key=$value\n");
93 my $interface = $_[0];
101 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
103 # Forwarded Incoming...
104 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
107 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
109 # Forwarded Outgoing...
110 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
112 return "$bytesin:$bytesout";
116 if ( ! -e
"$rrdlog/cpu.rrd") {
117 RRDs
::create
("$rrdlog/cpu.rrd", "--step=300",
118 "DS:user:COUNTER:600:0:500000000",
119 "DS:system:COUNTER:600:0:500000000",
120 "DS:idle:COUNTER:600:0:500000000",
121 "DS:iowait:COUNTER:600:0:500000000",
122 "DS:irq:COUNTER:600:0:500000000",
123 "RRA:AVERAGE:0.5:1:576",
124 "RRA:AVERAGE:0.5:6:672",
125 "RRA:AVERAGE:0.5:24:732",
126 "RRA:AVERAGE:0.5:144:1460");
127 $ERROR = RRDs
::error
;
128 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
131 my ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq);
133 open STAT
, "/proc/stat";
137 ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/;
145 RRDs
::update
("$rrdlog/cpu.rrd",
146 "-t", "user:system:idle:iowait:irq",
147 "N:$user:$system:$idle:$iowait:$irq");
148 $ERROR = RRDs
::error
;
149 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
154 if ( ! -e
"$rrdlog/load.rrd") {
155 RRDs
::create
("$rrdlog/load.rrd", "--step=60",
156 "DS:load1:GAUGE:120:0:U",
157 "DS:load5:GAUGE:120:0:U",
158 "DS:load15:GAUGE:120:0:U",
159 "RRA:AVERAGE:0.5:1:2160",
160 "RRA:AVERAGE:0.5:5:2016",
161 "RRA:AVERAGE:0.5:15:2880",
162 "RRA:AVERAGE:0.5:60:8760");
164 $ERROR = RRDs
::error
;
165 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
170 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
171 if ( ! -e
"$rrdlog/mem.rrd") {
172 RRDs
::create
("$rrdlog/mem.rrd", "--step=300",
173 "DS:memused:ABSOLUTE:600:0:5000000000",
174 "DS:memfree:ABSOLUTE:600:0:5000000000",
175 "DS:memshared:ABSOLUTE:600:0:5000000000",
176 "DS:membuffers:ABSOLUTE:600:0:5000000000",
177 "DS:memcache:ABSOLUTE:600:0:5000000000",
178 "DS:swapused:ABSOLUTE:600:0:5000000000",
179 "DS:swapfree:ABSOLUTE:600:0:5000000000",
180 "RRA:AVERAGE:0.5:1:576",
181 "RRA:AVERAGE:0.5:6:672",
182 "RRA:AVERAGE:0.5:24:732",
183 "RRA:AVERAGE:0.5:144:1460");
184 $ERROR = RRDs
::error
;
185 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
188 open MEM
, "/proc/meminfo";
191 if ($_ =~ /^MemTotal:/) {
192 my @temp = split (/\s+/, $_);
194 } elsif ($_ =~ /^MemFree:/) {
195 my @temp = split (/\s+/, $_);
197 } elsif ($_ =~ /^Cached:/) {
198 my @temp = split (/\s+/, $_);
199 $memcache = $temp[1];
200 } elsif ($_ =~ /^Buffers:/) {
201 my @temp = split (/\s+/, $_);
202 $membuffers = $temp[1];
203 } elsif ($_ =~ /^SwapTotal:/) {
204 my @temp = split (/\s+/, $_);
205 $swaptotal = $temp[1];
206 } elsif ($_ =~ /^SwapFree:/) {
207 my @temp = split (/\s+/, $_);
208 $swapfree = $temp[1];
213 system("/bin/df > /tmp/diskfree");
214 open DF
, "/tmp/diskfree";
218 my @temp = split (/\s+/, $_);
219 $memshared = $temp[2];
223 system("/bin/rm -f /tmp/diskfree");
225 $swapused = $swaptotal-$swapfree;
226 RRDs
::update
("$rrdlog/mem.rrd",
227 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
228 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
229 $ERROR = RRDs
::error
;
230 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
235 my ($readsect, $writesect, $trash);
236 if ( ! -e
"$rrdlog/disk-$disk.rrd") {
237 RRDs
::create
("$rrdlog/disk-$disk.rrd", "--step=300",
238 "DS:readsect:COUNTER:600:0:5000000000",
239 "DS:writesect:COUNTER:600:0:5000000000",
240 "RRA:AVERAGE:0.5:1:576",
241 "RRA:AVERAGE:0.5:6:672",
242 "RRA:AVERAGE:0.5:24:732",
243 "RRA:AVERAGE:0.5:144:1460");
244 $ERROR = RRDs
::error
;
245 print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR;
248 my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
249 ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
251 print "\nread:".$readsect."write:".$writesect."\n";
253 if ($readsect && $writesect) {
254 RRDs
::update
("$rrdlog/disk-$disk.rrd",
255 "-t", "readsect:writesect",
256 "N:$readsect:$writesect");
257 $ERROR = RRDs
::error
;
258 print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
260 print "Error in RRD::update for disk: $disk no data available\n";
265 my $interface = $_[0];
267 if ( ! -e
"$rrdlog/$interface.rrd") {
268 RRDs
::create
("$rrdlog/$interface.rrd", "--step=300",
269 "DS:incoming:ABSOLUTE:600:0:12500000",
270 "DS:outgoing:ABSOLUTE:600:0:12500000",
271 "RRA:AVERAGE:0.5:1:576",
272 "RRA:AVERAGE:0.5:6:672",
273 "RRA:AVERAGE:0.5:24:732",
274 "RRA:AVERAGE:0.5:144:1460");
275 $ERROR = RRDs
::error
;
276 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
279 my $traffic = gettraffic
($interface);
280 RRDs
::update
("$rrdlog/$interface.rrd",
281 "-t", "incoming:outgoing",
283 $ERROR = RRDs
::error
;
284 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
287 sub updatefwhitsdata
{
294 if (! -e
"$rrdlog/firewallhits.rrd")
296 RRDs
::create
("$rrdlog/firewallhits.rrd", "--step=300",
297 "DS:amount:GAUGE:600:0:U",
298 "DS:portamount:GAUGE:600:0:U",
299 "RRA:AVERAGE:0.5:1:576",
300 "RRA:AVERAGE:0.5:6:672",
301 "RRA:AVERAGE:0.5:24:732",
302 "RRA:AVERAGE:0.5:144:1460");
303 $ERROR = RRDs
::error
;
304 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
307 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
308 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
314 if (/kernel:.*(IN=.*)$/) {
321 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
322 if (!(open (FILE
,'/tmp/snort.fwhits'))) {
335 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
341 if (/kernel:.*(Scan.*)$/) {
348 system("rm /tmp/messages.fwhits");
349 system("rm /tmp/snort.fwhits");
351 $portamount = $portaktuell + $alertaktuell;
353 RRDs
::update
("$rrdlog/firewallhits.rrd",
354 "N:$aktuell:$portamount");
355 $ERROR = RRDs
::error
;
356 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
359 # Creates and updates a link quality database
360 # -------------------------------------------
362 if ( ! -e
"$rrdlog/lq.rrd") {
363 RRDs
::create
("$rrdlog/lq.rrd", "--step=300",
364 "DS:loss:GAUGE:600:0:100",
365 "DS:roundtrip:GAUGE:600:0:10000",
366 "RRA:AVERAGE:0.5:1:576",
367 "RRA:AVERAGE:0.5:6:672",
368 "RRA:AVERAGE:0.5:24:732",
369 "RRA:AVERAGE:0.5:144:1460");
370 $ERROR = RRDs
::error
;
371 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
376 # LQ_GATEWAY is the ip of your isp's public ip facing you
377 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
379 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
381 my @temp = split (/\/|\
%|\s
/, $pingoutput);
382 $packetloss = $temp[17];
383 $roundtrip = $temp[28];
384 RRDs
::update
("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
385 $ERROR = RRDs
::error
;
386 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
392 if ( ! -e
"$rrdlog/hddtemp-$disk.rrd")
394 # database did not exist -> create
395 RRDs
::create
("$rrdlog/hddtemp-$disk.rrd", "--step=300",
396 "DS:temperature:GAUGE:600:0:100",
397 "RRA:AVERAGE:0.5:1:576",
398 "RRA:AVERAGE:0.5:6:672",
399 "RRA:AVERAGE:0.5:24:732",
400 "RRA:AVERAGE:0.5:144:1460");
401 $ERROR = RRDs
::error
;
402 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
407 my $smart_output = '';
409 if ( -e
"$path_smartctl" )
411 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
414 if ( -e
"$path_hddtemp" )
416 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
418 # I know 4 response possible responses:
420 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
421 # /dev/harddisk: harddisk type: no sensor
422 # /dev/harddisk: harddisk type: 37?C or ?F
425 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
429 elsif ( index($hdd_output, "no sensor") != -1 )
433 elsif ( index($hdd_output, "$disk") != -1 )
435 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
440 $hdd_output =~ /(\d+)\s/;
444 elsif ( -e
"/var/log/smartctl_out_hddtemp-$disk" )
446 $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
447 my @t = split(/\s+/,$hdd_output);
455 # print "hdd $hdd_output \n";
456 # print "temp $temp \n";
458 RRDs
::update
("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
460 $ERROR = RRDs
::error
;
461 print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
466 if ( ! -e
"$rrdlog/mbmon.rrd" )
468 # database did not exist -> create
470 @args = ("$rrdlog/mbmon.rrd");
472 push(@args, "--step=300");
473 foreach $key ( sort(keys %mbmon_values) )
475 push(@args, "DS:$key:GAUGE:600:U:U");
477 push(@args, "RRA:AVERAGE:0.5:1:576");
478 push(@args, "RRA:AVERAGE:0.5:6:672");
479 push(@args, "RRA:AVERAGE:0.5:24:732");
480 push(@args, "RRA:AVERAGE:0.5:144:1460");
482 print("create ". join( ", ", @args)) if ( $dbg );
484 RRDs
::create
(@args);
485 $ERROR = RRDs
::error
;
486 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
493 foreach $key ( sort(keys %mbmon_values) )
496 push(@val, $mbmon_values{$key});
499 $template = join(':', @ds);
500 $value = "N:".join(':', @val);
502 print("update template = '$template'\n") if ( $dbg );
503 print("update value = '$value'\n") if ( $dbg );
505 RRDs
::update
("$rrdlog/mbmon.rrd", "-t", $template, $value);
506 $ERROR = RRDs
::error
;
507 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
511 system ('/usr/sbin/fetchipac');
517 if ( -e
"/var/log/squid/access.log") {
518 system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
524 if ((${Lang
::language
} eq 'cs') ||
525 (${Lang
::language
} eq 'hu') ||
526 (${Lang
::language
} eq 'pl') ||
527 (${Lang
::language
} eq 'sk')) {
528 # Czech, Hungarian, Polish and Slovak character set
529 foreach my $key(keys %Lang::tr
) {
530 from_to
($tr{$key}, "utf-8", "iso-8859-2");
532 } elsif (${Lang
::language
} eq 'tr') {
534 foreach my $key(keys %Lang::tr
) {
535 from_to
($tr{$key}, "utf-8", "iso-8859-9");
538 foreach my $key(keys %Lang::tr
) {
539 from_to
($tr{$key}, "utf-8", "iso-8859-1");
550 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
551 print "\nFound following amount of disks:".@disks."\n";
555 print "Working on disk ".$disk.".\n";
556 updatediskdata
($disk);
570 ### HDDTEMP-Graphs for /dev/harddisk
573 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
574 print "\nFound following amount of disks for hddtemp:".@disks."\n";
578 updatehdddata
($disk);
584 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
586 updateifdata
("GREEN");
587 updateifdata
("RED");
588 if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {
589 updateifdata
("ORANGE");
591 if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {
592 updateifdata
("BLUE");