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