]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/graphs.pl
Add cpufreq graph
[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 # Read the global settings files to get the current theme and after this load
21 # colors for this theme
22
23 my %color = ();
24 my %mainsettings = ();
25 my %sensorsettings = ();
26 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
27 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
28
29
30 # If the collection deamon is working and collecting lm_sensors data there will be
31 # some data source named after a common scheme, with the sensorssettingsfile
32 # the user is able to deactivate some of this parameters, in case not to show
33 # false collected value´s may be disable. The user has the ability to ente
34 # custom graph names in order to change temp0 to cpu or motherboad
35
36 my $key;
37 my $value;
38 my @args = ();
39 my $count = 0;
40 my @sensorsgraphs = ();
41 my @processesgraph = `ls -dA $rrdlog/collectd/localhost/processes-*/`;
42 my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`;
43 foreach (@sensorsdir)
44 {
45 chomp($_);chop($_);
46 foreach (`ls $_/*`){
47 chomp($_);
48 push(@sensorsgraphs,$_);
49 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
50 my $label = $2.$3;$label=~ s/-//g;
51 $sensorsettings{'LABEL-'.$label}="$label";
52 $sensorsettings{'LINE-'.$label}="checked";
53 }
54 }
55
56 &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
57 use Encode 'from_to';
58
59 my %tr=();
60 if ((${Lang::language} eq 'el') ||
61 (${Lang::language} eq 'fa') ||
62 (${Lang::language} eq 'ru') ||
63 (${Lang::language} eq 'th') ||
64 (${Lang::language} eq 'vi') ||
65 (${Lang::language} eq 'zh') ||
66 (${Lang::language} eq 'zt')) {
67 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
68 } else {
69 %tr=%Lang::tr; # use translated version for other languages
70 }
71
72 # Generate the CPU Graph for the current period of time for values given by
73 # collectd atm only cpu average is displayed and only 1 or 2 cpus is working
74
75 sub updatecpugraph {
76 my $period = $_[0];
77 my @command = ("$graphs/cpu-$period.png",
78 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
79 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
80 "--color", "SHADEA".$color{"color19"},
81 "--color", "SHADEB".$color{"color19"},
82 "--color", "BACK".$color{"color21"},
83 "-t $Lang::tr{'cpu usage per'} $Lang::tr{$period}");
84
85 if ( -e "$rrdlog/collectd/localhost/cpu-1/" ){
86 push(@command,"DEF:iowait0=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE",
87 "DEF:nice0=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE",
88 "DEF:interrupt0=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE",
89 "DEF:steal0=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE",
90 "DEF:user0=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE",
91 "DEF:system0=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE",
92 "DEF:idle0=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE",
93 "DEF:irq0=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE");
94 push(@command,"DEF:iowait1=$rrdlog/collectd/localhost/cpu-1/cpu-wait.rrd:value:AVERAGE",
95 "DEF:nice1=$rrdlog/collectd/localhost/cpu-1/cpu-nice.rrd:value:AVERAGE",
96 "DEF:interrupt1=$rrdlog/collectd/localhost/cpu-1/cpu-interrupt.rrd:value:AVERAGE",
97 "DEF:steal1=$rrdlog/collectd/localhost/cpu-1/cpu-steal.rrd:value:AVERAGE",
98 "DEF:user1=$rrdlog/collectd/localhost/cpu-1/cpu-user.rrd:value:AVERAGE",
99 "DEF:system1=$rrdlog/collectd/localhost/cpu-1/cpu-system.rrd:value:AVERAGE",
100 "DEF:idle1=$rrdlog/collectd/localhost/cpu-1/cpu-idle.rrd:value:AVERAGE",
101 "DEF:irq1=$rrdlog/collectd/localhost/cpu-1/cpu-softirq.rrd:value:AVERAGE");
102 push(@command,"CDEF:user=user0,user1,+",
103 "CDEF:nice=nice0,nice1,+",
104 "CDEF:interrupt=interrupt0,interrupt1,+",
105 "CDEF:steal=steal0,steal1,+",
106 "CDEF:system=system0,system1,+",
107 "CDEF:idle=idle0,idle1,+",
108 "CDEF:iowait=iowait0,iowait1,+",
109 "CDEF:irq=irq0,irq1,+");
110 }
111 else {
112 push(@command,"DEF:iowait=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE",
113 "DEF:nice=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE",
114 "DEF:interrupt=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE",
115 "DEF:steal=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE",
116 "DEF:user=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE",
117 "DEF:system=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE",
118 "DEF:idle=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE",
119 "DEF:irq=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE");
120 }
121 push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+",
122 "CDEF:userpct=100,user,total,/,*",
123 "CDEF:nicepct=100,nice,total,/,*",
124 "CDEF:interruptpct=100,interrupt,total,/,*",
125 "CDEF:stealpct=100,steal,total,/,*",
126 "CDEF:systempct=100,system,total,/,*",
127 "CDEF:idlepct=100,idle,total,/,*",
128 "CDEF:iowaitpct=100,iowait,total,/,*",
129 "CDEF:irqpct=100,irq,total,/,*",
130 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
131 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
132 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
133 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
134 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
135 "AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'}),
136 "GPRINT:iowaitpct:MAX:%3.2lf%%",
137 "GPRINT:iowaitpct:AVERAGE:%3.2lf%%",
138 "GPRINT:iowaitpct:MIN:%3.2lf%%",
139 "GPRINT:iowaitpct:LAST:%3.2lf%%\\j",
140 "STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'}),
141 "GPRINT:irqpct:MAX:%3.2lf%%",
142 "GPRINT:irqpct:AVERAGE:%3.2lf%%",
143 "GPRINT:irqpct:MIN:%3.2lf%%",
144 "GPRINT:irqpct:LAST:%3.2lf%%\\j",
145 "STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'}),
146 "GPRINT:nicepct:MAX:%3.2lf%%",
147 "GPRINT:nicepct:AVERAGE:%3.2lf%%",
148 "GPRINT:nicepct:MIN:%3.2lf%%",
149 "GPRINT:nicepct:LAST:%3.2lf%%\\j",
150 "STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'}),
151 "GPRINT:interruptpct:MAX:%3.2lf%%",
152 "GPRINT:interruptpct:AVERAGE:%3.2lf%%",
153 "GPRINT:interruptpct:MIN:%3.2lf%%",
154 "GPRINT:interruptpct:LAST:%3.2lf%%\\j",
155 "STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'}),
156 "GPRINT:stealpct:MAX:%3.2lf%%",
157 "GPRINT:stealpct:AVERAGE:%3.2lf%%",
158 "GPRINT:stealpct:MIN:%3.2lf%%",
159 "GPRINT:stealpct:LAST:%3.2lf%%\\j",
160 "STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'}),
161 "GPRINT:userpct:MAX:%3.2lf%%",
162 "GPRINT:userpct:AVERAGE:%3.2lf%%",
163 "GPRINT:userpct:MIN:%3.2lf%%",
164 "GPRINT:userpct:LAST:%3.2lf%%\\j",
165 "STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'}),
166 "GPRINT:systempct:MAX:%3.2lf%%",
167 "GPRINT:systempct:AVERAGE:%3.2lf%%",
168 "GPRINT:systempct:MIN:%3.2lf%%",
169 "GPRINT:systempct:LAST:%3.2lf%%\\j",
170 "STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'}),
171 "GPRINT:idlepct:MAX:%3.2lf%%",
172 "GPRINT:idlepct:AVERAGE:%3.2lf%%",
173 "GPRINT:idlepct:MIN:%3.2lf%%",
174 "GPRINT:idlepct:LAST:%3.2lf%%\\j");
175
176 RRDs::graph (@command);
177 $ERROR = RRDs::error;
178 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
179 }
180
181 # Generate the CPU Frequency Graph for the current period of time for values given by
182 # only 1 or 2 cpus is working
183 sub updatecpufreqgraph {
184 if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd" ){
185
186 my $period = $_[0];
187 my @command = ("$graphs/cpufreq-$period.png",
188 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v Mhz",
189 "-w 600", "-h 125", "-r",
190 "--color", "SHADEA".$color{"color19"},
191 "--color", "SHADEB".$color{"color19"},
192 "--color", "BACK".$color{"color21"},
193 "-t $Lang::tr{'cpu frequency per'} $Lang::tr{$period}");
194
195 if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
196 push(@command,"DEF:cpu1_=$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd:value:AVERAGE");
197 }
198 push(@command,"DEF:cpu0_=$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd:value:AVERAGE");
199
200 if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
201 push(@command,"CDEF:cpu1=cpu1_,1000000,/");
202 }
203 push(@command,"CDEF:cpu0=cpu0_,1000000,/");
204
205 if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
206 push(@command,"LINE1:cpu1".$color{"color11"}."A0:cpu 1\\j",
207 "COMMENT:$Lang::tr{'maximal'}",
208 "COMMENT:$Lang::tr{'average'}",
209 "COMMENT:$Lang::tr{'minimal'}",
210 "COMMENT:$Lang::tr{'current'}\\j",
211 "GPRINT:cpu1:MAX:%3.0lf Mhz",
212 "GPRINT:cpu1:AVERAGE:%3.0lf Mhz",
213 "GPRINT:cpu1:MIN:%3.0lf Mhz",
214 "GPRINT:cpu1:LAST:%3.0lf Mhz\\j",);
215 }
216 push(@command,"LINE2:cpu0".$color{"color12"}."A1:cpu 0\\j",
217 "COMMENT:$Lang::tr{'maximal'}",
218 "COMMENT:$Lang::tr{'average'}",
219 "COMMENT:$Lang::tr{'minimal'}",
220 "COMMENT:$Lang::tr{'current'}\\j",
221 "GPRINT:cpu0:MAX:%3.0lf Mhz",
222 "GPRINT:cpu0:AVERAGE:%3.0lf Mhz",
223 "GPRINT:cpu0:MIN:%3.0lf Mhz",
224 "GPRINT:cpu0:LAST:%3.0lf Mhz\\j",);
225
226 RRDs::graph (@command);
227 $ERROR = RRDs::error;
228 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
229 }
230 }
231
232
233 # Generate the Load Graph for the current period of time for values given by collecd
234
235 sub updateloadgraph {
236 my $period = $_[0];
237
238 RRDs::graph ("$graphs/load-$period.png",
239 "--start", "-1$period", "-aPNG",
240 "-w 600", "-h 125", "-i", "-z", "-W www.ipfire.org", "-l 0", "-r", "--alt-y-grid",
241 "-t Load Average $Lang::tr{'graph per'} $Lang::tr{$period}", "-v $Lang::tr{'processes'}",
242 "--color", "SHADEA".$color{"color19"},
243 "--color", "SHADEB".$color{"color19"},
244 "--color", "BACK".$color{"color21"},
245 "DEF:load1=$rrdlog/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
246 "DEF:load5=$rrdlog/collectd/localhost/load/load.rrd:midterm:AVERAGE",
247 "DEF:load15=$rrdlog/collectd/localhost/load/load.rrd:longterm:AVERAGE",
248 "AREA:load1".$color{"color13"}."A0:1 Minute:",
249 "GPRINT:load1:LAST:%5.2lf",
250 "AREA:load5".$color{"color18"}."A0:5 Minuten:",
251 "GPRINT:load5:LAST:%5.2lf",
252 "AREA:load15".$color{"color14"}."A0:15 Minuten:",
253 "GPRINT:load15:LAST:%5.2lf\\j",
254 "LINE1:load5".$color{"color13"},
255 "LINE1:load1".$color{"color18"});
256 $ERROR = RRDs::error;
257 print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
258 }
259
260
261 # Generate the Memory and Swap Graph for the current period of time for values given by collecd
262
263 sub updatememgraph {
264 my $period = $_[0];
265
266 RRDs::graph ("$graphs/memory-$period.png",
267 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
268 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
269 "--color", "SHADEA".$color{"color19"},
270 "--color", "SHADEB".$color{"color19"},
271 "--color", "BACK".$color{"color21"},
272 "-t $Lang::tr{'memory usage per'} $Lang::tr{$period}",
273 "DEF:used=$rrdlog/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
274 "DEF:free=$rrdlog/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
275 "DEF:buffer=$rrdlog/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
276 "DEF:cache=$rrdlog/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
277 "CDEF:total=used,free,cache,buffer,+,+,+",
278 "CDEF:usedpct=used,total,/,100,*",
279 "CDEF:bufferpct=buffer,total,/,100,*",
280 "CDEF:cachepct=cache,total,/,100,*",
281 "CDEF:freepct=free,total,/,100,*",
282 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
283 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
284 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
285 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
286 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
287 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used memory'}),
288 "GPRINT:usedpct:MAX:%3.2lf%%",
289 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
290 "GPRINT:usedpct:MIN:%3.2lf%%",
291 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
292 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'buffered memory'}),
293 "GPRINT:bufferpct:MAX:%3.2lf%%",
294 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
295 "GPRINT:bufferpct:MIN:%3.2lf%%",
296 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
297 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'cached memory'}),
298 "GPRINT:cachepct:MAX:%3.2lf%%",
299 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
300 "GPRINT:cachepct:MIN:%3.2lf%%",
301 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
302 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free memory'}),
303 "GPRINT:freepct:MAX:%3.2lf%%",
304 "GPRINT:freepct:AVERAGE:%3.2lf%%",
305 "GPRINT:freepct:MIN:%3.2lf%%",
306 "GPRINT:freepct:LAST:%3.2lf%%\\j");
307 $ERROR = RRDs::error;
308 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
309
310 RRDs::graph ("$graphs/swap-$period.png",
311 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
312 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
313 "--color", "SHADEA".$color{"color19"},
314 "--color", "SHADEB".$color{"color19"},
315 "--color", "BACK".$color{"color21"},
316 "-t $Lang::tr{'swap usage per'} $Lang::tr{$period}",
317 "DEF:used=$rrdlog/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
318 "DEF:free=$rrdlog/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
319 "DEF:cached=$rrdlog/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
320 "CDEF:total=used,free,cached,+,+",
321 "CDEF:usedpct=100,used,total,/,*",
322 "CDEF:freepct=100,free,total,/,*",
323 "CDEF:cachedpct=100,cached,total,/,*",
324 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
325 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
326 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
327 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
328 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
329 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used swap'}),
330 "GPRINT:usedpct:MAX:%3.2lf%%",
331 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
332 "GPRINT:usedpct:MIN:%3.2lf%%",
333 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
334 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
335 "GPRINT:freepct:MAX:%3.2lf%%",
336 "GPRINT:freepct:AVERAGE:%3.2lf%%",
337 "GPRINT:freepct:MIN:%3.2lf%%",
338 "GPRINT:freepct:LAST:%3.2lf%%\\j",
339 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}),
340 "GPRINT:cachedpct:MAX:%3.2lf%%",
341 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
342 "GPRINT:cachedpct:MIN:%3.2lf%%",
343 "GPRINT:cachedpct:LAST:%3.2lf%%\\j");
344 $ERROR = RRDs::error;
345 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
346 }
347
348 # Generate the Disk Graph for the current period of time for values given by collecd
349
350 sub updatediskgraph {
351 my $period = $_[0];
352 my $disk = $_[1];
353
354 RRDs::graph ("$graphs/disk-$disk-$period.png",
355 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
356 "--alt-y-grid", "-w 600", "-h 125", "-r", "-z",
357 "--color", "SHADEA".$color{"color19"},
358 "--color", "SHADEB".$color{"color19"},
359 "--color", "BACK".$color{"color21"},
360 "-t $disk $Lang::tr{'disk access per'} $Lang::tr{$period}",
361 "DEF:read=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
362 "DEF:write=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
363 "CDEF:writen=write,-1,*",
364 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
365 "CDEF:st=standby,INF,*",
366 "CDEF:st1=standby,-INF,*",
367 "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}),
368 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
369 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
370 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
371 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
372 "AREA:st".$color{"color20"}."A0:",
373 "AREA:st1".$color{"color20"}."A0:standby\\j",
374 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
375 "GPRINT:read:MAX:%8.1lf %sBps",
376 "GPRINT:read:AVERAGE:%8.1lf %sBps",
377 "GPRINT:read:MIN:%8.1lf %sBps",
378 "GPRINT:read:LAST:%8.1lf %sBps\\j",
379 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
380 "GPRINT:write:MAX:%8.1lf %sBps",
381 "GPRINT:write:AVERAGE:%8.1lf %sBps",
382 "GPRINT:write:MIN:%8.1lf %sBps",
383 "GPRINT:write:LAST:%8.1lf %sBps\\j");
384 $ERROR = RRDs::error;
385 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
386 }
387
388 # Generate the Interface Graph for the current period of time for values given by collecd
389
390 sub updateifgraph {
391 my $interface = $_[0];
392 my $period = $_[1];
393
394 RRDs::graph ("$graphs/$interface-$period.png",
395 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
396 "--alt-y-grid", "-w 600", "-h 125", "-z", "-r",
397 "--color", "SHADEA".$color{"color19"},
398 "--color", "SHADEB".$color{"color19"},
399 "--color", "BACK".$color{"color21"},
400 "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
401 "-v$Lang::tr{'bytes per second'}",
402 "DEF:incoming=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:rx:AVERAGE",
403 "DEF:outgoing=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:tx:AVERAGE",
404 "CDEF:outgoingn=outgoing,-1,*",
405 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
406 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
407 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
408 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
409 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
410 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
411 "GPRINT:incoming:MAX:%8.1lf %sBps",
412 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
413 "GPRINT:incoming:MIN:%8.1lf %sBps",
414 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
415 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
416 "GPRINT:outgoing:MAX:%8.1lf %sBps",
417 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
418 "GPRINT:outgoing:MIN:%8.1lf %sBps",
419 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j");
420 $ERROR = RRDs::error;
421 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
422 }
423
424 # Generate the Firewall Graph for the current period of time for values given by collecd
425
426 sub updatefwhitsgraph {
427 my $period = $_[0];
428 RRDs::graph ("$graphs/fwhits-$period.png",
429 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
430 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
431 "--color", "SHADEA".$color{"color19"},
432 "--color", "SHADEB".$color{"color19"},
433 "--color", "BACK".$color{"color21"},
434 "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}",
435 "DEF:output=$rrdlog/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
436 "DEF:input=$rrdlog/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
437 "DEF:newnotsyn=$rrdlog/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
438 "DEF:portscan=$rrdlog/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
439 "CDEF:amount=output,input,newnotsyn,+,+",
440 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
441 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
442 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
443 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
444 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
445 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr{'firewallhits'}),
446 "GPRINT:amount:MAX:%8.1lf %sBps",
447 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
448 "GPRINT:amount:MIN:%8.1lf %sBps",
449 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
450 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr{'portscans'}),
451 "GPRINT:portscan:MAX:%8.1lf %sBps",
452 "GPRINT:portscan:MIN:%8.1lf %sBps",
453 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
454 "GPRINT:portscan:LAST:%8.1lf %sBps\\j");
455 $ERROR = RRDs::error;
456 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
457 }
458
459 # Generate the Line Quality Graph for the current period of time for values given by collecd
460
461 sub updatepinggraph {
462 my $period = $_[0];
463 my $host = $_[1];
464 RRDs::graph ("$graphs/$host-$period.png",
465 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
466 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-r", "-v ms",
467 "-t $Lang::tr{'linkq'} $host $Lang::tr{'graph per'} $Lang::tr{$period}",
468 "--color", "SHADEA".$color{"color19"},
469 "--color", "SHADEB".$color{"color19"},
470 "--color", "BACK".$color{"color21"},
471 "DEF:roundtrip=$rrdlog/collectd/localhost/ping/ping-$host.rrd:ping:AVERAGE",
472 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
473 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
474 "CDEF:r0=roundtrip,30,MIN",
475 "CDEF:r1=roundtrip,70,MIN",
476 "CDEF:r2=roundtrip,150,MIN",
477 "CDEF:r3=roundtrip,300,MIN",
478 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
479 "AREA:r3".$color{"color18"}."A0:150-300 ms",
480 "AREA:r2".$color{"color14"}."A0:70-150 ms",
481 "AREA:r1".$color{"color17"}."A0:30-70 ms",
482 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
483 "COMMENT:$Lang::tr{'maximal'}",
484 "COMMENT:$Lang::tr{'average'}",
485 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
486 "LINE1:roundtrip#707070:",
487 "GPRINT:roundtrip:MAX:%3.2lf ms",
488 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
489 "GPRINT:roundtrip:MIN:%3.2lf ms",
490 "GPRINT:roundtrip:LAST:%3.2lf ms\\j");
491 $ERROR = RRDs::error;
492 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
493 }
494
495 # Generate the Hdd Graph for the current period of time for values given by collecd
496
497 sub updatehddgraph {
498
499 my $disk = $_[0];
500 my $period = $_[1];
501
502 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
503 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
504 "--alt-y-grid", "-w 600", "-h 125",
505 "--color", "SHADEA".$color{"color19"},
506 "--color", "SHADEB".$color{"color19"},
507 "--color", "BACK".$color{"color21"},
508 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
509 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
510 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
511 "CDEF:st=standby,INF,*",
512 "AREA:st".$color{"color20"}."A0:standby",
513 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
514 "COMMENT:$Lang::tr{'maximal'}",
515 "COMMENT:$Lang::tr{'average'}",
516 "COMMENT:$Lang::tr{'minimal'}",
517 "COMMENT:$Lang::tr{'current'}\\j",
518 "GPRINT:temperature:MAX:%3.0lf Grad C",
519 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
520 "GPRINT:temperature:MIN:%3.0lf Grad C",
521 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
522 );
523 $ERROR = RRDs::error;
524 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
525 }
526
527 # Generate the QoS Graph for the current period of time
528
529 sub overviewgraph {
530
531 my $period = $_[0];
532 my $periodstring;
533 my $description;
534 my %qossettings = ();
535 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
536 my $classentry = "";
537 my @classes = ();
538 my @classline = ();
539 my $classfile = "/var/ipfire/qos/classes";
540
541 $qossettings{'DEV'} = $_[1];
542 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
543 $qossettings{'CLASSPRFX'} = '1';
544 } else {
545 $qossettings{'CLASSPRFX'} = '2';
546 }
547
548 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
549 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'})";}
550
551 my $ERROR="";
552 my $count="1";
553 my $color="#000000";
554 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
555 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
556 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
557 "--color", "SHADEA".$color{"color19"},
558 "--color", "SHADEB".$color{"color19"},
559 "--color", "BACK".$color{"color21"},
560 "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}),
561 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
562 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
563 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
564 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
565 $description
566 );
567 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
568 @classes = <FILE>;
569 close FILE;
570 foreach $classentry (sort @classes)
571 {
572 @classline = split( /\;/, $classentry );
573 if ( $classline[0] eq $qossettings{'DEV'} )
574 {
575 $color=random_hex_color(6);
576 push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
577
578 if ($count eq "1") {
579 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
580 } else {
581 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
582
583 }
584 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps");
585 push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps");
586 push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps");
587 push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
588 $count++;
589 }
590 }
591 RRDs::graph (@command);
592 $ERROR = RRDs::error;
593 print "$ERROR";
594 }
595
596 # Generate the Temperature Graph for the current period of time for values given by collecd and lm_sensors
597
598 sub updatehwtempgraph {
599
600 my $period = $_[0];
601
602 my @command = ("$graphs/sensors-hwtemp-$period.png",
603 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
604 "--alt-y-grid", "-w 600", "-h 125",
605 "--color", "SHADEA".$color{"color19"},"--color",
606 "SHADEB".$color{"color19"},"--color",
607 "BACK".$color{"color21"},
608 "-t $Lang::tr{'sensors temp'} $Lang::tr{'graph per'} $Lang::tr{$period}");
609
610 foreach(@sensorsgraphs){
611 chomp($_);
612 if ( $_ =~ /temperature/ ) {
613 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
614 my $label = $2.$3;$label=~ s/-//g;
615 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
616 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
617 }
618 }
619 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j");
620 foreach(@sensorsgraphs){
621 chomp($_);
622 if ( $_ =~ /temperature/ ){
623 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
624 my $label = $2.$3;$label=~ s/-//g;
625 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
626 push(@command,"LINE3:".$sensorsettings{'LABEL-'.$label}.random_hex_color(6)."A0:".sprintf("%-25s",$sensorsettings{'LABEL-'.$label}),"GPRINT:".$sensorsettings{'LABEL-'.$label}.":MAX:%3.2lf C","GPRINT:".$sensorsettings{'LABEL-'.$label}.":AVERAGE:%3.2lf C","GPRINT:".$sensorsettings{'LABEL-'.$label}.":MIN:%3.2lf C","GPRINT:".$sensorsettings{'LABEL-'.$label}.":LAST:%3.2lf C\\j",);
627 }
628 }
629 RRDs::graph (@command);
630 $ERROR = RRDs::error;
631 print "$ERROR";
632 }
633
634 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
635
636 sub updatehwvoltgraph {
637
638 my $period = $_[0];
639
640 my @command = ("$graphs/sensors-hwvolt-$period.png",
641 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
642 "--alt-y-grid", "-w 600", "-h 125",
643 "--color", "SHADEA".$color{"color19"},"--color",
644 "SHADEB".$color{"color19"},"--color",
645 "BACK".$color{"color21"},
646 "-t $Lang::tr{'mbmon volt'} $Lang::tr{'graph per'} $Lang::tr{$period}");
647
648 foreach(@sensorsgraphs){
649 chomp($_);
650 if ( $_ =~ /voltage/ ) {
651 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
652 my $label = $2.$3;$label=~ s/-//g;
653 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
654 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
655 }
656 }
657 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j");
658 foreach(@sensorsgraphs){
659 chomp($_);
660 if ( $_ =~ /voltage/ ){
661 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
662 my $label = $2.$3;$label=~ s/-//g;
663 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
664 push(@command,"LINE3:".$sensorsettings{'LABEL-'.$label}.random_hex_color(6)."A0:".sprintf("%-25s",$sensorsettings{'LABEL-'.$label}),"GPRINT:".$sensorsettings{'LABEL-'.$label}.":MAX:%3.2lf V","GPRINT:".$sensorsettings{'LABEL-'.$label}.":AVERAGE:%3.2lf V","GPRINT:".$sensorsettings{'LABEL-'.$label}.":MIN:%3.2lf V","GPRINT:".$sensorsettings{'LABEL-'.$label}.":LAST:%3.2lf V\\j",);
665 }
666 }
667 RRDs::graph (@command);
668 $ERROR = RRDs::error;
669 print "$ERROR";
670 }
671
672 # Generate the Load Graph for the current period of time for values given by collecd and lm_sensors
673
674 sub updatehwfangraph {
675
676 my $period = $_[0];
677
678 my @command = ("$graphs/sensors-hwfan-$period.png",
679 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
680 "--alt-y-grid", "-w 600", "-h 125",
681 "--color", "SHADEA".$color{"color19"},"--color",
682 "SHADEB".$color{"color19"},"--color",
683 "BACK".$color{"color21"},
684 "-t $Lang::tr{'mbmon fan'} $Lang::tr{'graph per'} $Lang::tr{$period}");
685
686 foreach(@sensorsgraphs){
687 chomp($_);
688 if ( $_ =~ /fanspeed/ ) {
689 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
690 my $label = $2.$3;$label=~ s/-//g;
691 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
692 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
693 }
694 }
695 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j");
696 foreach(@sensorsgraphs){
697 chomp($_);
698 if ( $_ =~ /fanspeed/ ){
699 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
700 my $label = $2.$3;$label=~ s/-//g;
701 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
702 push(@command,"LINE3:".$sensorsettings{'LABEL-'.$label}.random_hex_color(6)."A0:".sprintf("%-25s",$sensorsettings{'LABEL-'.$label}),"GPRINT:".$sensorsettings{'LABEL-'.$label}.":MAX:%3.2lf RPM","GPRINT:".$sensorsettings{'LABEL-'.$label}.":AVERAGE:%3.2lf RPM","GPRINT:".$sensorsettings{'LABEL-'.$label}.":MIN:%3.2lf RPM","GPRINT:".$sensorsettings{'LABEL-'.$label}.":LAST:%3.2lf RPM\\j",);
703 }
704 }
705 RRDs::graph (@command);
706 $ERROR = RRDs::error;
707 print "$ERROR";
708 }
709
710 sub updateprocessesgraph {
711
712 my $period = $_[0];
713 my $count="0";
714
715 my @command = ("$graphs/processes-$period.png",
716 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
717 "--alt-y-grid", "-w 600", "-h 125",
718 "--color", "SHADEA".$color{"color19"},"--color",
719 "SHADEB".$color{"color19"},"--color",
720 "BACK".$color{"color21"},
721 "-t $Lang::tr{'processes'} $Lang::tr{'graph per'} $Lang::tr{$period}");
722
723 foreach(@processesgraph){
724 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
725 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
726 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
727 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");}
728
729 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
730
731 foreach(@processesgraph){
732 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
733 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
734 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
735 $count++;}
736
737 RRDs::graph (@command);
738 $ERROR = RRDs::error;
739 print "$ERROR";
740
741 my $count="0";
742
743 my @command = ("$graphs/processesmem-$period.png",
744 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
745 "--alt-y-grid", "-w 600", "-h 125",
746 "--color", "SHADEA".$color{"color19"},"--color",
747 "SHADEB".$color{"color19"},"--color",
748 "BACK".$color{"color21"},
749 "-t $Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph per'} $Lang::tr{$period}");
750
751 foreach(@processesgraph){
752 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
753 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");}
754 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
755
756 foreach(@processesgraph){
757 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
758 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
759 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
760 $count++;}
761
762 RRDs::graph (@command);
763 $ERROR = RRDs::error;
764 print "$ERROR";
765 }
766
767 sub wireless {
768 my $period = $_[0];
769 my $interface = $_[1];
770 RRDs::graph ("$graphs/wireless-$interface-$period.png",
771 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
772 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v dBm", "-z",
773 "-t Wireless $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
774 "--color", "SHADEA".$color{"color19"},
775 "--color", "SHADEB".$color{"color19"},
776 "--color", "BACK".$color{"color21"},
777 "DEF:noise=$rrdlog/collectd/localhost/wireless-$interface/signal_noise.rrd:value:AVERAGE",
778 "DEF:power=$rrdlog/collectd/localhost/wireless-$interface/signal_power.rrd:value:AVERAGE",
779 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
780 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
781 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
782 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
783 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
784 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
785 "GPRINT:noise:MAX:%5.1lf %sdBm",
786 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
787 "GPRINT:noise:MIN:%5.1lf %sdBm",
788 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
789 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
790 "GPRINT:power:MAX:%5.1lf %sdBm",
791 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
792 "GPRINT:power:MIN:%5.1lf %sdBm",
793 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
794 );
795 $ERROR = RRDs::error;
796 print "Error in RRD::graph for Wireless: $ERROR\n" if $ERROR;
797 }
798
799 # Generate a random color, used by Qos Graph to be independent from the amount of values
800
801 sub random_hex_color {
802 my $size = shift;
803 $size = 6 if $size !~ /^3|6$/;
804 my @hex = ( 0 .. 9, 'a' .. 'f' );
805 my @color;
806 push @color, @hex[rand(@hex)] for 1 .. $size;
807 return join('', '#', @color);
808 }