]>
git.ipfire.org Git - people/pmueller/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 system("chmod 777 /srv/web/ipfire/html/graphs");
43 # Force language back to English (ugly hack!)
44 # Modified to only force if we are unable to convert charset
46 if ((${Lang
::language
} eq 'el') ||
47 (${Lang
::language
} eq 'fa') ||
48 (${Lang
::language
} eq 'ru') ||
49 (${Lang
::language
} eq 'th') ||
50 (${Lang
::language
} eq 'vi') ||
51 (${Lang
::language
} eq 'zh') ||
52 (${Lang
::language
} eq 'zt')) {
53 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
55 %tr=%Lang::tr
; # use translated version for other languages
59 my $rrdlog = "/var/log/rrd";
60 my $graphs = "/srv/web/ipfire/html/graphs";
61 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
62 my $hdd_device = "/dev/harddisk";
64 my %mbmon_values = ();
71 my $path_smartctl = "/usr/sbin/smartctl";
72 my $path_hddtemp = "/usr/sbin/hddtemp";
75 my %mainsettings = ();
76 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
77 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
79 open(MBMON_OUT
, ">/var/log/mbmon-values");
80 open(FD
, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
84 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
88 $mbmon_values{$key} = $value;
89 print(MBMON_OUT
"$key=$value\n");
95 my $interface = $_[0];
103 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
105 # Forwarded Incoming...
106 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
109 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
111 # Forwarded Outgoing...
112 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
114 return "$bytesin:$bytesout";
118 if ( ! -e
"$rrdlog/cpu.rrd") {
119 RRDs
::create
("$rrdlog/cpu.rrd", "--step=300",
120 "DS:user:COUNTER:600:0:500000000",
121 "DS:system:COUNTER:600:0:500000000",
122 "DS:idle:COUNTER:600:0:500000000",
123 "DS:iowait:COUNTER:600:0:500000000",
124 "DS:irq:COUNTER:600:0:500000000",
125 "RRA:AVERAGE:0.5:1:576",
126 "RRA:AVERAGE:0.5:6:672",
127 "RRA:AVERAGE:0.5:24:732",
128 "RRA:AVERAGE:0.5:144:1460");
129 $ERROR = RRDs
::error
;
130 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
133 my ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq);
135 open STAT
, "/proc/stat";
139 ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/;
147 RRDs
::update
("$rrdlog/cpu.rrd",
148 "-t", "user:system:idle:iowait:irq",
149 "N:$user:$system:$idle:$iowait:$irq");
150 $ERROR = RRDs
::error
;
151 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
156 if ( ! -e
"$rrdlog/load.rrd") {
157 RRDs
::create
("$rrdlog/load.rrd", "--step=60",
158 "DS:load1:GAUGE:120:0:U",
159 "DS:load5:GAUGE:120:0:U",
160 "DS:load15:GAUGE:120:0:U",
161 "RRA:AVERAGE:0.5:1:2160",
162 "RRA:AVERAGE:0.5:5:2016",
163 "RRA:AVERAGE:0.5:15:2880",
164 "RRA:AVERAGE:0.5:60:8760");
166 $ERROR = RRDs
::error
;
167 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
172 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
173 if ( ! -e
"$rrdlog/mem.rrd") {
174 RRDs
::create
("$rrdlog/mem.rrd", "--step=300",
175 "DS:memused:ABSOLUTE:600:0:5000000000",
176 "DS:memfree:ABSOLUTE:600:0:5000000000",
177 "DS:memshared:ABSOLUTE:600:0:5000000000",
178 "DS:membuffers:ABSOLUTE:600:0:5000000000",
179 "DS:memcache:ABSOLUTE:600:0:5000000000",
180 "DS:swapused:ABSOLUTE:600:0:5000000000",
181 "DS:swapfree:ABSOLUTE:600:0:5000000000",
182 "RRA:AVERAGE:0.5:1:576",
183 "RRA:AVERAGE:0.5:6:672",
184 "RRA:AVERAGE:0.5:24:732",
185 "RRA:AVERAGE:0.5:144:1460");
186 $ERROR = RRDs
::error
;
187 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
190 open MEM
, "/proc/meminfo";
193 if ($_ =~ /^MemTotal:/) {
194 my @temp = split (/\s+/, $_);
196 } elsif ($_ =~ /^MemFree:/) {
197 my @temp = split (/\s+/, $_);
199 } elsif ($_ =~ /^Cached:/) {
200 my @temp = split (/\s+/, $_);
201 $memcache = $temp[1];
202 } elsif ($_ =~ /^Buffers:/) {
203 my @temp = split (/\s+/, $_);
204 $membuffers = $temp[1];
205 } elsif ($_ =~ /^SwapTotal:/) {
206 my @temp = split (/\s+/, $_);
207 $swaptotal = $temp[1];
208 } elsif ($_ =~ /^SwapFree:/) {
209 my @temp = split (/\s+/, $_);
210 $swapfree = $temp[1];
215 system("/bin/df > /tmp/diskfree");
216 open DF
, "/tmp/diskfree";
220 my @temp = split (/\s+/, $_);
221 $memshared = $temp[2];
225 system("/bin/rm -f /tmp/diskfree");
227 $swapused = $swaptotal-$swapfree;
228 RRDs
::update
("$rrdlog/mem.rrd",
229 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
230 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
231 $ERROR = RRDs
::error
;
232 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
237 my ($readsect, $writesect, $trash);
238 if ( ! -e
"$rrdlog/disk-$disk.rrd") {
239 RRDs
::create
("$rrdlog/disk-$disk.rrd", "--step=300",
240 "DS:readsect:COUNTER:600:0:5000000000",
241 "DS:writesect:COUNTER:600:0:5000000000",
242 "RRA:AVERAGE:0.5:1:576",
243 "RRA:AVERAGE:0.5:6:672",
244 "RRA:AVERAGE:0.5:24:732",
245 "RRA:AVERAGE:0.5:144:1460");
246 $ERROR = RRDs
::error
;
247 print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR;
250 my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
251 ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
253 print "\nread:".$readsect."write:".$writesect."\n";
255 if ($readsect && $writesect) {
256 RRDs
::update
("$rrdlog/disk-$disk.rrd",
257 "-t", "readsect:writesect",
258 "N:$readsect:$writesect");
259 $ERROR = RRDs
::error
;
260 print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
262 print "Error in RRD::update for disk: $disk no data available\n";
267 my $interface = $_[0];
269 if ( ! -e
"$rrdlog/$interface.rrd") {
270 RRDs
::create
("$rrdlog/$interface.rrd", "--step=300",
271 "DS:incoming:ABSOLUTE:600:0:12500000",
272 "DS:outgoing:ABSOLUTE:600:0:12500000",
273 "RRA:AVERAGE:0.5:1:576",
274 "RRA:AVERAGE:0.5:6:672",
275 "RRA:AVERAGE:0.5:24:732",
276 "RRA:AVERAGE:0.5:144:1460");
277 $ERROR = RRDs
::error
;
278 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
281 my $traffic = gettraffic
($interface);
282 RRDs
::update
("$rrdlog/$interface.rrd",
283 "-t", "incoming:outgoing",
285 $ERROR = RRDs
::error
;
286 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
289 sub updatefwhitsdata
{
296 if (! -e
"$rrdlog/firewallhits.rrd")
298 RRDs
::create
("$rrdlog/firewallhits.rrd", "--step=300",
299 "DS:amount:GAUGE:600:0:U",
300 "DS:portamount:GAUGE:600:0:U",
301 "RRA:AVERAGE:0.5:1:576",
302 "RRA:AVERAGE:0.5:6:672",
303 "RRA:AVERAGE:0.5:24:732",
304 "RRA:AVERAGE:0.5:144:1460");
305 $ERROR = RRDs
::error
;
306 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
309 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
310 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
316 if (/kernel:.*(IN=.*)$/) {
323 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
324 if (!(open (FILE
,'/tmp/snort.fwhits'))) {
337 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
343 if (/kernel:.*(Scan.*)$/) {
350 system("rm /tmp/messages.fwhits");
351 system("rm /tmp/snort.fwhits");
353 $portamount = $portaktuell + $alertaktuell;
355 RRDs
::update
("$rrdlog/firewallhits.rrd",
356 "N:$aktuell:$portamount");
357 $ERROR = RRDs
::error
;
358 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
361 # Creates and updates a link quality database
362 # -------------------------------------------
364 if ( ! -e
"$rrdlog/lq.rrd") {
365 RRDs
::create
("$rrdlog/lq.rrd", "--step=300",
366 "DS:loss:GAUGE:600:0:100",
367 "DS:roundtrip:GAUGE:600:0:10000",
368 "RRA:AVERAGE:0.5:1:576",
369 "RRA:AVERAGE:0.5:6:672",
370 "RRA:AVERAGE:0.5:24:732",
371 "RRA:AVERAGE:0.5:144:1460");
372 $ERROR = RRDs
::error
;
373 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
378 # LQ_GATEWAY is the ip of your isp's public ip facing you
379 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
381 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
383 my @temp = split (/\/|\
%|\s
/, $pingoutput);
384 $packetloss = $temp[17];
385 $roundtrip = $temp[28];
386 RRDs
::update
("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
387 $ERROR = RRDs
::error
;
388 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
394 if ( ! -e
"$rrdlog/hddtemp-$disk.rrd")
396 # database did not exist -> create
397 RRDs
::create
("$rrdlog/hddtemp-$disk.rrd", "--step=300",
398 "DS:temperature:GAUGE:600:0:100",
399 "RRA:AVERAGE:0.5:1:576",
400 "RRA:AVERAGE:0.5:6:672",
401 "RRA:AVERAGE:0.5:24:732",
402 "RRA:AVERAGE:0.5:144:1460");
403 $ERROR = RRDs
::error
;
404 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
409 my $smart_output = '';
411 if ( -e
"$path_smartctl" )
413 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
416 if ( -e
"$path_hddtemp" )
418 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
420 # I know 4 response possible responses:
422 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
423 # /dev/harddisk: harddisk type: no sensor
424 # /dev/harddisk: harddisk type: 37?C or ?F
427 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
431 elsif ( index($hdd_output, "no sensor") != -1 )
435 elsif ( index($hdd_output, "$disk") != -1 )
437 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
442 $hdd_output =~ /(\d+)\s/;
446 elsif ( -e
"/var/log/smartctl_out_hddtemp-$disk" )
448 $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
449 my @t = split(/\s+/,$hdd_output);
457 # print "hdd $hdd_output \n";
458 # print "temp $temp \n";
460 RRDs
::update
("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
462 $ERROR = RRDs
::error
;
463 print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
468 if ( ! -e
"$rrdlog/mbmon.rrd" )
470 # database did not exist -> create
472 @args = ("$rrdlog/mbmon.rrd");
474 push(@args, "--step=300");
475 foreach $key ( sort(keys %mbmon_values) )
477 push(@args, "DS:$key:GAUGE:600:U:U");
479 push(@args, "RRA:AVERAGE:0.5:1:576");
480 push(@args, "RRA:AVERAGE:0.5:6:672");
481 push(@args, "RRA:AVERAGE:0.5:24:732");
482 push(@args, "RRA:AVERAGE:0.5:144:1460");
484 print("create ". join( ", ", @args)) if ( $dbg );
486 RRDs
::create
(@args);
487 $ERROR = RRDs
::error
;
488 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
495 foreach $key ( sort(keys %mbmon_values) )
498 push(@val, $mbmon_values{$key});
501 $template = join(':', @ds);
502 $value = "N:".join(':', @val);
504 print("update template = '$template'\n") if ( $dbg );
505 print("update value = '$value'\n") if ( $dbg );
507 RRDs
::update
("$rrdlog/mbmon.rrd", "-t", $template, $value);
508 $ERROR = RRDs
::error
;
509 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
513 system ('/usr/sbin/fetchipac');
519 if ( -e
"/var/log/squid/access.log") {
520 system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
526 if ((${Lang
::language
} eq 'cs') ||
527 (${Lang
::language
} eq 'hu') ||
528 (${Lang
::language
} eq 'pl') ||
529 (${Lang
::language
} eq 'sk')) {
530 # Czech, Hungarian, Polish and Slovak character set
531 foreach my $key(keys %Lang::tr
) {
532 from_to
($tr{$key}, "utf-8", "iso-8859-2");
534 } elsif (${Lang
::language
} eq 'tr') {
536 foreach my $key(keys %Lang::tr
) {
537 from_to
($tr{$key}, "utf-8", "iso-8859-9");
540 foreach my $key(keys %Lang::tr
) {
541 from_to
($tr{$key}, "utf-8", "iso-8859-1");
552 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
553 print "\nFound following amount of disks:".@disks."\n";
557 print "Working on disk ".$disk.".\n";
558 updatediskdata
($disk);
572 ### HDDTEMP-Graphs for /dev/harddisk
575 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
576 print "\nFound following amount of disks for hddtemp:".@disks."\n";
580 updatehdddata
($disk);
586 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
588 updateifdata
("GREEN");
589 updateifdata
("RED");
590 if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {
591 updateifdata
("ORANGE");
593 if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {
594 updateifdata
("BLUE");