]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/graphs.pl
Corrected guardian
[people/pmueller/ipfire-2.x.git] / config / cfgroot / graphs.pl
1 #!/usr/bin/perl
2 # Generate Graphs exported from Makegraphs to minimize system load an only generate the Graphs when displayed
3 # This is part of the IPFire Firewall
4
5
6 package Graphs;
7
8 use strict;
9 use RRDs;
10
11 require '/var/ipfire/general-functions.pl';
12 require "${General::swroot}/lang.pl";
13 require "${General::swroot}/header.pl";
14
15 my $ERROR;
16 my $rrdlog = "/var/log/rrd";
17 my $graphs = "/srv/web/ipfire/html/graphs";
18 $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
19
20 my %color = ();
21 my %mainsettings = ();
22 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
23 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
24
25 my %mbmon_settings = ();
26 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
27
28 my %mbmon_values = ();
29 if ( -e "/var/log/mbmon-values" ){
30 &General::readhash("/var/log/mbmon-values", \%mbmon_values);
31 }
32
33 my $key;
34 my $value;
35 my @args = ();
36 my $count = 0;
37
38 use Encode 'from_to';
39
40 my %tr=();
41 if ((${Lang::language} eq 'el') ||
42 (${Lang::language} eq 'fa') ||
43 (${Lang::language} eq 'ru') ||
44 (${Lang::language} eq 'th') ||
45 (${Lang::language} eq 'vi') ||
46 (${Lang::language} eq 'zh') ||
47 (${Lang::language} eq 'zt')) {
48 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
49 } else {
50 %tr=%Lang::tr; # use translated version for other languages
51 }
52
53
54 sub updatecpugraph {
55 my $period = $_[0];
56
57 RRDs::graph ("$graphs/cpu-$period.png",
58 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",, "-v $Lang::tr{'percentage'}",
59 "--alt-y-grid", "-w 600", "-h 150", "-l 0", "-u 100", "-r",
60 "--color", "SHADEA".$color{"color19"},
61 "--color", "SHADEB".$color{"color19"},
62 "--color", "BACK".$color{"color21"},
63 "-t $Lang::tr{'cpu usage per'} $Lang::tr{$period}",
64 "DEF:iowait=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE",
65 "DEF:nice=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE",
66 "DEF:interrupt=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE",
67 "DEF:steal=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE",
68 "DEF:user=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE",
69 "DEF:system=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE",
70 "DEF:idle=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE",
71 "DEF:irq=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE",
72 "CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+",
73 "CDEF:userpct=100,user,total,/,*",
74 "CDEF:nicepct=100,nice,total,/,*",
75 "CDEF:interruptpct=100,interrupt,total,/,*",
76 "CDEF:stealpct=100,steal,total,/,*",
77 "CDEF:systempct=100,system,total,/,*",
78 "CDEF:idlepct=100,idle,total,/,*",
79 "CDEF:iowaitpct=100,iowait,total,/,*",
80 "CDEF:irqpct=100,irq,total,/,*",
81 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
82 "COMMENT:$Lang::tr{'maximal'}",
83 "COMMENT:$Lang::tr{'average'}",
84 "COMMENT:$Lang::tr{'minimal'}",
85 "COMMENT:$Lang::tr{'current'}\\j",
86 "AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'}),
87 "GPRINT:iowaitpct:MAX:%3.2lf%%",
88 "GPRINT:iowaitpct:AVERAGE:%3.2lf%%",
89 "GPRINT:iowaitpct:MIN:%3.2lf%%",
90 "GPRINT:iowaitpct:LAST:%3.2lf%%\\j",
91 "STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'}),
92 "GPRINT:irqpct:MAX:%3.2lf%%",
93 "GPRINT:irqpct:AVERAGE:%3.2lf%%",
94 "GPRINT:irqpct:MIN:%3.2lf%%",
95 "GPRINT:irqpct:LAST:%3.2lf%%\\j",
96 "STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'}),
97 "GPRINT:nicepct:MAX:%3.2lf%%",
98 "GPRINT:nicepct:AVERAGE:%3.2lf%%",
99 "GPRINT:nicepct:MIN:%3.2lf%%",
100 "GPRINT:nicepct:LAST:%3.2lf%%\\j",
101 "STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'}),
102 "GPRINT:interruptpct:MAX:%3.2lf%%",
103 "GPRINT:interruptpct:AVERAGE:%3.2lf%%",
104 "GPRINT:interruptpct:MIN:%3.2lf%%",
105 "GPRINT:interruptpct:LAST:%3.2lf%%\\j",
106 "STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'}),
107 "GPRINT:stealpct:MAX:%3.2lf%%",
108 "GPRINT:stealpct:AVERAGE:%3.2lf%%",
109 "GPRINT:stealpct:MIN:%3.2lf%%",
110 "GPRINT:stealpct:LAST:%3.2lf%%\\j",
111 "STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'}),
112 "GPRINT:userpct:MAX:%3.2lf%%",
113 "GPRINT:userpct:AVERAGE:%3.2lf%%",
114 "GPRINT:userpct:MIN:%3.2lf%%",
115 "GPRINT:userpct:LAST:%3.2lf%%\\j",
116 "STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'}),
117 "GPRINT:systempct:MAX:%3.2lf%%",
118 "GPRINT:systempct:AVERAGE:%3.2lf%%",
119 "GPRINT:systempct:MIN:%3.2lf%%",
120 "GPRINT:systempct:LAST:%3.2lf%%\\j",
121 "STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'}),
122 "GPRINT:idlepct:MAX:%3.2lf%%",
123 "GPRINT:idlepct:AVERAGE:%3.2lf%%",
124 "GPRINT:idlepct:MIN:%3.2lf%%",
125 "GPRINT:idlepct:LAST:%3.2lf%%\\j");
126 $ERROR = RRDs::error;
127 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
128 }
129
130 sub updateloadgraph {
131 my $period = $_[0];
132
133 RRDs::graph ("$graphs/load-$period.png",
134 "--start", "-1$period", "-aPNG",
135 "-w 600", "-h 150", "-i", "-z", "-W www.ipfire.org", "-l 0", "-r", "--alt-y-grid",
136 "-t Load Average $Lang::tr{'graph per'} $Lang::tr{$period}",
137 "--color", "SHADEA".$color{"color19"},
138 "--color", "SHADEB".$color{"color19"},
139 "--color", "BACK".$color{"color21"},
140 "DEF:load1=$rrdlog/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
141 "DEF:load5=$rrdlog/collectd/localhost/load/load.rrd:midterm:AVERAGE",
142 "DEF:load15=$rrdlog/collectd/localhost/load/load.rrd:longterm:AVERAGE",
143 "AREA:load1".$color{"color13"}."A0:1 Minute, letzter:",
144 "GPRINT:load1:LAST:%5.2lf",
145 "AREA:load5".$color{"color18"}."A0:5 Minuten, letzter:",
146 "GPRINT:load5:LAST:%5.2lf",
147 "AREA:load15".$color{"color14"}."A0:15 Minuten, letzter:",
148 "GPRINT:load15:LAST:%5.2lf\\j",
149 "LINE1:load5".$color{"color13"},
150 "LINE1:load1".$color{"color18"});
151 $ERROR = RRDs::error;
152 print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
153 }
154
155 sub updatememgraph {
156 my $period = $_[0];
157
158 RRDs::graph ("$graphs/memory-$period.png",
159 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
160 "--alt-y-grid", "-w 600", "-h 150", "-l 0", "-u 100", "-r",
161 "--color", "SHADEA".$color{"color19"},
162 "--color", "SHADEB".$color{"color19"},
163 "--color", "BACK".$color{"color21"},
164 "-t $Lang::tr{'memory usage per'} $Lang::tr{$period}",
165 "DEF:used=$rrdlog/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
166 "DEF:free=$rrdlog/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
167 "DEF:buffer=$rrdlog/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
168 "DEF:cache=$rrdlog/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
169 "CDEF:total=used,free,cache,buffer,+,+,+",
170 "CDEF:usedpct=used,total,/,100,*",
171 "CDEF:bufferpct=buffer,total,/,100,*",
172 "CDEF:cachepct=cache,total,/,100,*",
173 "CDEF:freepct=free,total,/,100,*",
174 "COMMENT:$Lang::".sprintf("%-29s",$Lang::tr{'caption'}),
175 "COMMENT:$Lang::tr{'maximal'}",
176 "COMMENT:$Lang::tr{'average'}",
177 "COMMENT:$Lang::tr{'minimal'}",
178 "COMMENT:$Lang::tr{'current'}\\j",
179 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used memory'}),
180 "GPRINT:usedpct:MAX:%3.2lf%%",
181 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
182 "GPRINT:usedpct:MIN:%3.2lf%%",
183 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
184 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'buffered memory'}),
185 "GPRINT:bufferpct:MAX:%3.2lf%%",
186 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
187 "GPRINT:bufferpct:MIN:%3.2lf%%",
188 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
189 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'cached memory'}),
190 "GPRINT:cachepct:MAX:%3.2lf%%",
191 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
192 "GPRINT:cachepct:MIN:%3.2lf%%",
193 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
194 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free memory'}),
195 "GPRINT:freepct:MAX:%3.2lf%%",
196 "GPRINT:freepct:AVERAGE:%3.2lf%%",
197 "GPRINT:freepct:MIN:%3.2lf%%",
198 "GPRINT:freepct:LAST:%3.2lf%%\\j");
199 $ERROR = RRDs::error;
200 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
201
202 RRDs::graph ("$graphs/swap-$period.png",
203 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
204 "--alt-y-grid", "-w 600", "-h 150", "-l 0", "-u 100", "-r",
205 "--color", "SHADEA".$color{"color19"},
206 "--color", "SHADEB".$color{"color19"},
207 "--color", "BACK".$color{"color21"},
208 "-t $Lang::tr{'swap usage per'} $Lang::tr{$period}",
209 "DEF:used=$rrdlog/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
210 "DEF:free=$rrdlog/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
211 "DEF:cached=$rrdlog/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
212 "CDEF:total=used,free,cached,+,+",
213 "CDEF:usedpct=100,used,total,/,*",
214 "CDEF:freepct=100,free,total,/,*",
215 "CDEF:cachedpct=100,cached,total,/,*",
216 "COMMENT:$Lang::".sprintf("%-29s",$Lang::tr{'caption'}),
217 "COMMENT:$Lang::tr{'maximal'}",
218 "COMMENT:$Lang::tr{'average'}",
219 "COMMENT:$Lang::tr{'minimal'}",
220 "COMMENT:$Lang::tr{'current'}\\j",
221 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used swap'}),
222 "GPRINT:usedpct:MAX:%3.2lf%%",
223 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
224 "GPRINT:usedpct:MIN:%3.2lf%%",
225 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
226 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
227 "GPRINT:freepct:MAX:%3.2lf%%",
228 "GPRINT:freepct:AVERAGE:%3.2lf%%",
229 "GPRINT:freepct:MIN:%3.2lf%%",
230 "GPRINT:freepct:LAST:%3.2lf%%\\j",
231 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}),
232 "GPRINT:cachedpct:MAX:%3.2lf%%",
233 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
234 "GPRINT:cachedpct:MIN:%3.2lf%%",
235 "GPRINT:cachedpct:LAST:%3.2lf%%\\j");
236 $ERROR = RRDs::error;
237 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
238 }
239
240 sub updatediskgraph {
241 my $period = $_[0];
242 my $disk = $_[1];
243
244 RRDs::graph ("$graphs/disk-$disk-$period.png",
245 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
246 "--alt-y-grid", "-w 600", "-h 150", "-r", "-z",
247 "--color", "SHADEA".$color{"color19"},
248 "--color", "SHADEB".$color{"color19"},
249 "--color", "BACK".$color{"color21"},
250 "-t $disk $Lang::tr{'disk access per'} $Lang::tr{$period}",
251 "DEF:read=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
252 "DEF:write=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
253 "CDEF:writen=write,-1,*",
254 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
255 "CDEF:st=standby,INF,*",
256 "COMMENT:$Lang::".sprintf("%-25s",$Lang::tr{'caption'}),
257 "COMMENT:$Lang::tr{'maximal'}",
258 "COMMENT:$Lang::tr{'average'}",
259 "COMMENT:$Lang::tr{'minimal'}",
260 "COMMENT:$Lang::tr{'current'}\\j",
261 "AREA:st".$color{"color20"}.":standby\\j",
262 "AREA:read".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
263 "GPRINT:read:MAX:%8.1lf %sBps",
264 "GPRINT:read:AVERAGE:%8.1lf %sBps",
265 "GPRINT:read:MIN:%8.1lf %sBps",
266 "GPRINT:read:LAST:%8.1lf %sBps\\j",
267 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
268 "GPRINT:write:MAX:%8.1lf %sBps",
269 "GPRINT:write:AVERAGE:%8.1lf %sBps",
270 "GPRINT:write:MIN:%8.1lf %sBps",
271 "GPRINT:write:LAST:%8.1lf %sBps\\j");
272 $ERROR = RRDs::error;
273 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
274 }
275
276 sub updateifgraph {
277 my $interface = $_[0];
278 my $period = $_[1];
279
280 RRDs::graph ("$graphs/$interface-$period.png",
281 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
282 "--alt-y-grid", "-w 600", "-h 150", "-z", "-r",
283 "--color", "SHADEA".$color{"color19"},
284 "--color", "SHADEB".$color{"color19"},
285 "--color", "BACK".$color{"color21"},
286 "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
287 "-v$Lang::tr{'bytes per second'}",
288 "DEF:incoming=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:rx:AVERAGE",
289 "DEF:outgoing=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:tx:AVERAGE",
290 "CDEF:outgoingn=outgoing,-1,*",
291 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'}),
292 "COMMENT:$Lang::tr{'maximal'}",
293 "COMMENT:$Lang::tr{'average'}",
294 "COMMENT:$Lang::tr{'minimal'}",
295 "COMMENT:$Lang::tr{'current'}\\j",
296 "AREA:incoming".$color{"color12"}."A0:$Lang::tr{'incoming traffic in bytes per second'}",
297 "GPRINT:incoming:MAX:%8.1lf %sBps",
298 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
299 "GPRINT:incoming:MIN:%8.1lf %sBps",
300 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
301 "AREA:outgoingn".$color{"color13"}."A0:$Lang::tr{'outgoing traffic in bytes per second'}",
302 "GPRINT:outgoing:MAX:%8.1lf %sBps",
303 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
304 "GPRINT:outgoing:MIN:%8.1lf %sBps",
305 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j");
306 $ERROR = RRDs::error;
307 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
308 }
309
310 sub updatefwhitsgraph {
311 my $period = $_[0];
312 RRDs::graph ("$graphs/fwhits-$period.png",
313 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
314 "--alt-y-grid", "-w 600", "-h 150", "-r", "-v $Lang::tr{'bytes per second'}",
315 "--color", "SHADEA".$color{"color19"},
316 "--color", "SHADEB".$color{"color19"},
317 "--color", "BACK".$color{"color21"},
318 "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}",
319 "DEF:output=$rrdlog/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
320 "DEF:input=$rrdlog/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
321 "DEF:newnotsyn=$rrdlog/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
322 "DEF:portscan=$rrdlog/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
323 "CDEF:amount=output,input,newnotsyn,+,+",
324 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'}),
325 "COMMENT:$Lang::tr{'maximal'}",
326 "COMMENT:$Lang::tr{'average'}",
327 "COMMENT:$Lang::tr{'minimal'}",
328 "COMMENT:$Lang::tr{'current'}\\j",
329 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr{'firewallhits'}),
330 "GPRINT:amount:MAX:%8.1lf %sBps",
331 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
332 "GPRINT:amount:MIN:%8.1lf %sBps",
333 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
334 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr{'portscans'}),
335 "GPRINT:portscan:MAX:%8.1lf %sBps",
336 "GPRINT:portscan:MIN:%8.1lf %sBps",
337 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
338 "GPRINT:portscan:LAST:%8.1lf %sBps\\j");
339 $ERROR = RRDs::error;
340 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
341 }
342
343 sub updatelqgraph {
344 my $period = $_[0];
345 RRDs::graph ("$graphs/lq-$period.png",
346 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
347 "--alt-y-grid", "-w 600", "-h 150", "-l 0", "-r", "-v ms",
348 "-t $Lang::tr{'linkq'} $Lang::tr{'graph per'} $Lang::tr{$period}",
349 "--color", "SHADEA".$color{"color19"},
350 "--color", "SHADEB".$color{"color19"},
351 "--color", "BACK".$color{"color21"},
352 "DEF:roundtrip=$rrdlog/collectd/localhost/ping/ping-gateway.rrd:ping:AVERAGE",
353 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
354 "CDEF:r0=roundtrip,30,-",
355 "CDEF:r1=r0,70,-",
356 "CDEF:r2=r1,150,-",
357 "CDEF:r3=r2,300,-",
358 "AREA:r0".$color{"color12"}."A0:<30 ms",
359 "STACK:r1".$color{"color17"}."A0:30-70 ms",
360 "STACK:r2".$color{"color14"}."A0:70-150 ms",
361 "STACK:r3".$color{"color18"}."A0:150-300 ms",
362 "STACK:roundtrip".$color{"color25"}.":>300 ms\\j",
363 "COMMENT:$Lang::tr{'maximal'}",
364 "COMMENT:$Lang::tr{'average'}",
365 "COMMENT:$Lang::tr{'minimal'}",
366 "COMMENT:$Lang::tr{'current'}\\j",
367 "LINE1:roundtrip#707070:",
368 "GPRINT:roundtrip:MAX:%3.2lf ms",
369 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
370 "GPRINT:roundtrip:MIN:%3.2lf ms",
371 "GPRINT:roundtrip:LAST:%3.2lf ms\\j");
372 $ERROR = RRDs::error;
373 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
374 }
375
376 sub updatehddgraph {
377
378 my $disk = $_[0];
379 my $period = $_[1];
380
381 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
382 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
383 "--alt-y-grid", "-w 600", "-h 150",
384 "--color", "SHADEA".$color{"color19"},
385 "--color", "SHADEB".$color{"color19"},
386 "--color", "BACK".$color{"color21"},
387 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
388 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
389 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
390 "CDEF:st=standby,INF,*",
391 "AREA:st".$color{"color20"}.":standby",
392 "LINE2:temperature".$color{"color11"}.":$Lang::tr{'hdd temperature in'} C\\j",
393 "COMMENT:$Lang::tr{'maximal'}",
394 "COMMENT:$Lang::tr{'average'}",
395 "COMMENT:$Lang::tr{'minimal'}",
396 "COMMENT:$Lang::tr{'current'}\\j",
397 "GPRINT:temperature:MAX:%3.0lf Grad C",
398 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
399 "GPRINT:temperature:MIN:%3.0lf Grad C",
400 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
401 );
402 $ERROR = RRDs::error;
403 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
404 }
405
406 sub updatetempgraph
407 {
408 my $type = "temp";
409 my $period = $_[0];
410 my $count = "11";
411
412 @args = ("$graphs/mbmon-$type-$period.png",
413 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
414 "--alt-y-grid", "-w 600", "-h 150", "--alt-autoscale",
415 "--color", "SHADEA".$color{"color19"},
416 "--color", "SHADEB".$color{"color19"},
417 "--color", "BACK".$color{"color21"},
418 "-t $Lang::tr{'mbmon temp'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
419 "COMMENT:$Lang::tr{'caption'}\\t\\t",
420 "COMMENT:$Lang::tr{'maximal'}",
421 "COMMENT:$Lang::tr{'average'}",
422 "COMMENT:$Lang::tr{'minimal'}",
423 "COMMENT:$Lang::tr{'current'}\\j",);
424
425 foreach $key ( sort(keys %mbmon_values) )
426 {
427 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
428 {
429 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
430 {
431 $mbmon_settings{'LABEL-'.$key} = $key;
432 }
433 push (@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
434 push (@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Grad C");
435 push (@args, "GPRINT:$key:MAX:%3.1lf");
436 push (@args, "GPRINT:$key:AVERAGE:%3.1lf");
437 push (@args, "GPRINT:$key:MIN:%3.1lf");
438 push (@args, "GPRINT:$key:LAST:%3.1lf\\j");
439 $count++;
440 }
441 }
442
443 RRDs::graph ( @args );
444 $ERROR = RRDs::error;
445 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
446 }
447
448 sub updatefangraph
449 {
450 my $type = "fan";
451 my $period = $_[0];
452 my $count = "11";
453
454 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
455 "--alt-y-grid", "-w 600", "-h 150", "--alt-autoscale",
456 "--color", "SHADEA".$color{"color19"},
457 "--color", "SHADEB".$color{"color19"},
458 "--color", "BACK".$color{"color21"},
459 "-t $Lang::tr{'mbmon fan'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
460 "COMMENT:$Lang::tr{'caption'}\\t\\t",
461 "COMMENT:$Lang::tr{'maximal'}",
462 "COMMENT:$Lang::tr{'average'}",
463 "COMMENT:$Lang::tr{'minimal'}",
464 "COMMENT:$Lang::tr{'current'}\\j",);
465
466 foreach $key ( sort(keys %mbmon_values) )
467 {
468 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
469 {
470 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
471 {
472 $mbmon_settings{'LABEL-'.$key} = $key;
473 }
474
475 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
476 push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} rpm");
477 push(@args, "GPRINT:$key:MAX:%5.0lf");
478 push(@args, "GPRINT:$key:AVERAGE:%5.0lf");
479 push(@args, "GPRINT:$key:MIN:%5.0lf");
480 push(@args, "GPRINT:$key:LAST:%5.0lf\\j");
481 $count++;
482 }
483 }
484 RRDs::graph ( @args );
485 $ERROR = RRDs::error;
486 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
487 }
488
489 sub updatevoltgraph
490 {
491 my $type = "volt";
492 my $period = $_[0];
493 my $count = "11";
494
495 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
496 "--alt-y-grid", "-w 600", "-h 150", "--alt-autoscale",
497 "--color", "SHADEA".$color{"color19"},
498 "--color", "SHADEB".$color{"color19"},
499 "--color", "BACK".$color{"color21"},
500 "-t $Lang::tr{'mbmon volt'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
501 "COMMENT:$Lang::tr{'caption'}\\t",
502 "COMMENT:$Lang::tr{'maximal'}",
503 "COMMENT:$Lang::tr{'average'}",
504 "COMMENT:$Lang::tr{'minimal'}",
505 "COMMENT:$Lang::tr{'current'}\\j",);
506
507 foreach $key ( sort(keys %mbmon_values) )
508 {
509 my $v = substr($key,0,1);
510 if ( ($v eq 'v') && ($mbmon_settings{'LINE-'.$key} eq 'on') )
511 {
512 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
513 {
514 $mbmon_settings{'LABEL-'.$key} = $key;
515 }
516
517 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
518 push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Volt");
519 push(@args, "GPRINT:$key:MAX:%3.2lf");
520 push(@args, "GPRINT:$key:AVERAGE:%3.2lf");
521 push(@args, "GPRINT:$key:MIN:%3.2lf");
522 push(@args, "GPRINT:$key:LAST:%3.2lf\\j");
523 $count++;
524 }
525 }
526
527 RRDs::graph ( @args );
528 $ERROR = RRDs::error;
529 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
530 }
531
532 sub overviewgraph {
533
534 my $period = $_[0];
535 my $periodstring;
536 my $description;
537 my %qossettings = ();
538 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
539 my $classentry = "";
540 my @classes = ();
541 my @classline = ();
542 my $classfile = "/var/ipfire/qos/classes";
543
544 $qossettings{'DEV'} = $_[1];
545 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
546 $qossettings{'CLASSPRFX'} = '1';
547 } else {
548 $qossettings{'CLASSPRFX'} = '2';
549 }
550
551 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
552 if ( $period ne '3240' ){ $description = "-t $Lang::tr{'Utilization on'} ($qossettings{'DEV'}) ($Lang::tr{'graph per'} $Lang::tr{$period})";}else{ $description = "-t $Lang::tr{'Utilization on'} ($qossettings{'DEV'})";}
553
554 my $ERROR="";
555 my $count="1";
556 my $color="#000000";
557 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
558 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
559 "--alt-y-grid", "-w 600", "-h 150", "-r",
560 "--color", "SHADEA".$color{"color19"},
561 "--color", "SHADEB".$color{"color19"},
562 "--color", "BACK".$color{"color21"},
563 "COMMENT:$Lang::tr{'caption'}\\t\\t\\t\\t ",
564 "COMMENT:$Lang::tr{'maximal'}",
565 "COMMENT:$Lang::tr{'average'}",
566 "COMMENT:$Lang::tr{'minimal'}",
567 "COMMENT:$Lang::tr{'current'}\\j",
568 $description
569 );
570 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
571 @classes = <FILE>;
572 close FILE;
573 foreach $classentry (sort @classes)
574 {
575 @classline = split( /\;/, $classentry );
576 if ( $classline[0] eq $qossettings{'DEV'} )
577 {
578 $color=random_hex_color(6);
579 push(@command, "DEF:$classline[1]=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
580
581 if ($count eq "1") {
582 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
583 } else {
584 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
585
586 }
587 push(@command, "GPRINT:$classline[1]:MAX:%5.2lf");
588 push(@command, "GPRINT:$classline[1]:AVERAGE:%5.2lf");
589 push(@command, "GPRINT:$classline[1]:MIN:%5.2lf");
590 push(@command, "GPRINT:$classline[1]:LAST:%5.2lf\\j");
591 $count++;
592 }
593 }
594 RRDs::graph (@command);
595 $ERROR = RRDs::error;
596 print "$ERROR";
597 }
598
599 sub random_hex_color {
600 my $size = shift;
601 $size = 6 if $size !~ /^3|6$/;
602 my @hex = ( 0 .. 9, 'a' .. 'f' );
603 my @color;
604 push @color, @hex[rand(@hex)] for 1 .. $size;
605 return join('', '#', @color);
606 }