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