]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/makegraphs
53daccc888ad52fdd1ea6be34b02bcb61b3e7d6d
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 #use translated version for other languages
60 my $rrdlog = "/var/log/rrd";
61 my $graphs = "/srv/web/ipfire/html/graphs";
62 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
63 my $hdd_device = "/dev/harddisk";
65 my %mbmon_values = ();
72 my $path_smartctl = "/usr/sbin/smartctl";
73 my $path_hddtemp = "/usr/sbin/hddtemp";
76 my %mainsettings = ();
77 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
78 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
80 open(MBMON_OUT
, ">/var/log/mbmon-values");
81 open(FD
, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
85 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
89 $mbmon_values{$key} = $value;
90 print(MBMON_OUT
"$key=$value\n");
96 my $interface = $_[0];
103 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
104 # Forwarded Incoming...
105 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
107 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
108 # Forwarded Outgoing...
109 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
111 return "$bytesin:$bytesout";
115 if ( ! -e
"$rrdlog/cpu.rrd") {
116 RRDs
::create
("$rrdlog/cpu.rrd", "--step=300",
117 "DS:user:COUNTER:600:0:500000000",
118 "DS:system:COUNTER:600:0:500000000",
119 "DS:idle:COUNTER:600:0:500000000",
120 "DS:iowait:COUNTER:600:0:500000000",
121 "DS:irq:COUNTER:600:0:500000000",
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, $iowait, $irq, $softirq);
131 open STAT
, "/proc/stat";
135 ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/;
141 RRDs
::update
("$rrdlog/cpu.rrd",
142 "-t", "user:system:idle:iowait:irq",
143 "N:$user:$system:$idle:$iowait:$irq");
144 $ERROR = RRDs
::error
;
145 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
149 if ( ! -e
"$rrdlog/load.rrd") {
150 RRDs
::create
("$rrdlog/load.rrd", "--step=60",
151 "DS:load1:GAUGE:120:0:U",
152 "DS:load5:GAUGE:120:0:U",
153 "DS:load15:GAUGE:120:0:U",
154 "RRA:AVERAGE:0.5:1:2160",
155 "RRA:AVERAGE:0.5:5:2016",
156 "RRA:AVERAGE:0.5:15:2880",
157 "RRA:AVERAGE:0.5:60:8760");
158 $ERROR = RRDs
::error
;
159 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
164 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
165 if ( ! -e
"$rrdlog/mem.rrd") {
166 RRDs
::create
("$rrdlog/mem.rrd", "--step=300",
167 "DS:memused:ABSOLUTE:600:0:5000000000",
168 "DS:memfree:ABSOLUTE:600:0:5000000000",
169 "DS:memshared:ABSOLUTE:600:0:5000000000",
170 "DS:membuffers:ABSOLUTE:600:0:5000000000",
171 "DS:memcache:ABSOLUTE:600:0:5000000000",
172 "DS:swapused:ABSOLUTE:600:0:5000000000",
173 "DS:swapfree:ABSOLUTE:600:0:5000000000",
174 "RRA:AVERAGE:0.5:1:576",
175 "RRA:AVERAGE:0.5:6:672",
176 "RRA:AVERAGE:0.5:24:732",
177 "RRA:AVERAGE:0.5:144:1460");
178 $ERROR = RRDs
::error
;
179 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
182 open MEM
, "/proc/meminfo";
185 if ($_ =~ /^MemTotal:/) {my @temp = split (/\s+/, $_);$memused = $temp[1];
186 } elsif ($_ =~ /^MemFree:/) {my @temp = split (/\s+/, $_);$memfree = $temp[1];
187 } elsif ($_ =~ /^Cached:/) {my @temp = split (/\s+/, $_);$memcache = $temp[1];
188 } elsif ($_ =~ /^Buffers:/) {my @temp = split (/\s+/, $_);$membuffers = $temp[1];
189 } elsif ($_ =~ /^SwapTotal:/) {my @temp = split (/\s+/, $_);$swaptotal = $temp[1];
190 } elsif ($_ =~ /^SwapFree:/) {my @temp = split (/\s+/, $_);$swapfree = $temp[1];}
194 system("/bin/df > /tmp/diskfree");
195 open DF
, "/tmp/diskfree";
198 if ($_ =~ /^shm/) {my @temp = split (/\s+/, $_);$memshared = $temp[2];}
201 system("/bin/rm -f /tmp/diskfree");
202 $swapused = $swaptotal-$swapfree;
203 RRDs
::update
("$rrdlog/mem.rrd",
204 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
205 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
206 $ERROR = RRDs
::error
;
207 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
212 my ($readsect, $writesect, $trash);
213 my @array = split(/\//,$disk);
214 if ( ! -e
"$rrdlog/disk-".$array[$#array].".rrd") {
215 RRDs
::create
("$rrdlog/disk-".$array[$#array].".rrd", "--step=300",
216 "DS:readsect:COUNTER:600:0:5000000000",
217 "DS:writesect:COUNTER:600:0:5000000000",
218 "RRA:AVERAGE:0.5:1:576",
219 "RRA:AVERAGE:0.5:6:672",
220 "RRA:AVERAGE:0.5:24:732",
221 "RRA:AVERAGE:0.5:144:1460");
222 $ERROR = RRDs
::error
;
223 print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR;
225 my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
226 ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
227 print "\nread:".$readsect."write:".$writesect."\n";
228 if ($readsect && $writesect) {
229 RRDs
::update
("$rrdlog/disk-".$array[$#array].".rrd",
230 "-t", "readsect:writesect",
231 "N:$readsect:$writesect");
232 $ERROR = RRDs
::error
;
233 print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
234 } else {print "Error in RRD::update for disk: $disk no data available\n";}
238 my $interface = $_[0];
239 if ( ! -e
"$rrdlog/$interface.rrd") {
240 RRDs
::create
("$rrdlog/$interface.rrd", "--step=300",
241 "DS:incoming:ABSOLUTE:600:0:12500000",
242 "DS:outgoing:ABSOLUTE:600:0:12500000",
243 "RRA:AVERAGE:0.5:1:576",
244 "RRA:AVERAGE:0.5:6:672",
245 "RRA:AVERAGE:0.5:24:732",
246 "RRA:AVERAGE:0.5:144:1460");
247 $ERROR = RRDs
::error
;
248 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
250 my $traffic = gettraffic
($interface);
251 RRDs
::update
("$rrdlog/$interface.rrd",
252 "-t", "incoming:outgoing",
254 $ERROR = RRDs
::error
;
255 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
258 sub updatefwhitsdata
{
264 if (! -e
"$rrdlog/firewallhits.rrd"){
265 RRDs
::create
("$rrdlog/firewallhits.rrd", "--step=300",
266 "DS:amount:GAUGE:600:0:U",
267 "DS:portamount:GAUGE:600:0:U",
268 "RRA:AVERAGE:0.5:1:576",
269 "RRA:AVERAGE:0.5:6:672",
270 "RRA:AVERAGE:0.5:24:732",
271 "RRA:AVERAGE:0.5:144:1460");
272 $ERROR = RRDs
::error
;
273 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
275 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
276 if (!(open (FILE
,'/tmp/messages.fwhits'))) {$skip=1;}
280 if (/kernel: DROP_INPUT.*$/) {$aktuell++;}
284 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
285 if (!(open (FILE
,'/tmp/snort.fwhits'))) {$skip=1;}
289 if (/scan.*$/) {$alertaktuell++;}
293 if (!(open (FILE
,'/tmp/messages.fwhits'))) {$skip=1;}
297 if (/kernel:.*(Scan.*)$/) {$portaktuell++;}
301 system("rm /tmp/messages.fwhits");
302 system("rm /tmp/snort.fwhits");
303 $portamount = $portaktuell + $alertaktuell;
305 RRDs
::update
("$rrdlog/firewallhits.rrd",
306 "N:$aktuell:$portamount");
307 $ERROR = RRDs
::error
;
308 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
311 # Creates and updates a link quality database
312 # -------------------------------------------
314 if ( ! -e
"$rrdlog/lq.rrd") {
315 RRDs
::create
("$rrdlog/lq.rrd", "--step=300",
316 "DS:loss:GAUGE:600:0:100",
317 "DS:roundtrip:GAUGE:600:0:10000",
318 "RRA:AVERAGE:0.5:1:576",
319 "RRA:AVERAGE:0.5:6:672",
320 "RRA:AVERAGE:0.5:24:732",
321 "RRA:AVERAGE:0.5:144:1460");
322 $ERROR = RRDs
::error
;
323 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
328 #LQ_GATEWAY is the ip of your isp's public ip facing you
329 my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`;
332 my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q $LQ_GATEWAY | tail -2`;
333 my @temp = split (/\/|\
%|\s
/, $pingoutput);
334 $packetloss = $temp[5];
335 $roundtrip = $temp[17];
336 print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
337 if ( $packetloss eq "100" ){
338 my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org | tail -2`;
339 my @temp = split (/\/|\
%|\s
/, $pingoutput);
340 $packetloss = $temp[5];
341 $roundtrip = $temp[17];
342 print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
344 RRDs
::update
("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
345 $ERROR = RRDs
::error
;
346 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
353 my @array = split(/\//,$disk);
355 if ( ! -e
"$rrdlog/hddshutdown-".$array[$#array].".rrd"){
356 # database did not exist -> create
357 RRDs
::create
("$rrdlog/hddshutdown-".$array[$#array].".rrd", "--step=300",
358 "DS:standby:GAUGE:600:0:1",
359 "RRA:AVERAGE:0.5:1:576",
360 "RRA:AVERAGE:0.5:6:672",
361 "RRA:AVERAGE:0.5:24:732",
362 "RRA:AVERAGE:0.5:144:1460");
363 $ERROR = RRDs
::error
;
364 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
367 if (-e
"/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
370 RRDs
::update
("$rrdlog/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
371 $ERROR = RRDs
::error
;
372 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
374 if ( ! -e
"$rrdlog/hddtemp-".$array[$#array].".rrd"){
375 # database did not exist -> create
376 RRDs
::create
("$rrdlog/hddtemp-".$array[$#array].".rrd", "--step=300",
377 "DS:temperature:GAUGE:600:0:100",
378 "RRA:AVERAGE:0.5:1:576",
379 "RRA:AVERAGE:0.5:6:672",
380 "RRA:AVERAGE:0.5:24:732",
381 "RRA:AVERAGE:0.5:144:1460");
382 $ERROR = RRDs
::error
;
383 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
386 # Temperaturlesen wÃrde die Platte aufwecken!!!
390 my $smart_output = '';
391 if ( -e
"$path_smartctl" ){system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");}
392 if ( -e
"/var/log/smartctl_out_hddtemp-".$array[$#array] ){
393 $hdd_output = `cat /var/log/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`;
394 my @t = split(/\s+/,$hdd_output);
397 print "Temperature for ".$array[$#array]."->".$temp."<-\n";
398 system("echo \"Temperature for $array[$#array] -> $temp <-\n\" >>/tmp/debug");
399 # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
401 RRDs
::update
("$rrdlog/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
402 $ERROR = RRDs
::error
;
403 print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
410 if ( ! -e
"$rrdlog/mbmon.rrd" ){
411 # database did not exist -> create
413 @args = ("$rrdlog/mbmon.rrd");
414 push(@args, "--step=300");
415 foreach $key ( sort(keys %mbmon_values) ){push(@args, "DS:$key:GAUGE:600:U:U");}
416 push(@args, "RRA:AVERAGE:0.5:1:576");
417 push(@args, "RRA:AVERAGE:0.5:6:672");
418 push(@args, "RRA:AVERAGE:0.5:24:732");
419 push(@args, "RRA:AVERAGE:0.5:144:1460");
421 print("create ". join( ", ", @args)) if ( $dbg );
422 RRDs
::create
(@args);
423 $ERROR = RRDs
::error
;
424 print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
431 foreach $key ( sort(keys %mbmon_values) ){
433 push(@val, $mbmon_values{$key});
436 $template = join(':', @ds);
437 $value = "N:".join(':', @val);
439 print("update template = '$template'\n") if ( $dbg );
440 print("update value = '$value'\n") if ( $dbg );
442 RRDs
::update
("$rrdlog/mbmon.rrd", "-t", $template, $value);
443 $ERROR = RRDs
::error
;
444 print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
448 system ('/usr/sbin/fetchipac');
454 if ( -e
"/var/log/squid/access.log") {system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");}
459 if ((${Lang
::language
} eq 'cs') || (${Lang
::language
} eq 'hu') || (${Lang
::language
} eq 'pl') || (${Lang
::language
} eq 'sk')) {
460 # Czech, Hungarian, Polish and Slovak character set
461 foreach my $key(keys %Lang::tr
) {from_to
($tr{$key}, "utf-8", "iso-8859-2");}
462 } elsif (${Lang
::language
} eq 'tr') {
464 foreach my $key(keys %Lang::tr
) {from_to
($tr{$key}, "utf-8", "iso-8859-9");}
466 foreach my $key(keys %Lang::tr
) {from_to
($tr{$key}, "utf-8", "iso-8859-1");}
481 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
482 system("unlink /tmp/hddstatus && touch /tmp/hddstatus");
483 print "\nFound following amount of disks:".@disks."\n";
487 print "Working on disk ".$disk.".\n";
491 my $newdiskstats = "";
492 my @array = split(/\//,$disk);
494 $diskstats = `cat /tmp/hddstats-$array[$#array]`;
496 my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
498 my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
501 if ($status !~/standby/ || $diskstats ne $newdiskstats){
502 if (-e
"/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);}
505 if (-e
"/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";}
506 else{$status = " active\n";}
508 open(DATEI
, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
509 print DATEI
$disk."-".$status;
512 updatediskdata
($disk);
513 updatehdddata
($disk);
535 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
537 updateifdata
("GREEN");
538 updateifdata
("RED");
539 if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {updateifdata
("ORANGE");}
540 if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {updateifdata
("BLUE");}