]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/makegraphs
8cd4de0cf5984478d3a6e86e3e4f4847a6b65504
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);
35 # Added for conversion of utf-8 characters
39 # Force language back to English (ugly hack!)
40 # Modified to only force if we are unable to convert charset
42 if ((${Lang
::language
} eq 'el') ||
43 (${Lang
::language
} eq 'fa') ||
44 (${Lang
::language
} eq 'ru') ||
45 (${Lang
::language
} eq 'th') ||
46 (${Lang
::language
} eq 'vi') ||
47 (${Lang
::language
} eq 'zh') ||
48 (${Lang
::language
} eq 'zt')) {
49 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
51 %tr=%Lang::tr
; # use translated version for other languages
55 my $rrdlog = "/var/log/rrd";
56 my $graphs = "/home/httpd/html/graphs";
57 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
58 my $hdd_device = "/dev/harddisk";
61 my $interface = $_[0];
69 $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
71 # Forwarded Incoming...
72 $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
75 $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
77 # Forwarded Outgoing...
78 $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
80 return "$bytesin:$bytesout";
86 RRDs
::graph
("$graphs/cpu-$period.png",
87 "--start", "-1$period", "-aPNG", "-i", "-z",
88 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
89 "--color", "SHADEA#EAE9EE",
90 "--color", "SHADEB#EAE9EE",
91 "--color", "BACK#FFFFFF",
92 "-t $tr{'cpu usage per'} $tr{$period}",
93 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
94 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
95 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
96 "CDEF:total=user,system,idle,+,+",
97 "CDEF:userpct=100,user,total,/,*",
98 "CDEF:systempct=100,system,total,/,*",
99 "CDEF:idlepct=100,idle,total,/,*",
100 "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j",
101 "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j",
102 "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j",
103 "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%",
104 "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%",
105 "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j",
106 "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%",
107 "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%",
108 "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j",
109 "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%",
110 "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%",
111 "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j");
112 $ERROR = RRDs
::error
;
113 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
117 if ( ! -e
"$rrdlog/cpu.rrd") {
118 RRDs
::create
("$rrdlog/cpu.rrd", "--step=300",
119 "DS:user:COUNTER:600:0:500000000",
120 "DS:system:COUNTER:600:0:500000000",
121 "DS:idle: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);
132 open STAT
, "/proc/stat";
136 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
142 RRDs
::update
("$rrdlog/cpu.rrd",
143 "-t", "user:system:idle",
144 "N:$user:$system:$idle");
145 $ERROR = RRDs
::error
;
146 print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
153 RRDs
::graph
("$graphs/memory-$period.png",
154 "--start", "-1$period", "-aPNG", "-i", "-z",
155 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
156 "--color", "SHADEA#EAE9EE",
157 "--color", "SHADEB#EAE9EE",
158 "--color", "BACK#FFFFFF",
159 "-t $tr{'memory usage per'} $tr{$period}",
160 "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
161 "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
162 "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
163 "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
164 "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
165 "CDEF:total=used,free,+",
166 "CDEF:used2=used,buffer,cache,shared,+,+,-",
167 "CDEF:usedpct=100,used2,total,/,*",
168 "CDEF:sharedpct=100,shared,total,/,*",
169 "CDEF:bufferpct=100,buffer,total,/,*",
170 "CDEF:cachepct=100,cache,total,/,*",
171 "CDEF:freepct=100,free,total,/,*",
172 "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
173 "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
174 "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
175 "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
176 "STACK:freepct#00FF00:$tr{'free memory'}\\j",
177 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
178 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
179 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
180 "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
181 "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
182 "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
183 "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
184 "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
185 "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
186 "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
187 "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
188 "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
189 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
190 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
191 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
192 $ERROR = RRDs
::error
;
193 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
195 RRDs
::graph
("$graphs/swap-$period.png",
196 "--start", "-1$period", "-aPNG", "-i", "-z",
197 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
198 "--color", "SHADEA#EAE9EE",
199 "--color", "SHADEB#EAE9EE",
200 "--color", "BACK#FFFFFF",
201 "-t $tr{'swap usage per'} $tr{$period}",
202 "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
203 "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
204 "CDEF:total=used,free,+",
205 "CDEF:usedpct=100,used,total,/,*",
206 "CDEF:freepct=100,free,total,/,*",
207 "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
208 "STACK:freepct#00FF00:$tr{'free swap'}\\j",
209 "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
210 "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
211 "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
212 "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
213 "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
214 "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
215 $ERROR = RRDs
::error
;
216 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
220 my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
221 if ( ! -e
"$rrdlog/mem.rrd") {
222 RRDs
::create
("$rrdlog/mem.rrd", "--step=300",
223 "DS:memused:ABSOLUTE:600:0:5000000000",
224 "DS:memfree:ABSOLUTE:600:0:5000000000",
225 "DS:memshared:ABSOLUTE:600:0:5000000000",
226 "DS:membuffers:ABSOLUTE:600:0:5000000000",
227 "DS:memcache:ABSOLUTE:600:0:5000000000",
228 "DS:swapused:ABSOLUTE:600:0:5000000000",
229 "DS:swapfree:ABSOLUTE:600:0:5000000000",
230 "RRA:AVERAGE:0.5:1:576",
231 "RRA:AVERAGE:0.5:6:672",
232 "RRA:AVERAGE:0.5:24:732",
233 "RRA:AVERAGE:0.5:144:1460");
234 $ERROR = RRDs
::error
;
235 print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
238 open MEM
, "/proc/meminfo";
242 my @temp = split (/\s+/, $_);
245 $memshared = $temp[4];
246 $membuffers = $temp[5];
247 $memcache = $temp[6];
248 } elsif ($_ =~ /^Swap:/) {
249 my @temp = split (/\s+/, $_);
250 $swapused = $temp[2];
251 $swapfree = $temp[3];
256 RRDs
::update
("$rrdlog/mem.rrd",
257 "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
258 "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
259 $ERROR = RRDs
::error
;
260 print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
263 sub updatediskgraph
{
266 RRDs
::graph
("$graphs/disk-$period.png",
267 "--start", "-1$period", "-aPNG", "-i", "-z",
268 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
269 "--color", "SHADEA#EAE9EE",
270 "--color", "SHADEB#EAE9EE",
271 "--color", "BACK#FFFFFF",
272 "-t $tr{'disk access per'} $tr{$period}",
273 "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
274 "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
275 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
276 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
277 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
278 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
279 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
280 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
281 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
282 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
283 $ERROR = RRDs
::error
;
284 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
288 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
289 if ( ! -e
"$rrdlog/disk.rrd") {
290 RRDs
::create
("$rrdlog/disk.rrd", "--step=300",
291 "DS:readsect:COUNTER:600:0:5000000000",
292 "DS:writesect:COUNTER:600:0:5000000000",
293 "RRA:AVERAGE:0.5:1:576",
294 "RRA:AVERAGE:0.5:6:672",
295 "RRA:AVERAGE:0.5:24:732",
296 "RRA:AVERAGE:0.5:144:1460");
297 $ERROR = RRDs
::error
;
298 print "Error in RRD::create for disk: $ERROR\n" if $ERROR;
301 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
302 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
304 my $major = $rdev >> 8;
305 my $minor = $rdev & 0xFF;
307 open STAT
, "/proc/stat";
308 my @diskstat = <STAT
>;
310 foreach my $line (@diskstat)
313 my @temp = split(/\:\ /,$line);
315 my @devicestat = split(/\ /,$temp[1]);
316 foreach my $stats (@devicestat)
319 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
320 if ($major eq $fields[1] and $minor eq $fields[2])
322 $readwritereq = $fields[3];
323 $readreq = $fields[4];
324 $readsect = $fields[5];
325 $writereq = $fields[6];
326 $writesect = $fields[7];
332 if ($readsect && $writesect) {
333 RRDs
::update
("$rrdlog/disk.rrd",
334 "-t", "readsect:writesect",
335 "N:$readsect:$writesect");
336 $ERROR = RRDs
::error
;
337 print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
339 print "Error in RRD::update for disk: no data available\n";
343 sub updatediskgraphnew
{
347 RRDs
::graph
("$graphs/disk-$disk-$period.png",
348 "--start", "-1$period", "-aPNG", "-i", "-z",
349 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
350 "--color", "SHADEA#EAE9EE",
351 "--color", "SHADEB#EAE9EE",
352 "--color", "BACK#FFFFFF",
353 "-t $tr{'disk access per'} $tr{$period}",
354 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
355 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
356 "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
357 "CDEF:sl_state=sleep,INF,*",
359 "AREA:sl_state#a0a0a0:disk standby\\j",
360 "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
361 "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
363 "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
364 "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
365 "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
366 "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
367 "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
368 "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
369 $ERROR = RRDs
::error
;
370 print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
373 sub updatediskdatanew
{
376 my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
377 if ( ! -e
"$rrdlog/disk-$disk.rrd") {
378 RRDs
::create
("$rrdlog/disk-$disk.rrd", "--step=300",
379 "DS:readsect:COUNTER:600:0:5000000000",
380 "DS:writesect:COUNTER:600:0:5000000000",
381 "DS:sleeping:GAUGE:600:0:1",
382 "RRA:AVERAGE:0.5:1:576",
383 "RRA:AVERAGE:0.5:6:672",
384 "RRA:AVERAGE:0.5:24:732",
385 "RRA:AVERAGE:0.5:144:1460");
386 $ERROR = RRDs
::error
;
387 print "Error in RRD::create for disk-$disk: $ERROR\n" if $ERROR;
390 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
391 $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
393 my $major = $rdev >> 8;
394 my $minor = ($rdev & 0xFF) >>6;
396 open STAT
, "/proc/stat";
397 my @diskstat = <STAT
>;
399 foreach my $line (@diskstat)
402 my @temp = split(/\:\ /,$line);
404 my @devicestat = split(/\ /,$temp[1]);
405 foreach my $stats (@devicestat)
408 my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
409 if ($major eq $fields[1] and $minor eq $fields[2])
411 $readwritereq = $fields[3];
412 $readreq = $fields[4];
413 $readsect = $fields[5];
414 $writereq = $fields[6];
415 $writesect = $fields[7];
422 my $lastsleepstate=0;
424 if ( -e
"/tmp/hddshutdown-$disk" ) {
425 open STAT
,"/tmp/hddshutdown-$disk";
426 $lastsleepstate = <STAT
>;
428 if ($lastsleepstate==$readwritereq) {
433 if ($readsect && $writesect) {
434 RRDs
::update
("$rrdlog/disk-$disk.rrd",
435 "-t", "readsect:writesect:sleeping",
436 "N:$readsect:$writesect:$sleeping");
437 $ERROR = RRDs
::error
;
438 print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
440 print "Error in RRD::update for disk-$disk: no data available\n";
445 my $interface = $_[0];
448 RRDs
::graph
("$graphs/$interface-$period.png",
449 "--start", "-1$period", "-aPNG", "-i", "-z",
450 "--alt-y-grid", "-w 600", "-h 100",
451 "--color", "SHADEA#EAE9EE",
452 "--color", "SHADEB#EAE9EE",
453 "--color", "BACK#FFFFFF",
454 "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
455 "-v$tr{'bytes per second'}",
456 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
457 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
458 "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
459 "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
460 "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
461 "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
462 "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
463 "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
464 "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
465 "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
466 $ERROR = RRDs
::error
;
467 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
471 my $interface = $_[0];
473 if ( ! -e
"$rrdlog/$interface.rrd") {
474 RRDs
::create
("$rrdlog/$interface.rrd", "--step=300",
475 "DS:incoming:ABSOLUTE:600:0:12500000",
476 "DS:outgoing:ABSOLUTE:600:0:12500000",
477 "RRA:AVERAGE:0.5:1:576",
478 "RRA:AVERAGE:0.5:6:672",
479 "RRA:AVERAGE:0.5:24:732",
480 "RRA:AVERAGE:0.5:144:1460");
481 $ERROR = RRDs
::error
;
482 print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
485 my $traffic = gettraffic
($interface);
486 RRDs
::update
("$rrdlog/$interface.rrd",
487 "-t", "incoming:outgoing",
489 $ERROR = RRDs
::error
;
490 print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
493 sub updatefwhitsgraph
{
494 my $interval = $_[0];
496 RRDs
::graph
("$graphs/firewallhits-$interval-area.png",
497 "--start", "-1$interval", "-aPNG", "-i", "-z",
498 "--alt-y-grid", "-w 600", "-h 200",
499 "--color", "SHADEA#EAE9EE",
500 "--color", "SHADEB#EAE9EE",
501 "--color", "BACK#FFFFFF",
502 "-t firewall hits over the last $interval",
503 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
504 "AREA:amount#6464FF:firewallhits",
505 "GPRINT:amount:MAX: Max\\: %2.2lf %S",
506 "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S",
507 "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n",
508 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
509 "AREA:portamount#FF6464:portscans",
510 "GPRINT:portamount:MAX: Max\\: %2.2lf %S",
511 "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S",
512 "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min");
513 $ERROR = RRDs
::error
;
514 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
516 RRDs
::graph
("$graphs/firewallhits-$interval-line.png",
517 "--start", "-1$interval", "-aPNG", "-i", "-z",
518 "--alt-y-grid", "-w 600", "-h 200",
519 "--color", "SHADEA#EAE9EE",
520 "--color", "SHADEB#EAE9EE",
521 "--color", "BACK#FFFFFF",
522 "-t firewall hits over the last $interval",
523 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
524 "LINE2:amount#6464FF:firewallhits",
525 "GPRINT:amount:MAX: Max\\: %2.2lf %S",
526 "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S",
527 "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n",
528 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
529 "LINE2:portamount#FF6464:portscans",
530 "GPRINT:portamount:MAX: Max\\: %2.2lf %S",
531 "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S",
532 "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min");
533 $ERROR = RRDs
::error
;
534 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
537 sub updatefwhitsdata
{
544 if (! -e
"$rrdlog/firewallhits.rrd")
546 RRDs
::create
("$rrdlog/firewallhits.rrd", "--step=300",
547 "DS:amount:GAUGE:600:0:U",
548 "DS:portamount:GAUGE:600:0:U",
549 "RRA:AVERAGE:0.5:1:576",
550 "RRA:AVERAGE:0.5:6:672",
551 "RRA:AVERAGE:0.5:24:732",
552 "RRA:AVERAGE:0.5:144:1460");
553 $ERROR = RRDs
::error
;
554 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
557 system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
558 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
564 if (/kernel:.*(IN=.*)$/) {
571 system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
572 if (!(open (FILE
,'/tmp/snort.fwhits'))) {
585 if (!(open (FILE
,'/tmp/messages.fwhits'))) {
591 if (/kernel:.*(Scan.*)$/) {
598 system("rm /tmp/messages.fwhits");
599 system("rm /tmp/snort.fwhits");
601 $portamount = $portaktuell + $alertaktuell;
603 RRDs
::update
("$rrdlog/firewallhits.rrd",
604 "N:$aktuell:$portamount");
605 $ERROR = RRDs
::error
;
606 print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
609 # Creates and updates a link quality database
610 # -------------------------------------------
612 if ( ! -e
"$rrdlog/lq.rrd") {
613 RRDs
::create
("$rrdlog/lq.rrd", "--step=300",
614 "DS:loss:GAUGE:600:0:100",
615 "DS:roundtrip:GAUGE:600:0:10000",
616 "RRA:AVERAGE:0.5:1:576",
617 "RRA:AVERAGE:0.5:6:672",
618 "RRA:AVERAGE:0.5:24:732",
619 "RRA:AVERAGE:0.5:144:1460");
620 $ERROR = RRDs
::error
;
621 print "Error in RRD::create for link: $ERROR\n" if $ERROR;
626 # LQ_GATEWAY is the ip of your isp's public ip facing you
627 my $LQ_GATEWAY='www.heise.de';
629 my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
631 my @temp = split (/\/|\
%|\s
/, $pingoutput);
632 $packetloss = $temp[17];
633 $roundtrip = $temp[28];
634 RRDs
::update
("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
635 $ERROR = RRDs
::error
;
636 print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
641 RRDs
::graph
("$graphs/lq-$period.png",
642 "--start", "-1$period", "-aPNG", "-i", "-z",
643 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
644 "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
646 "--color", "SHADEA#EAE9EE",
647 "--color", "SHADEB#EAE9EE",
648 "--color", "BACK#FFFFFF",
649 "-v ms / pkts (% x10)",
650 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
651 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
652 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
653 "CDEF:loss10=loss,10,*",
654 "CDEF:r0=roundtrip,30,MIN",
655 "CDEF:r1=roundtrip,70,MIN",
656 "CDEF:r2=roundtrip,150,MIN",
657 "CDEF:r3=roundtrip,300,MIN",
658 "AREA:roundtrip#EE7000:>300 ms",
659 "AREA:r3#D88E1B:150-300 ms",
660 "AREA:r2#B9B63F:70-150 ms",
661 "AREA:r1#99E064:30-70 ms",
662 "AREA:r0#80FF80:<30 ms",
663 "AREA:loss10#800000:Packet loss (x10)",
664 "LINE1:roundtrip#707070:",
665 "GPRINT:roundtrip:MAX:$tr{'maximal'} $tr{'linkq'}\\:%3.2lf ms",
666 "GPRINT:roundtrip:AVERAGE:$tr{'average'} $tr{'linkq'}\\:%3.2lf ms",
667 "GPRINT:roundtrip:LAST:$tr{'current'} $tr{'linkq'}\\:%3.2lf ms\\j",
668 "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
669 "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
670 "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
672 $ERROR = RRDs
::error
;
673 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
678 if ( ! -e
"$rrdlog/hddtemp.rrd")
680 # database did not exist -> create
681 RRDs
::create
("$rrdlog/hddtemp.rrd", "--step=300",
682 "DS:temperature:GAUGE:600:0:100",
683 "RRA:AVERAGE:0.5:1:576",
684 "RRA:AVERAGE:0.5:6:672",
685 "RRA:AVERAGE:0.5:24:732",
686 "RRA:AVERAGE:0.5:144:1460");
687 $ERROR = RRDs
::error
;
688 print "Error in RRD::create for hdd: $ERROR\n" if $ERROR;
691 my $hdd_output = `/usr/sbin/hddtemp -qn $hdd_device`;
693 # I know 4 response possible responses:
695 # /dev/harddisk: harddisk type: S.M.A.R.T. not available
696 # /dev/harddisk: harddisk type: no sensor
697 # /dev/harddisk: harddisk type: 37°C or °F
700 if ( index($hdd_output, "S.M.A.R.T.") != -1 )
704 elsif ( index($hdd_output, "no sensor") != -1 )
708 elsif ( index($hdd_output, "$hdd_device") != -1 )
710 $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
715 $hdd_output =~ /(\d+)\s/;
719 RRDs
::update
("$rrdlog/hddtemp.rrd", "-t", "temperature", "N:$temp");
721 $ERROR = RRDs
::error
;
722 print "Error in RRD::update for hdd: $ERROR\n" if $ERROR;
728 RRDs
::graph
("$graphs/hddtemp-$period.png",
729 "--start", "-1$period", "-aPNG", "-i", "-z",
730 "--alt-y-grid", "-w 600", "-h 100",
731 "--color", "SHADEA#EAE9EE",
732 "--color", "SHADEB#EAE9EE",
733 "--color", "BACK#FFFFFF",
734 "-t $tr{'harddisk temperature'} ($tr{'graph per'} $tr{$period})",
735 "DEF:temperature=$rrdlog/hddtemp.rrd:temperature:AVERAGE",
736 "LINE2:temperature#0000FF:$tr{'hdd temperature in'} °C",
737 "GPRINT:temperature:MAX:$tr{'maximal'}\\:%3.0lf °C",
738 "GPRINT:temperature:AVERAGE:$tr{'average'}\\:%3.0lf °C",
739 "GPRINT:temperature:LAST:$tr{'current'}\\:%3.0lf °C",
741 $ERROR = RRDs
::error
;
742 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
746 system ('/usr/sbin/fetchipac');
752 if ( -e
"/var/log/squid/access.log") {
753 system ("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
759 if ((${Lang
::language
} eq 'cs') ||
760 (${Lang
::language
} eq 'hu') ||
761 (${Lang
::language
} eq 'pl') ||
762 (${Lang
::language
} eq 'sk')) {
763 # Czech, Hungarian, Polish and Slovak character set
764 foreach my $key(keys %Lang::tr
) {
765 from_to
($tr{$key}, "utf-8", "iso-8859-2");
767 } elsif (${Lang
::language
} eq 'tr') {
769 foreach my $key(keys %Lang::tr
) {
770 from_to
($tr{$key}, "utf-8", "iso-8859-9");
773 foreach my $key(keys %Lang::tr
) {
774 from_to
($tr{$key}, "utf-8", "iso-8859-1");
782 updatecpugraph
("day");
783 updatecpugraph
("week");
784 updatecpugraph
("month");
785 updatecpugraph
("year");
788 updatememgraph
("day");
789 updatememgraph
("week");
790 updatememgraph
("month");
791 updatememgraph
("year");
794 updatediskgraph
("day");
795 updatediskgraph
("week");
796 updatediskgraph
("month");
797 updatediskgraph
("year");
799 if (open STAT
,"/dev/hda") {
801 updatediskdatanew
("hda");
802 updatediskgraphnew
("hda","day");
803 updatediskgraphnew
("hda","week");
804 updatediskgraphnew
("hda","month");
805 updatediskgraphnew
("hda","year");
807 if (-e
"$graphs/disk-hda-day.png") {
808 system("rm $graphs/disk-hda-day.png");
812 if (open STAT
,"/dev/hdb") {
814 updatediskdatanew
("hdb");
815 updatediskgraphnew
("hdb","day");
816 updatediskgraphnew
("hdb","week");
817 updatediskgraphnew
("hdb","month");
818 updatediskgraphnew
("hdb","year");
820 if (-e
"$graphs/disk-hdb-day.png") {
821 system("rm $graphs/disk-hdb-day.png");
825 if (open STAT
,"/dev/hdc") {
827 updatediskdatanew
("hdc");
828 updatediskgraphnew
("hdc","day");
829 updatediskgraphnew
("hdc","week");
830 updatediskgraphnew
("hdc","month");
831 updatediskgraphnew
("hdc","year");
833 if (-e
"$graphs/disk-hdc-day.png") {
834 system("rm $graphs/disk-hdc-day.png");
838 if (open STAT
,"/dev/hdd") {
840 updatediskdatanew
("hdd");
841 updatediskgraphnew
("hdd","day");
842 updatediskgraphnew
("hdd","week");
843 updatediskgraphnew
("hdd","month");
844 updatediskgraphnew
("hdd","year");
846 if (-e
"$graphs/disk-hdd-day.png") {
847 system("rm $graphs/disk-hdd-day.png");
851 if (open STAT
,"/dev/hde") {
853 updatediskdatanew
("hde");
854 updatediskgraphnew
("hde","day");
855 updatediskgraphnew
("hde","week");
856 updatediskgraphnew
("hde","month");
857 updatediskgraphnew
("hde","year");
859 if (-e
"$graphs/disk-hde-day.png") {
860 system("rm $graphs/disk-hde-day.png");
864 if (open STAT
,"/dev/hdf") {
866 updatediskdatanew
("hdf");
867 updatediskgraphnew
("hdf","day");
868 updatediskgraphnew
("hdf","week");
869 updatediskgraphnew
("hdf","month");
870 updatediskgraphnew
("hdf","year");
872 if (-e
"$graphs/disk-hdf-day.png") {
873 system("rm $graphs/disk-hdf-day.png");
877 if (open STAT
,"/dev/hdg") {
879 updatediskdatanew
("hdg");
880 updatediskgraphnew
("hdg","day");
881 updatediskgraphnew
("hdg","week");
882 updatediskgraphnew
("hdg","month");
883 updatediskgraphnew
("hdg","year");
885 if (-e
"$graphs/disk-hdg-day.png") {
886 system("rm $graphs/disk-hdg-day.png");
890 if (open STAT
,"/dev/hdh") {
892 updatediskdatanew
("hdh");
893 updatediskgraphnew
("hdh","day");
894 updatediskgraphnew
("hdh","week");
895 updatediskgraphnew
("hdh","month");
896 updatediskgraphnew
("hdh","year");
898 if (-e
"$graphs/disk-hdh-day.png") {
899 system("rm $graphs/disk-hdh-day.png");
907 updatefwhitsgraph
("day");
908 updatefwhitsgraph
("week");
909 updatefwhitsgraph
("month");
910 updatefwhitsgraph
("year");
917 updatelqgraph
("day");
918 updatelqgraph
("week");
919 updatelqgraph
("month");
920 updatelqgraph
("year");
923 ### HDDTEMP-Graphs for /dev/harddisk
926 updatehddgraph
("day");
927 updatehddgraph
("week");
928 updatehddgraph
("month");
929 updatehddgraph
("year");
934 @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
936 updateifdata
("GREEN");
937 updateifdata
("RED");
938 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) {
939 updateifdata
("ORANGE");
941 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) {
942 updateifdata
("BLUE");
945 if ( -e
"$rrdlog/GREEN.rrd") {
946 updateifgraph
("GREEN", "day");
947 updateifgraph
("GREEN", "week");
948 updateifgraph
("GREEN", "month");
949 updateifgraph
("GREEN", "year");
952 if ( -e
"$rrdlog/RED.rrd") {
953 updateifgraph
("RED", "day");
954 updateifgraph
("RED", "week");
955 updateifgraph
("RED", "month");
956 updateifgraph
("RED", "year");
959 if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e
"$rrdlog/ORANGE.rrd") {
960 updateifgraph
("ORANGE", "day");
961 updateifgraph
("ORANGE", "week");
962 updateifgraph
("ORANGE", "month");
963 updateifgraph
("ORANGE", "year");
966 if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e
"$rrdlog/BLUE.rrd") {
967 updateifgraph
("BLUE", "day");
968 updateifgraph
("BLUE", "week");
969 updateifgraph
("BLUE", "month");
970 updateifgraph
("BLUE", "year");
973 #chmod 777 /home/httpd/html/{graphs,sgraph} -R
974 system("chmod -R 0777 /home/httpd/html/graphs");
975 system("chmod -R 0777 /home/httpd/html/sgraph");