]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Samba default Freigabe angepasst
[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
de53a053
CS
41system("chmod 777 /srv/web/ipfire/html/graphs");
42
cd1a2927
MT
43# Force language back to English (ugly hack!)
44# Modified to only force if we are unable to convert charset
45# from utf-8
46if ((${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')) {
350b52c5 53 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
cd1a2927 54} else {
350b52c5 55 %tr=%Lang::tr; # use translated version for other languages
cd1a2927
MT
56}
57
58# Settings
59my $rrdlog = "/var/log/rrd";
fd0763dc 60my $graphs = "/srv/web/ipfire/html/graphs";
cd1a2927 61$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
60cbd6e7 62my $hdd_device = "/dev/harddisk";
a68fedca 63my $temp = '';
52345790
MT
64my %mbmon_values = ();
65my $key;
66my $value;
67my @args = ();
68my $count = 0;
69my $ERROR;
70my $dbg = 0;
52345790 71my $path_smartctl = "/usr/sbin/smartctl";
e3a8510a 72my $path_hddtemp = "/usr/sbin/hddtemp";
52345790 73
4b4aec3a
CS
74my %color = ();
75my %mainsettings = ();
76&General::readhash("${General::swroot}/main/settings", \%mainsettings);
77&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
52345790
MT
78
79open(MBMON_OUT, ">/var/log/mbmon-values");
80open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
81
82while( $_ = <FD> )
83{
84 next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
85 $key = $1 ;
86 $value = $2 ;
87 $key =~ y/A-Z/a-z/ ;
88 $mbmon_values{$key} = $value;
89 print(MBMON_OUT "$key=$value\n");
90}
91close(FD);
92close(MBMON_OUT);
cd1a2927
MT
93
94sub gettraffic {
350b52c5 95 my $interface = $_[0];
cd1a2927 96
350b52c5
CS
97 my $bytesin=0;
98 my $bytesout=0;
cd1a2927 99
350b52c5
CS
100 foreach (@ipacsum)
101 {
102 # Incoming...
103 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
cd1a2927 104
350b52c5
CS
105 # Forwarded Incoming...
106 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
cd1a2927 107
350b52c5
CS
108 # Outgoing...
109 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
cd1a2927 110
350b52c5
CS
111 # Forwarded Outgoing...
112 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
113 }
114 return "$bytesin:$bytesout";
cd1a2927
MT
115}
116
117sub updatecpudata {
350b52c5
CS
118 if ( ! -e "$rrdlog/cpu.rrd") {
119 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
60412147
CS
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",
350b52c5
CS
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;
131 }
132
60412147 133 my ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq);
350b52c5 134
60412147
CS
135 open STAT, "/proc/stat";
136 while(<STAT>) {
137 chomp;
138 /^cpu\s/ or next;
139 ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/;
140 last;
141 }
142 close STAT;
350b52c5 143 $user += $nice;
60412147
CS
144 $irq += $softirq;
145
350b52c5
CS
146
147 RRDs::update ("$rrdlog/cpu.rrd",
60412147
CS
148 "-t", "user:system:idle:iowait:irq",
149 "N:$user:$system:$idle:$iowait:$irq");
350b52c5
CS
150 $ERROR = RRDs::error;
151 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
cd1a2927
MT
152
153}
154
207cc1cf 155sub updateloaddata {
350b52c5
CS
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");
207cc1cf 165
350b52c5
CS
166 $ERROR = RRDs::error;
167 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
168 }
cd1a2927
MT
169}
170
171sub updatememdata {
350b52c5
CS
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;
188 }
189
190 open MEM, "/proc/meminfo";
191 while(<MEM>) {
192 chomp;
193 if ($_ =~ /^MemTotal:/) {
194 my @temp = split (/\s+/, $_);
195 $memused = $temp[1];
196 } elsif ($_ =~ /^MemFree:/) {
197 my @temp = split (/\s+/, $_);
198 $memfree = $temp[1];
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];
211 }
212 }
213 close MEM;
214
215 system("/bin/df > /tmp/diskfree");
216 open DF, "/tmp/diskfree";
217 while(<DF>) {
218 chomp;
219 if ($_ =~ /^shm/) {
220 my @temp = split (/\s+/, $_);
221 $memshared = $temp[2];
222 }
223 }
224 close DF;
225 system("/bin/rm -f /tmp/diskfree");
226
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;
cd1a2927
MT
233}
234
235sub updatediskdata {
350b52c5
CS
236 my $disk = $_[0];
237 my ($readsect, $writesect, $trash);
265352a0
CS
238 my @array = split(/\//,$disk);
239 if ( ! -e "$rrdlog/disk-".$array[$#array].".rrd") {
240 RRDs::create ("$rrdlog/disk-".$array[$#array].".rrd", "--step=300",
350b52c5
CS
241 "DS:readsect:COUNTER:600:0:5000000000",
242 "DS:writesect:COUNTER:600:0:5000000000",
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 disk $disk: $ERROR\n" if $ERROR;
249 }
250
251 my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
252 ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
253
254 print "\nread:".$readsect."write:".$writesect."\n";
255
256 if ($readsect && $writesect) {
265352a0 257 RRDs::update ("$rrdlog/disk-".$array[$#array].".rrd",
350b52c5
CS
258 "-t", "readsect:writesect",
259 "N:$readsect:$writesect");
260 $ERROR = RRDs::error;
261 print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
262 } else {
263 print "Error in RRD::update for disk: $disk no data available\n";
264 }
cd1a2927
MT
265}
266
267sub updateifdata {
350b52c5
CS
268 my $interface = $_[0];
269
270 if ( ! -e "$rrdlog/$interface.rrd") {
271 RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
272 "DS:incoming:ABSOLUTE:600:0:12500000",
273 "DS:outgoing:ABSOLUTE:600:0:12500000",
274 "RRA:AVERAGE:0.5:1:576",
275 "RRA:AVERAGE:0.5:6:672",
276 "RRA:AVERAGE:0.5:24:732",
277 "RRA:AVERAGE:0.5:144:1460");
278 $ERROR = RRDs::error;
279 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
280 }
281
282 my $traffic = gettraffic ($interface);
283 RRDs::update ("$rrdlog/$interface.rrd",
284 "-t", "incoming:outgoing",
285 "N:$traffic");
286 $ERROR = RRDs::error;
287 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
df8c7810
MT
288}
289
290sub updatefwhitsdata {
350b52c5
CS
291 my $portamount=0;
292 my $alertaktuell=0;
293 my $aktuell=0;
294 my $portaktuell=0;
295 my $skip=0;
296
297 if (! -e "$rrdlog/firewallhits.rrd")
298 {
299 RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
300 "DS:amount:GAUGE:600:0:U",
301 "DS:portamount:GAUGE:600:0:U",
302 "RRA:AVERAGE:0.5:1:576",
303 "RRA:AVERAGE:0.5:6:672",
304 "RRA:AVERAGE:0.5:24:732",
305 "RRA:AVERAGE:0.5:144:1460");
306 $ERROR = RRDs::error;
307 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
308 }
309
310 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
311 if (!(open (FILE,'/tmp/messages.fwhits'))) {
df8c7810 312 $skip=1;
350b52c5
CS
313 }
314 $aktuell = 0;
315 if (!$skip) {
316 while (<FILE>) {
317 if (/kernel:.*(IN=.*)$/) {
318 $aktuell++;
319 }
320 }
321 close (FILE);
322 }
323
324 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
325 if (!(open (FILE,'/tmp/snort.fwhits'))) {
df8c7810 326 $skip=1;
350b52c5
CS
327 }
328 $alertaktuell = 0;
329 if (!$skip) {
330 while (<FILE>) {
331 if (/scan.*$/) {
332 $alertaktuell++;
333 }
334 }
335 close (FILE);
336 }
337
338 if (!(open (FILE,'/tmp/messages.fwhits'))) {
df8c7810 339 $skip=1;
350b52c5
CS
340 }
341 $portaktuell = 0;
342 if (!$skip) {
343 while (<FILE>) {
344 if (/kernel:.*(Scan.*)$/) {
345 $portaktuell++;
346 }
347 }
348 close (FILE);
349 }
350
351 system("rm /tmp/messages.fwhits");
352 system("rm /tmp/snort.fwhits");
353
354 $portamount = $portaktuell + $alertaktuell;
355 chomp($portamount);
356 RRDs::update ("$rrdlog/firewallhits.rrd",
357 "N:$aktuell:$portamount");
358 $ERROR = RRDs::error;
359 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
df8c7810
MT
360}
361
072cd997
MT
362# Creates and updates a link quality database
363# -------------------------------------------
364sub updatelq {
350b52c5
CS
365 if ( ! -e "$rrdlog/lq.rrd") {
366 RRDs::create ("$rrdlog/lq.rrd", "--step=300",
367 "DS:loss:GAUGE:600:0:100",
368 "DS:roundtrip:GAUGE:600:0:10000",
369 "RRA:AVERAGE:0.5:1:576",
370 "RRA:AVERAGE:0.5:6:672",
371 "RRA:AVERAGE:0.5:24:732",
372 "RRA:AVERAGE:0.5:144:1460");
373 $ERROR = RRDs::error;
374 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
375 }
376 my $packetloss=0;
377 my $roundtrip=0;
378 my $test=0;
379# LQ_GATEWAY is the ip of your isp's public ip facing you
cce90b0b
CS
380 my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`;
381 chomp($LQ_GATEWAY);
382 my $NUMPINGS=5;
a28fdc01 383 my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q $LQ_GATEWAY | tail -2`;
350b52c5 384 my @temp = split (/\/|\%|\s/, $pingoutput);
a28fdc01
CS
385 $packetloss = $temp[5];
386 $roundtrip = $temp[17];
387
388 print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
389
390 if ( $packetloss eq "100" ){
391 my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org | tail -2`;
392 my @temp = split (/\/|\%|\s/, $pingoutput);
393 $packetloss = $temp[5];
394 $roundtrip = $temp[17];
395
396 print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
397 }
398
350b52c5
CS
399 RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
400 $ERROR = RRDs::error;
401 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
072cd997
MT
402}
403
60cbd6e7
MT
404sub updatehdddata
405{
9217f236 406 my $disk = $_[0];
471a46f7 407 my $standby;
265352a0 408 my @array = split(/\//,$disk);
471a46f7 409
265352a0 410 if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd")
471a46f7
CS
411 {
412 # database did not exist -> create
265352a0 413 RRDs::create ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "--step=300",
471a46f7
CS
414 "DS:standby:GAUGE:600:0:1",
415 "RRA:AVERAGE:0.5:1:576",
416 "RRA:AVERAGE:0.5:6:672",
417 "RRA:AVERAGE:0.5:24:732",
418 "RRA:AVERAGE:0.5:144:1460");
419 $ERROR = RRDs::error;
265352a0 420 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
471a46f7
CS
421 }
422
265352a0 423 if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
471a46f7
CS
424 else {$standby = 0;}
425
265352a0 426 RRDs::update ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
471a46f7 427 $ERROR = RRDs::error;
265352a0 428 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
471a46f7 429
265352a0 430 if ( ! -e "$rrdlog/hddtemp-".$array[$#array].".rrd")
60cbd6e7
MT
431 {
432 # database did not exist -> create
265352a0 433 RRDs::create ("$rrdlog/hddtemp-".$array[$#array].".rrd", "--step=300",
60cbd6e7
MT
434 "DS:temperature:GAUGE:600:0:100",
435 "RRA:AVERAGE:0.5:1:576",
436 "RRA:AVERAGE:0.5:6:672",
437 "RRA:AVERAGE:0.5:24:732",
438 "RRA:AVERAGE:0.5:144:1460");
439 $ERROR = RRDs::error;
265352a0 440 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
60cbd6e7 441 }
52345790 442
471a46f7
CS
443