]>
git.ipfire.org Git - people/ms/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:GAUGE:600:0:100",
119 "DS:system:GAUGE:600:0:100",
120 "DS:idle:GAUGE:600:0:100",
121 "DS:iowait:GAUGE:600:0:100",
122 "RRA:AVERAGE:0.5:1:576",
123 "RRA:AVERAGE:0.5:6:672",
124 "RRA:AVERAGE:0.5:24:732",
125 "RRA:AVERAGE:0.5:144:1460");
126 $ERROR = RRDs
::error
;
127 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
130 my ($cpu, $user, $nice, $system, $idle, $trash, $iowait);
132 my $Zeilen = `/usr/bin/iostat -c | tail -2 | head -1`;
133 ($trash, $user, $nice, $system, $iowait, $trash, $idle) = split(/\s+/,$Zeilen);
136 RRDs
::update
("$rrdlog/cpu.rrd",
137 "-t", "user:system:idle:iowait",
138 "N:$user:$system:$idle:$iowait");
139 $ERROR = RRDs
::error
;
140 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
145 if ( ! -e
"$rrdlog/load.rrd") {
146 RRDs
::create
("$rrdlog/load.rrd", "--step=60",
147 "DS:load1:GAUGE:120:0:U",
148 "DS:load5:GAUGE:120:0:U",
149 "DS:load15:GAUGE:120:0:U",
150 "RRA:AVERAGE:0.5:1:2160",
151 "RRA:AVERAGE:0.5:5:2016",
152 "RRA:AVERAGE:0.5:15:2880",
153 "RRA:AVERAGE:0.5:60:8760");
155 $ERROR = RRDs
::error
;
156 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
161 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
162 if ( ! -e
"$rrdlog/mem.rrd") {
163 RRDs
::create
("$rrdlog/mem.rrd", "--step=300",
164 "DS:memused:ABSOLUTE:600:0:5000000000",
165 "DS:memfree:ABSOLUTE:600:0:5000000000",
166 "DS:memshared:ABSOLUTE:600:0:5000000000",
167 "DS:membuffers:ABSOLUTE:600:0:5000000000",
168 "DS:memcache:ABSOLUTE:600:0:5000000000",
169 "DS:swapused:ABSOLUTE:600:0:5000000000",
170 "DS:swapfree:ABSOLUTE:600:0:5000000000",
171 "RRA:AVERAGE:0.5:1:576",
172 "RRA:AVERAGE:0.5:6:672",
173 "RRA:AVERAGE:0.5:24:732",
174 "RRA:AVERAGE:0.5:144:1460");
175 $ERROR = RRDs
::error
;
176 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
179 open MEM
, "/proc/meminfo";
182 if ($_ =~ /^MemTotal:/) {
183 my @temp = split (/\s+/, $_);
185 } elsif ($_ =~ /^MemFree:/) {
186 my @temp = split (/\s+/, $_);
188 } elsif ($_ =~ /^Cached:/) {
189 my @temp = split (/\s+/, $_);
190 $memcache = $temp[1];
191 } elsif ($_ =~ /^Buffers:/) {
192 my @temp = split (/\s+/, $_);
193 $membuffers = $temp[1];
194 } elsif ($_ =~ /^SwapTotal:/) {
195 my @temp = split (/\s+/, $_);
196 $swaptotal = $temp[1];
197 } elsif ($_ =~ /^SwapFree:/) {
198 my @temp = split (/\s+/, $_);
199 $swapfree = $temp[1];
204 system("/bin/df > /tmp/diskfree");
205 open DF
, "/tmp/diskfree";
209 my @temp = split (/\s+/, $_);
210 $memshared = $temp[2];
214 system("/bin/rm -f /tmp/diskfree");
216 $swapused = $swaptotal-$swapfree;
217 RRDs
::update
("$rrdlog/mem.rrd",
218 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
219 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
220 $ERROR = RRDs
::error
;
221 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
226 my ($readsect, $writesect, $trash);
227 if ( ! -e
"$rrdlog/disk-$disk.rrd") {
228 RRDs
::create
("$rrdlog/disk-$disk.rrd", "--step=300",
229 "DS:readsect:COUNTER:600:0:5000000000",
230 "DS:writesect:COUNTER:600:0:5000000000",
231 "RRA:AVERAGE:0.5:1:576",
232 "RRA:AVERAGE:0.5:6:672",
233 "RRA:AVERAGE:0.5:24:732",
234 "RRA:AVERAGE:0.5:144:1460");
235 $ERROR = RRDs
::error
;
236 print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR;
239 my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
240 ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
242 print "\nread:".$readsect."write:".$writesect."\n";
244 if ($readsect && $writesect) {
245 RRDs
::update
("$rrdlog/disk-$disk.rrd",
246 "-t", "readsect:writesect",
247 "N:$readsect:$writesect");
248 $ERROR = RRDs
::error
;
249 print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
251 print "Error in RRD::update for disk: $disk no data available\n";
256 my $interface = $_[0];
258 if ( ! -e
"$rrdlog/$interface.rrd") {
259 RRDs
::create
("$rrdlog/$interface.rrd", "--step=300",
260 "DS:incoming:ABSOLUTE:600:0:12500000",
261 "DS:outgoing:ABSOLUTE:600:0:12500000",
262 "RRA:AVERAGE:0.5:1:576",
263 "RRA:AVERAGE:0.5:6:672",
264 "RRA:AVERAGE:0.5:24:732",
265 "RRA:AVERAGE:0.5:144:1460");
266 $ERROR = RRDs
::error
;
267 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
270 my $traffic = gettraffic
($interface);
271 RRDs
::update
("$rrdlog/$interface.rrd",
272 "-t", "incoming:outgoing",
274 $ERROR = RRDs
::error
;
275 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
278 sub updatefwhitsdata
{
285 if (! -e
"$rrdlog/firewallhits.rrd")
287 RRDs
::create
("$rrdlog/firewallhits.rrd", "--step=300",
288 "DS:amount:GAUGE:600:0:U",
289 "DS:portamount:GAUGE:600:0:U",
290 "RRA:AVERAGE:0.5:1:576",
291 "RRA:AVERAGE:0.5:6:672",
292 "RRA:AVERAGE:0.5:24:732",
293 "RRA:AVERAGE:0.5:144:1460");
294 $ERROR = RRDs
::error
;
295 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
298 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
299 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
305 if (/kernel:.*(IN=.*)$/) {
312 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
313 if (!(open (FILE
,'/tmp/snort.fwhits'))) {
326 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
332 if (/kernel:.*(Scan.*)$/) {
339 system("rm /tmp/messages.fwhits");
340 system("rm /tmp/snort.fwhits");
342 $portamount = $portaktuell + $alertaktuell;
344 RRDs
::update
("$rrdlog/firewallhits.rrd",
345 "N:$aktuell:$portamount");
346 $ERROR = RRDs
::error
;
347 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
350 # Creates and updates a link quality database
351 # -------------------------------------------
353 if ( ! -e
"$rrdlog/lq.rrd") {
354 RRDs
::create
("$rrdlog/lq.rrd", "--step=300",
355 "DS:loss:GAUGE:600:0:100",
356 "DS:roundtrip:GAUGE:600:0:10000",
357 "RRA:AVERAGE:0.5:1:576",
358 "RRA:AVERAGE:0.5:6:672",
359 "RRA:AVERAGE:0.5:24:732",
360 "RRA:AVERAGE:0.5:144:1460");
361 $ERROR = RRDs
::error
;
362 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
367 # LQ_GATEWAY is the ip of your isp's public ip facing you
368 my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
370 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
372 my @temp = split (/\/|\
%|\s
/, $pingoutput);
373 $packetloss = $temp[17];
374 $roundtrip = $temp[28];
375 RRDs
::update
("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
376 $ERROR = RRDs
::error
;
377 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
383 if ( ! -e
"$rrdlog/hddtemp-$disk.rrd")
385 # database did not exist -> create
386 RRDs
::create
("$rrdlog/hddtemp-$disk.rrd", "--step=300",
387 "DS:temperature:GAUGE:600:0:100",
388 "RRA:AVERAGE:0.5:1:576",
389 "RRA:AVERAGE:0.5:6:672",
390 "RRA:AVERAGE:0.5:24:732",
391 "RRA:AVERAGE:0.5:144:1460");
392 $ERROR = RRDs
::error
;
393 print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
398 my $smart_output = '';
400 if ( -e
"$path_smartctl" )
402 system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
405 if ( -e
"$path_hddtemp" )
407 $hdd_output = `$path_hddtemp -qn /dev/$disk`;
409 # I know 4 response possible responses:
411 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
412 # /dev/harddisk: harddisk type: no sensor
413 # /dev/harddisk: harddisk type: 37?C or ?F
416 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
420 elsif ( index($hdd_output, "no sensor") != -1 )
424 elsif ( index($hdd_output, "$disk") != -1 )
426 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
431 $hdd_output =~ /(\d+)\s/;
435 elsif ( -e
"/var/log/smartctl_out_hddtemp-$disk" )
437 $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
438 my @t = split(/\s+/,$hdd_output);
446 # print "hdd $hdd_output \n";
447 # print "temp $temp \n";
449 RRDs
::update
("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
451 $ERROR = RRDs
::error
;
452 print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
457 if ( ! -e
"$rrdlog/mbmon.rrd" )
459 # database did not exist -> create
461 @args = ("$rrdlog/mbmon.rrd");
463 push(@args, "--step=300");
464 foreach $key ( sort(keys %mbmon_values) )
466 push(@args, "DS:$key:GAUGE:600:U:U");
468 push(@args, "RRA:AVERAGE:0.5:1:576");
469 push(@args, "RRA:AVERAGE:0.5:6:672");
470 push(@args, "RRA:AVERAGE:0.5:24:732");
471 push(@args, "RRA:AVERAGE:0.5:144:1460");
473 print("create ". join( ", ", @args)) if ( $dbg );
475 RRDs
::create
(@args);
476 $ERROR = RRDs
::error
;
477 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
484 foreach $key ( sort(keys %mbmon_values) )
487 push(@val, $mbmon_values{$key});
490 $template = join(':', @ds);
491 $value = "N:".join(':', @val);
493 print("update template = '$template'\n") if ( $dbg );
494 print("update value = '$value'\n") if ( $dbg );
496 RRDs
::update
("$rrdlog/mbmon.rrd", "-t", $template, $value);
497 $ERROR = RRDs
::error
;
498 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
502 system ('/usr/sbin/fetchipac');
508 if ( -e
"/var/log/squid/access.log") {
509 system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
515 if ((${Lang
::language
} eq 'cs') ||
516 (${Lang
::language
} eq 'hu') ||
517 (${Lang
::language
} eq 'pl') ||
518 (${Lang
::language
} eq 'sk')) {
519 # Czech, Hungarian, Polish and Slovak character set
520 foreach my $key(keys %Lang::tr
) {
521 from_to
($tr{$key}, "utf-8", "iso-8859-2");
523 } elsif (${Lang
::language
} eq 'tr') {
525 foreach my $key(keys %Lang::tr
) {
526 from_to
($tr{$key}, "utf-8", "iso-8859-9");
529 foreach my $key(keys %Lang::tr
) {
530 from_to
($tr{$key}, "utf-8", "iso-8859-1");
541 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
542 print "\nFound following amount of disks:".@disks."\n";
546 print "Working on disk ".$disk.".\n";
547 updatediskdata
($disk);
561 ### HDDTEMP-Graphs for /dev/harddisk
564 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
565 print "\nFound following amount of disks for hddtemp:".@disks."\n";
569 updatehdddata
($disk);
575 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
577 updateifdata
("GREEN");
578 updateifdata
("RED");
579 if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {
580 updateifdata
("ORANGE");
582 if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {
583 updateifdata
("BLUE");