]>
Commit | Line | Data |
---|---|---|
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 | ############################################################################ | |
24 | # | |
25 | # $Id: makegraphs,v 1.19.2.18 2006/01/08 13:41:04 eoberlander Exp $ | |
26 | # | |
27 | use strict; | |
28 | #use warnings; | |
29 | ||
30 | use RRDs; | |
31 | require "CONFIG_ROOT/general-functions.pl"; | |
32 | require "${General::swroot}/lang.pl"; | |
33 | ||
34 | my (%settings, @ipacsum, $iface, $ERROR); | |
35 | &General::readhash("${General::swroot}/ethernet/settings", \%settings); | |
36 | ||
37 | # Added for conversion of utf-8 characters | |
38 | use Encode 'from_to'; | |
39 | my %tr=(); | |
40 | ||
41 | # Force language back to English (ugly hack!) | |
42 | # Modified to only force if we are unable to convert charset | |
43 | # from utf-8 | |
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"`; | |
52 | } else { | |
53 | %tr=%Lang::tr; # use translated version for other languages | |
54 | } | |
55 | ||
56 | # Settings | |
57 | my $rrdlog = "/var/log/rrd"; | |
58 | my $graphs = "/home/httpd/html/graphs"; | |
59 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; | |
60 | ||
61 | sub gettraffic { | |
62 | my $interface = $_[0]; | |
63 | ||
64 | my $bytesin=0; | |
65 | my $bytesout=0; | |
66 | ||
67 | foreach (@ipacsum) | |
68 | { | |
69 | # Incoming... | |
70 | $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/); | |
71 | ||
72 | # Forwarded Incoming... | |
73 | $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/); | |
74 | ||
75 | # Outgoing... | |
76 | $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/); | |
77 | ||
78 | # Forwarded Outgoing... | |
79 | $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/); | |
80 | } | |
81 | return "$bytesin:$bytesout"; | |
82 | } | |
83 | ||
84 | sub updatecpugraph { | |
85 | my $period = $_[0]; | |
86 | ||
87 | RRDs::graph ("$graphs/cpu-$period.png", | |
88 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
89 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", | |
90 | "--color", "SHADEA#EAE9EE", | |
91 | "--color", "SHADEB#EAE9EE", | |
92 | "--color", "BACK#EAE9EE", | |
93 | "-t $tr{'cpu usage per'} $tr{$period}", | |
94 | "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE", | |
95 | "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE", | |
96 | "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE", | |
97 | "CDEF:total=user,system,idle,+,+", | |
98 | "CDEF:userpct=100,user,total,/,*", | |
99 | "CDEF:systempct=100,system,total,/,*", | |
100 | "CDEF:idlepct=100,idle,total,/,*", | |
101 | "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j", | |
102 | "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j", | |
103 | "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j", | |
104 | "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%", | |
105 | "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%", | |
106 | "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j", | |
107 | "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%", | |
108 | "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%", | |
109 | "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j", | |
110 | "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%", | |
111 | "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%", | |
112 | "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j"); | |
113 | $ERROR = RRDs::error; | |
114 | print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR; | |
115 | } | |
116 | ||
117 | sub updatecpudata { | |
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 | "RRA:AVERAGE:0.5:1:576", | |
124 | "RRA:AVERAGE:0.5:6:672", | |
125 | "RRA:AVERAGE:0.5:24:732", | |
126 | "RRA:AVERAGE:0.5:144:1460"); | |
127 | $ERROR = RRDs::error; | |
128 | print "Error in RRD::create for cpu: $ERROR\n" if $ERROR; | |
129 | } | |
130 | ||
131 | my ($cpu, $user, $nice, $system, $idle); | |
132 | ||
133 | open STAT, "/proc/stat"; | |
134 | while(<STAT>) { | |
135 | chomp; | |
136 | /^cpu\s/ or next; | |
137 | ($cpu, $user, $nice, $system, $idle) = split /\s+/; | |
138 | last; | |
139 | } | |
140 | close STAT; | |
141 | $user += $nice; | |
142 | ||
143 | RRDs::update ("$rrdlog/cpu.rrd", | |
144 | "-t", "user:system:idle", | |
145 | "N:$user:$system:$idle"); | |
146 | $ERROR = RRDs::error; | |
147 | print "Error in RRD::update for cpu: $ERROR\n" if $ERROR; | |
148 | ||
149 | } | |
150 | ||
151 | sub updatememgraph { | |
152 | my $period = $_[0]; | |
153 | ||
154 | RRDs::graph ("$graphs/memory-$period.png", | |
155 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
156 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", | |
157 | "--color", "SHADEA#EAE9EE", | |
158 | "--color", "SHADEB#EAE9EE", | |
159 | "--color", "BACK#EAE9EE", | |
160 | "-t $tr{'memory usage per'} $tr{$period}", | |
161 | "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE", | |
162 | "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE", | |
163 | "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE", | |
164 | "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE", | |
165 | "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE", | |
166 | "CDEF:total=used,free,+", | |
167 | "CDEF:used2=used,buffer,cache,shared,+,+,-", | |
168 | "CDEF:usedpct=100,used2,total,/,*", | |
169 | "CDEF:sharedpct=100,shared,total,/,*", | |
170 | "CDEF:bufferpct=100,buffer,total,/,*", | |
171 | "CDEF:cachepct=100,cache,total,/,*", | |
172 | "CDEF:freepct=100,free,total,/,*", | |
173 | "AREA:usedpct#0000FF:$tr{'used memory'}\\j", | |
174 | "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j", | |
175 | "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j", | |
176 | "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j", | |
177 | "STACK:freepct#00FF00:$tr{'free memory'}\\j", | |
178 | "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%", | |
179 | "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%", | |
180 | "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j", | |
181 | "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%", | |
182 | "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%", | |
183 | "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j", | |
184 | "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%", | |
185 | "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%", | |
186 | "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j", | |
187 | "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%", | |
188 | "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%", | |
189 | "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j", | |
190 | "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%", | |
191 | "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%", | |
192 | "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j"); | |
193 | $ERROR = RRDs::error; | |
194 | print "Error in RRD::graph for mem: $ERROR\n" if $ERROR; | |
195 | ||
196 | RRDs::graph ("$graphs/swap-$period.png", | |
197 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
198 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", | |
199 | "--color", "SHADEA#EAE9EE", | |
200 | "--color", "SHADEB#EAE9EE", | |
201 | "--color", "BACK#EAE9EE", | |
202 | "-t $tr{'swap usage per'} $tr{$period}", | |
203 | "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE", | |
204 | "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE", | |
205 | "CDEF:total=used,free,+", | |
206 | "CDEF:usedpct=100,used,total,/,*", | |
207 | "CDEF:freepct=100,free,total,/,*", | |
208 | "AREA:usedpct#0000FF:$tr{'used swap'}\\j", | |
209 | "STACK:freepct#00FF00:$tr{'free swap'}\\j", | |
210 | "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%", | |
211 | "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%", | |
212 | "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j", | |
213 | "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%", | |
214 | "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%", | |
215 | "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j"); | |
216 | $ERROR = RRDs::error; | |
217 | print "Error in RRD::graph for swap: $ERROR\n" if $ERROR; | |
218 | } | |
219 | ||
220 | sub updatememdata { | |
221 | my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree); | |
222 | if ( ! -e "$rrdlog/mem.rrd") { | |
223 | RRDs::create ("$rrdlog/mem.rrd", "--step=300", | |
224 | "DS:memused:ABSOLUTE:600:0:5000000000", | |
225 | "DS:memfree:ABSOLUTE:600:0:5000000000", | |
226 | "DS:memshared:ABSOLUTE:600:0:5000000000", | |
227 | "DS:membuffers:ABSOLUTE:600:0:5000000000", | |
228 | "DS:memcache:ABSOLUTE:600:0:5000000000", | |
229 | "DS:swapused:ABSOLUTE:600:0:5000000000", | |
230 | "DS:swapfree:ABSOLUTE: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 mem: $ERROR\n" if $ERROR; | |
237 | } | |
238 | ||
239 | open MEM, "/proc/meminfo"; | |
240 | while(<MEM>) { | |
241 | chomp; | |
242 | if ($_ =~ /^Mem:/) { | |
243 | my @temp = split (/\s+/, $_); | |
244 | $memused = $temp[2]; | |
245 | $memfree = $temp[3]; | |
246 | $memshared = $temp[4]; | |
247 | $membuffers = $temp[5]; | |
248 | $memcache = $temp[6]; | |
249 | } elsif ($_ =~ /^Swap:/) { | |
250 | my @temp = split (/\s+/, $_); | |
251 | $swapused = $temp[2]; | |
252 | $swapfree = $temp[3]; | |
253 | } | |
254 | } | |
255 | close MEM; | |
256 | ||
257 | RRDs::update ("$rrdlog/mem.rrd", | |
258 | "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree", | |
259 | "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree"); | |
260 | $ERROR = RRDs::error; | |
261 | print "Error in RRD::update for mem: $ERROR\n" if $ERROR; | |
262 | } | |
263 | ||
264 | sub updatediskgraph { | |
265 | my $period = $_[0]; | |
266 | ||
267 | RRDs::graph ("$graphs/disk-$period.png", | |
268 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
269 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r", | |
270 | "--color", "SHADEA#EAE9EE", | |
271 | "--color", "SHADEB#EAE9EE", | |
272 | "--color", "BACK#EAE9EE", | |
273 | "-t $tr{'disk access per'} $tr{$period}", | |
274 | "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE", | |
275 | "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE", | |
276 | "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j", | |
277 | "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j", | |
278 | "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf", | |
279 | "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf", | |
280 | "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j", | |
281 | "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf", | |
282 | "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf", | |
283 | "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j"); | |
284 | $ERROR = RRDs::error; | |
285 | print "Error in RRD::graph for disk: $ERROR\n" if $ERROR; | |
286 | } | |
287 | ||
288 | sub updatediskdata { | |
289 | my ($readwritereq, $readreq, $readsect, $writereq, $writesect); | |
290 | if ( ! -e "$rrdlog/disk.rrd") { | |
291 | RRDs::create ("$rrdlog/disk.rrd", "--step=300", | |
292 | "DS:readsect:COUNTER:600:0:5000000000", | |
293 | "DS:writesect:COUNTER:600:0:5000000000", | |
294 | "RRA:AVERAGE:0.5:1:576", | |
295 | "RRA:AVERAGE:0.5:6:672", | |
296 | "RRA:AVERAGE:0.5:24:732", | |
297 | "RRA:AVERAGE:0.5:144:1460"); | |
298 | $ERROR = RRDs::error; | |
299 | print "Error in RRD::create for disk: $ERROR\n" if $ERROR; | |
300 | } | |
301 | ||
302 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
303 | $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk"); | |
304 | ||
305 | my $major = $rdev >> 8; | |
306 | my $minor = $rdev & 0xFF; | |
307 | ||
308 | open STAT, "/proc/stat"; | |
309 | my @diskstat = <STAT>; | |
310 | close (STAT); | |
311 | foreach my $line (@diskstat) | |
312 | { | |
313 | chomp ($line); | |
314 | my @temp = split(/\:\ /,$line); | |
315 | if ($temp[1]) { | |
316 | my @devicestat = split(/\ /,$temp[1]); | |
317 | foreach my $stats (@devicestat) | |
318 | { | |
319 | chomp ($stats); | |
320 | my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats); | |
321 | if ($major eq $fields[1] and $minor eq $fields[2]) | |
322 | { | |
323 | $readwritereq = $fields[3]; | |
324 | $readreq = $fields[4]; | |
325 | $readsect = $fields[5]; | |
326 | $writereq = $fields[6]; | |
327 | $writesect = $fields[7]; | |
328 | } | |
329 | } | |
330 | } | |
331 | } | |
332 | ||
333 | if ($readsect && $writesect) { | |
334 | RRDs::update ("$rrdlog/disk.rrd", | |
335 | "-t", "readsect:writesect", | |
336 | "N:$readsect:$writesect"); | |
337 | $ERROR = RRDs::error; | |
338 | print "Error in RRD::update for disk: $ERROR\n" if $ERROR; | |
339 | } else { | |
340 | print "Error in RRD::update for disk: no data available\n"; | |
341 | } | |
342 | } | |
343 | ||
344 | sub updateifgraph { | |
345 | my $interface = $_[0]; | |
346 | my $period = $_[1]; | |
347 | ||
348 | RRDs::graph ("$graphs/$interface-$period.png", | |
349 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
350 | "--alt-y-grid", "-w 600", "-h 100", | |
351 | "--color", "SHADEA#EAE9EE", | |
352 | "--color", "SHADEB#EAE9EE", | |
353 | "--color", "BACK#EAE9EE", | |
354 | "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})", | |
355 | "-v$tr{'bytes per second'}", | |
356 | "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE", | |
357 | "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE", | |
358 | "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j", | |
359 | "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j", | |
360 | "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps", | |
361 | "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps", | |
362 | "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j", | |
363 | "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps", | |
364 | "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps", | |
365 | "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j"); | |
366 | $ERROR = RRDs::error; | |
367 | print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR; | |
368 | } | |
369 | ||
370 | sub updateifdata { | |
371 | my $interface = $_[0]; | |
372 | ||
373 | if ( ! -e "$rrdlog/$interface.rrd") { | |
374 | RRDs::create ("$rrdlog/$interface.rrd", "--step=300", | |
375 | "DS:incoming:ABSOLUTE:600:0:12500000", | |
376 | "DS:outgoing:ABSOLUTE:600:0:12500000", | |
377 | "RRA:AVERAGE:0.5:1:576", | |
378 | "RRA:AVERAGE:0.5:6:672", | |
379 | "RRA:AVERAGE:0.5:24:732", | |
380 | "RRA:AVERAGE:0.5:144:1460"); | |
381 | $ERROR = RRDs::error; | |
382 | print "Error in RRD::create for $interface: $ERROR\n" if $ERROR; | |
383 | } | |
384 | ||
385 | my $traffic = gettraffic ($interface); | |
386 | RRDs::update ("$rrdlog/$interface.rrd", | |
387 | "-t", "incoming:outgoing", | |
388 | "N:$traffic"); | |
389 | $ERROR = RRDs::error; | |
390 | print "Error in RRD::update for $interface: $ERROR\n" if $ERROR; | |
391 | } | |
392 | ||
df8c7810 MT |
393 | sub updatefwhitsgraph { |
394 | my $interval = $_[0]; | |
395 | ||
396 | RRDs::graph ("$graphs/firewallhits-$interval-area.png", | |
397 | "--start", "-1$interval", "-aPNG", "-i", "-z", | |
072cd997 | 398 | "--alt-y-grid", "-w 600", "-h 200", |
df8c7810 MT |
399 | "--color", "SHADEA#EAE9EE", |
400 | "--color", "SHADEB#EAE9EE", | |
401 | "--color", "BACK#EAE9EE", | |
402 | "-t firewall hits over the last $interval", | |
403 | "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE", | |
404 | "AREA:amount#6464FF:firewallhits", | |
405 | "GPRINT:amount:MAX: Max\\: %2.2lf %S", | |
406 | "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S", | |
407 | "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n", | |
408 | "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE", | |
409 | "AREA:portamount#FF6464:portscans", | |
410 | "GPRINT:portamount:MAX: Max\\: %2.2lf %S", | |
411 | "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S", | |
412 | "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min"); | |
413 | $ERROR = RRDs::error; | |
414 | print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR; | |
415 | ||
416 | RRDs::graph ("$graphs/firewallhits-$interval-line.png", | |
417 | "--start", "-1$interval", "-aPNG", "-i", "-z", | |
072cd997 | 418 | "--alt-y-grid", "-w 600", "-h 200", |
df8c7810 MT |
419 | "--color", "SHADEA#EAE9EE", |
420 | "--color", "SHADEB#EAE9EE", | |
421 | "--color", "BACK#EAE9EE", | |
422 | "-t firewall hits over the last $interval", | |
423 | "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE", | |
424 | "LINE2:amount#6464FF:firewallhits", | |
425 | "GPRINT:amount:MAX: Max\\: %2.2lf %S", | |
426 | "GPRINT:amount:AVERAGE: Avg\\: %2.2lf %S", | |
427 | "GPRINT:amount:LAST: Current\\: %2.2lf %Shits/5 min\\n", | |
428 | "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE", | |
429 | "LINE2:portamount#FF6464:portscans", | |
430 | "GPRINT:portamount:MAX: Max\\: %2.2lf %S", | |
431 | "GPRINT:portamount:AVERAGE: Avg\\: %2.2lf %S", | |
432 | "GPRINT:portamount:LAST: Current\\: %2.2lf %Shits/5 min"); | |
433 | $ERROR = RRDs::error; | |
434 | print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR; | |
435 | } | |
436 | ||
437 | sub updatefwhitsdata { | |
438 | my $portamount=0; | |
439 | my $alertaktuell=0; | |
440 | my $aktuell=0; | |
441 | my $portaktuell=0; | |
442 | my $skip=0; | |
443 | ||
444 | if (! -e "$rrdlog/firewallhits.rrd") | |
445 | { | |
446 | RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300", | |
447 | "DS:amount:GAUGE:600:0:U", | |
448 | "DS:portamount:GAUGE:600:0:U", | |
449 | "RRA:AVERAGE:0.5:1:576", | |
450 | "RRA:AVERAGE:0.5:6:672", | |
451 | "RRA:AVERAGE:0.5:24:732", | |
452 | "RRA:AVERAGE:0.5:144:1460"); | |
453 | $ERROR = RRDs::error; | |
454 | print "Error in RRD::create for cpu: $ERROR\n" if $ERROR; | |
455 | } | |
456 | ||
457 | system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits"); | |
458 | if (!(open (FILE,'/tmp/messages.fwhits'))) { | |
459 | $skip=1; | |
460 | } | |
461 | $aktuell = 0; | |
462 | if (!$skip) { | |
463 | while (<FILE>) { | |
464 | if (/kernel:.*(IN=.*)$/) { | |
465 | $aktuell++; | |
466 | } | |
467 | } | |
468 | close (FILE); | |
469 | } | |
470 | ||
471 | system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits"); | |
472 | if (!(open (FILE,'/tmp/snort.fwhits'))) { | |
473 | $skip=1; | |
474 | } | |
475 | $alertaktuell = 0; | |
476 | if (!$skip) { | |
477 | while (<FILE>) { | |
478 | if (/scan.*$/) { | |
479 | $alertaktuell++; | |
480 | } | |
481 | } | |
482 | close (FILE); | |
483 | } | |
484 | ||
485 | if (!(open (FILE,'/tmp/messages.fwhits'))) { | |
486 | $skip=1; | |
487 | } | |
488 | $portaktuell = 0; | |
489 | if (!$skip) { | |
490 | while (<FILE>) { | |
491 | if (/kernel:.*(Scan.*)$/) { | |
492 | $portaktuell++; | |
493 | } | |
494 | } | |
495 | close (FILE); | |
496 | } | |
497 | ||
498 | system("rm /tmp/messages.fwhits"); | |
499 | system("rm /tmp/snort.fwhits"); | |
500 | ||
501 | $portamount = $portaktuell + $alertaktuell; | |
502 | chomp($portamount); | |
503 | RRDs::update ("$rrdlog/firewallhits.rrd", | |
504 | "N:$aktuell:$portamount"); | |
505 | $ERROR = RRDs::error; | |
506 | print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR; | |
507 | } | |
508 | ||
072cd997 MT |
509 | # Creates and updates a link quality database |
510 | # ------------------------------------------- | |
511 | sub updatelq { | |
512 | if ( ! -e "$rrdlog/lq.rrd") { | |
513 | RRDs::create ("$rrdlog/lq.rrd", "--step=300", | |
514 | "DS:loss:GAUGE:600:0:100", | |
515 | "DS:roundtrip:GAUGE:600:0:10000", | |
516 | "RRA:AVERAGE:0.5:1:576", | |
517 | "RRA:AVERAGE:0.5:6:672", | |
518 | "RRA:AVERAGE:0.5:24:732", | |
519 | "RRA:AVERAGE:0.5:144:1460"); | |
520 | $ERROR = RRDs::error; | |
521 | print "Error in RRD::create for link: $ERROR\n" if $ERROR; | |
522 | } | |
523 | my $packetloss=0; | |
524 | my $roundtrip=0; | |
525 | my $test=0; | |
526 | # LQ_GATEWAY is the ip of your isp's public ip facing you | |
527 | my $LQ_GATEWAY=`netstat -r | grep ^default | awk '{print \$2}'`; | |
528 | my $NUMPINGS=10; | |
529 | my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`; | |
530 | chomp; | |
531 | my @temp = split (/\/|\%|\s/, $pingoutput); | |
532 | $packetloss = $temp[17]; | |
533 | $roundtrip = $temp[28]; | |
534 | RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip"); | |
535 | $ERROR = RRDs::error; | |
536 | print "Error in RRD::update for line quality: $ERROR\n" if $ERROR; | |
537 | } | |
538 | ||
539 | sub updatelqgraph { | |
540 | my $period = $_[0]; | |
541 | RRDs::graph ("$graphs/lq-$period.png", | |
542 | "--start", "-1$period", "-aPNG", "-i", "-z", | |
543 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r", | |
544 | "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})", | |
545 | "--lazy", | |
546 | "--color", "SHADEA#EAE9EE", | |
547 | "--color", "SHADEB#EAE9EE", | |
548 | "--color", "BACK#EAE9EE", | |
549 | "-v ms / pkts (% x10)", | |
550 | "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE", | |
551 | "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE", | |
552 | "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/", | |
553 | "CDEF:loss10=loss,10,*", | |
554 | "CDEF:r0=roundtrip,30,MIN", | |
555 | "CDEF:r1=roundtrip,70,MIN", | |
556 | "CDEF:r2=roundtrip,150,MIN", | |
557 | "CDEF:r3=roundtrip,300,MIN", | |
558 | "AREA:roundtrip#EE7000:>300 ms", | |
559 | "AREA:r3#D88E1B:150-300 ms", | |
560 | "AREA:r2#B9B63F:70-150 ms", | |
561 | "AREA:r1#99E064:30-70 ms", | |
562 | "AREA:r0#80FF80:<30 ms", | |
563 | "AREA:loss10#800000:Packet loss (x10)", | |
564 | "LINE1:roundtrip#707070:", | |
565 | "GPRINT:roundtrip:MAX:$tr{'maximal'} $tr{'linkq'}\\:%3.2lf ms", | |
566 | "GPRINT:roundtrip:AVERAGE:$tr{'average'} $tr{'linkq'}\\:%3.2lf ms", | |
567 | "GPRINT:roundtrip:LAST:$tr{'current'} $tr{'linkq'}\\:%3.2lf ms\\j", | |
568 | "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%", | |
569 | "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%", | |
570 | "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j" | |
571 | ); | |
572 | $ERROR = RRDs::error; | |
573 | print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR; | |
574 | } | |
575 | ||
cd1a2927 MT |
576 | ## Update ipac logs |
577 | system ('/usr/sbin/fetchipac'); | |
578 | sleep 8; | |
579 | ||
580 | ### | |
581 | ### Squid Graphs | |
582 | ### | |
583 | if ( -e "/var/log/squid/access.log") { | |
584 | system ("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1"); | |
585 | } | |
586 | ||
587 | ### | |
588 | ### utf8 conversion | |
589 | ### | |
590 | if ((${Lang::language} eq 'cs') || | |
591 | (${Lang::language} eq 'hu') || | |
592 | (${Lang::language} eq 'pl') || | |
593 | (${Lang::language} eq 'sk')) { | |
594 | # Czech, Hungarian, Polish and Slovak character set | |
595 | foreach my $key(keys %Lang::tr) { | |
596 | from_to($tr{$key}, "utf-8", "iso-8859-2"); | |
597 | } | |
598 | } elsif (${Lang::language} eq 'tr') { | |
599 | # Turkish | |
600 | foreach my $key(keys %Lang::tr) { | |
601 | from_to($tr{$key}, "utf-8", "iso-8859-9"); | |
602 | } | |
603 | } else { | |
604 | foreach my $key(keys %Lang::tr) { | |
605 | from_to($tr{$key}, "utf-8", "iso-8859-1"); | |
606 | } | |
607 | } | |
608 | ||
609 | ### | |
610 | ### System graphs | |
611 | ### | |
612 | updatecpudata(); | |
613 | updatecpugraph ("day"); | |
614 | updatecpugraph ("week"); | |
615 | updatecpugraph ("month"); | |
616 | updatecpugraph ("year"); | |
617 | ||
618 | updatememdata(); | |
619 | updatememgraph ("day"); | |
620 | updatememgraph ("week"); | |
621 | updatememgraph ("month"); | |
622 | updatememgraph ("year"); | |
623 | ||
624 | updatediskdata(); | |
625 | updatediskgraph ("day"); | |
626 | updatediskgraph ("week"); | |
627 | updatediskgraph ("month"); | |
628 | updatediskgraph ("year"); | |
629 | ||
df8c7810 MT |
630 | ### |
631 | ### Firewallhits | |
632 | ### | |
633 | updatefwhitsdata(); | |
634 | updatefwhitsgraph ("day"); | |
635 | updatefwhitsgraph ("week"); | |
636 | updatefwhitsgraph ("month"); | |
637 | updatefwhitsgraph ("year"); | |
638 | ||
072cd997 MT |
639 | ### |
640 | ### Link Quality | |
641 | ### | |
642 | updatelq(); | |
643 | sleep 2; | |
644 | updatelqgraph("day"); | |
645 | updatelqgraph("week"); | |
646 | updatelqgraph("month"); | |
647 | updatelqgraph("year"); | |
648 | ||
cd1a2927 MT |
649 | ### |
650 | ### Network Graphs | |
651 | ### | |
652 | @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`; | |
653 | if (@ipacsum) { | |
654 | updateifdata ("GREEN"); | |
655 | updateifdata ("RED"); | |
656 | if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) { | |
657 | updateifdata ("ORANGE"); | |
658 | } | |
659 | if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) { | |
660 | updateifdata ("BLUE"); | |
661 | } | |
662 | } | |
663 | if ( -e "$rrdlog/GREEN.rrd") { | |
664 | updateifgraph ("GREEN", "day"); | |
665 | updateifgraph ("GREEN", "week"); | |
666 | updateifgraph ("GREEN", "month"); | |
667 | updateifgraph ("GREEN", "year"); | |
668 | } | |
669 | ||
670 | if ( -e "$rrdlog/RED.rrd") { | |
671 | updateifgraph ("RED", "day"); | |
672 | updateifgraph ("RED", "week"); | |
673 | updateifgraph ("RED", "month"); | |
674 | updateifgraph ("RED", "year"); | |
675 | } | |
676 | ||
677 | if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e "$rrdlog/ORANGE.rrd") { | |
678 | updateifgraph ("ORANGE", "day"); | |
679 | updateifgraph ("ORANGE", "week"); | |
680 | updateifgraph ("ORANGE", "month"); | |
681 | updateifgraph ("ORANGE", "year"); | |
682 | } | |
683 | ||
684 | if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e "$rrdlog/BLUE.rrd") { | |
685 | updateifgraph ("BLUE", "day"); | |
686 | updateifgraph ("BLUE", "week"); | |
687 | updateifgraph ("BLUE", "month"); | |
688 | updateifgraph ("BLUE", "year"); | |
689 | } | |
3ea75603 | 690 | |
929a3bfc MT |
691 | #chmod 777 /home/httpd/html/{graphs,sgraph} -R |
692 | system("chmod -R 0777 /home/httpd/html/graphs"); | |
693 | system("chmod -R 0777 /home/httpd/html/sgraph"); | |
694 |