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