]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/graphs.pl
rrdimage: Switch graphs.pl to the new graph scripts
[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 ###############################################################################
4 # #
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2005-2010 IPFire Team #
7 # #
8 # This program is free software: you can redistribute it and/or modify #
9 # it under the terms of the GNU General Public License as published by #
10 # the Free Software Foundation, either version 3 of the License, or #
11 # (at your option) any later version. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 # #
21 ###############################################################################
22
23 package Graphs;
24
25 use strict;
26 use RRDs;
27 use experimental 'smartmatch';
28
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32
33 # Graph image size in pixel
34 our %image_size = ('width' => 910, 'height' => 300);
35
36 # List of all available time ranges
37 our @time_ranges = ("hour", "day", "week", "month", "year");
38
39 my $ERROR;
40
41 my @GRAPH_ARGS = (
42 # Output format
43 "--imgformat", "PNG",
44
45 # No border
46 "--border", "0",
47
48 # For a more 'organic' look
49 "--slope-mode",
50
51 # HxW define the size of the output image
52 "--full-size-mode",
53
54 # Watermark
55 "-W www.ipfire.org",
56
57 # Default size
58 "-w $image_size{'width'}",
59 "-h $image_size{'height'}",
60
61 # Use alternative grid
62 "--alt-y-grid",
63 );
64
65 # Read the global settings files to get the current theme and after this load
66 # colors for this theme
67
68 my %color = ();
69 my %mainsettings = ();
70 my %sensorsettings = ();
71 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
72 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
73
74 if ( $mainsettings{'RRDLOG'} eq "" ){
75 $mainsettings{'RRDLOG'}="/var/log/rrd";
76 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
77 }
78
79 # If the collection deamon is working and collecting lm_sensors data there will be
80 # some data source named after a common scheme, with the sensorssettingsfile
81 # the user is able to deactivate some of this parameters, in case not to show
82 # false collected values may be disable. The user has the ability to enter
83 # custom graph names in order to change temp0 to cpu or motherboard
84
85 my $count = 0;
86 my @sensorsgraphs = ();
87 my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/ 2>/dev/null`;
88 foreach (@sensorsdir){
89 chomp($_);chop($_);
90 foreach (`ls $_/*`){
91 chomp($_);
92 push(@sensorsgraphs,$_);
93 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
94 my $label = $2.$3;$label=~ s/-//g;
95 $sensorsettings{'LABEL-'.$label}="$label";
96 $sensorsettings{'LINE-'.$label}="checked";
97 }
98 }
99
100 &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
101
102 # Generate a nice box for selection of time range in graphs
103 # this will generate a nice div box for the cgi every klick for
104 # the graph will be handled by javascript
105 # 0 is the cgi refering to
106 # 1 is the graph name
107 # 2 is the time range for the graph (optional)
108
109 sub makegraphbox {
110 my ($origin, $name, $default_range) = @_;
111
112 # Optional time range: Default to "day" unless otherwise specified
113 $default_range = "day" unless ($default_range ~~ @time_ranges);
114
115 print <<END;
116 <div class="rrdimage" id="rrdimg-$name" data-origin="$origin" data-graph="$name" data-default-range="$default_range">
117 <ul>
118 END
119
120 # Print range select buttons
121 foreach my $range (@time_ranges) {
122 print <<END;
123 <li><button data-range="$range" onclick="rrdimage_selectRange(this)">$Lang::tr{$range}</button></li>
124 END
125 }
126
127 print <<END;
128 </ul>
129 <img src="/cgi-bin/getrrdimage.cgi?origin=${origin}&graph=${name}&range=${default_range}" alt="$Lang::tr{'graph'} ($name)">
130 </div>
131 END
132 }
133
134 # Generate the CPU Graph for the current period of time for values given by
135 # collectd we are now able to handle any kind of cpucount
136
137 sub updatecpugraph {
138 my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`;
139 my $period = $_[0];
140 my @command = (
141 @GRAPH_ARGS,
142 "-",
143 "--start",
144 "-1".$period,
145 "-l 0",
146 "-u 100",
147 "-r",
148 "-t ".$Lang::tr{'cpu usage per'}." ".$Lang::tr{$period."-graph"},
149 "-v ".$Lang::tr{'percentage'},
150 "--color=SHADEA".$color{"color19"},
151 "--color=SHADEB".$color{"color19"},
152 "--color=BACK".$color{"color21"},
153 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
154 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
155 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
156 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
157 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
158 );
159
160 my $nice = "CDEF:nice=";
161 my $interrupt = "CDEF:interrupt=";
162 my $steal = "CDEF:steal=";
163 my $user = "CDEF:user=";
164 my $system = "CDEF:system=";
165 my $idle = "CDEF:idle=";
166 my $iowait = "CDEF:iowait=";
167 my $irq = "CDEF:irq=";
168 my $addstring = "";
169
170 for(my $i = 0; $i < $cpucount; $i++) {
171 push(@command,"DEF:iowait".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-wait.rrd:value:AVERAGE"
172 ,"DEF:nice".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-nice.rrd:value:AVERAGE"
173 ,"DEF:interrupt".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-interrupt.rrd:value:AVERAGE"
174 ,"DEF:steal".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-steal.rrd:value:AVERAGE"
175 ,"DEF:user".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-user.rrd:value:AVERAGE"
176 ,"DEF:system".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-system.rrd:value:AVERAGE"
177 ,"DEF:idle".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-idle.rrd:value:AVERAGE"
178 ,"DEF:irq".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-softirq.rrd:value:AVERAGE");
179
180 $nice .= "nice".$i.",";
181 $interrupt .= "interrupt".$i.",";
182 $steal .= "steal".$i.",";
183 $user .= "user".$i.",";
184 $system .= "system".$i.",";
185 $idle .= "idle".$i.",";
186 $iowait .= "iowait".$i.",";
187 $irq .= "irq".$i.",";
188 }
189
190 for(my $i = 2; $i < $cpucount; $i++) {
191 $addstring .= "ADDNAN,";
192 }
193
194 if ( $cpucount > 1){
195 $addstring .= "+";
196 push(@command,$nice.$addstring
197 ,$interrupt.$addstring
198 ,$steal.$addstring
199 ,$user.$addstring
200 ,$system.$addstring
201 ,$idle.$addstring
202 ,$iowait.$addstring
203 ,$irq.$addstring);
204 }else{
205 chop($nice),chop($interrupt),chop($steal),chop($user),chop($system),chop($idle),chop($iowait),chop($irq);
206 push(@command,$nice,$interrupt,$steal,$user,$system,$idle,$iowait,$irq);
207 }
208
209 push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN"
210 ,"CDEF:userpct=100,user,total,/,*"
211 ,"CDEF:nicepct=100,nice,total,/,*"
212 ,"CDEF:interruptpct=100,interrupt,total,/,*"
213 ,"CDEF:stealpct=100,steal,total,/,*"
214 ,"CDEF:systempct=100,system,total,/,*"
215 ,"CDEF:idlepct=100,idle,total,/,*"
216 ,"CDEF:iowaitpct=100,iowait,total,/,*"
217 ,"CDEF:irqpct=100,irq,total,/,*"
218 ,"AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'})
219 ,"GPRINT:iowaitpct:MAX:%3.2lf%%"
220 ,"GPRINT:iowaitpct:AVERAGE:%3.2lf%%"
221 ,"GPRINT:iowaitpct:MIN:%3.2lf%%"
222 ,"GPRINT:iowaitpct:LAST:%3.2lf%%\\j"
223 ,"STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'})
224 ,"GPRINT:irqpct:MAX:%3.2lf%%"
225 ,"GPRINT:irqpct:AVERAGE:%3.2lf%%"
226 ,"GPRINT:irqpct:MIN:%3.2lf%%"
227 ,"GPRINT:irqpct:LAST:%3.2lf%%\\j"
228 ,"STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'})
229 ,"GPRINT:nicepct:MAX:%3.2lf%%"
230 ,"GPRINT:nicepct:AVERAGE:%3.2lf%%"
231 ,"GPRINT:nicepct:MIN:%3.2lf%%"
232 ,"GPRINT:nicepct:LAST:%3.2lf%%\\j"
233 ,"STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'})
234 ,"GPRINT:interruptpct:MAX:%3.2lf%%"
235 ,"GPRINT:interruptpct:AVERAGE:%3.2lf%%"
236 ,"GPRINT:interruptpct:MIN:%3.2lf%%"
237 ,"GPRINT:interruptpct:LAST:%3.2lf%%\\j"
238 ,"STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'})
239 ,"GPRINT:stealpct:MAX:%3.2lf%%"
240 ,"GPRINT:stealpct:AVERAGE:%3.2lf%%"
241 ,"GPRINT:stealpct:MIN:%3.2lf%%"
242 ,"GPRINT:stealpct:LAST:%3.2lf%%\\j"
243 ,"STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'})
244 ,"GPRINT:userpct:MAX:%3.1lf%%"
245 ,"GPRINT:userpct:AVERAGE:%3.2lf%%"
246 ,"GPRINT:userpct:MIN:%3.2lf%%"
247 ,"GPRINT:userpct:LAST:%3.2lf%%\\j"
248 ,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'})
249 ,"GPRINT:systempct:MAX:%3.2lf%%"
250 ,"GPRINT:systempct:AVERAGE:%3.2lf%%"
251 ,"GPRINT:systempct:MIN:%3.2lf%%"
252 ,"GPRINT:systempct:LAST:%3.2lf%%\\j"
253 ,"STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'})
254 ,"GPRINT:idlepct:MAX:%3.2lf%%"
255 ,"GPRINT:idlepct:AVERAGE:%3.2lf%%"
256 ,"GPRINT:idlepct:MIN:%3.2lf%%"
257 ,"GPRINT:idlepct:LAST:%3.2lf%%\\j");
258
259 RRDs::graph (@command);
260 $ERROR = RRDs::error;
261 return "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
262 }
263
264 # Generate the Load Graph for the current period of time for values given by collecd
265
266 sub updateloadgraph {
267 my $period = $_[0];
268 RRDs::graph(
269 @GRAPH_ARGS,
270 "-",
271 "--start",
272 "-1".$period,
273 "-l 0",
274 "-r",
275 "-t ".$Lang::tr{'uptime load average'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
276 "-v ".$Lang::tr{'processes'},
277 "--color=SHADEA".$color{"color19"},
278 "--color=SHADEB".$color{"color19"},
279 "--color=BACK".$color{"color21"},
280 "DEF:load1=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
281 "DEF:load5=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:midterm:AVERAGE",
282 "DEF:load15=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:longterm:AVERAGE",
283 "AREA:load1".$color{"color13"}."A0:1 ".$Lang::tr{'minute'},
284 "GPRINT:load1:LAST:%5.2lf",
285 "AREA:load5".$color{"color18"}."A0:5 ".$Lang::tr{'minutes'},
286 "GPRINT:load5:LAST:%5.2lf",
287 "AREA:load15".$color{"color14"}."A0:15 ".$Lang::tr{'minutes'},
288 "GPRINT:load15:LAST:%5.2lf\\j",
289 "LINE1:load5".$color{"color13"},
290 "LINE1:load1".$color{"color18"},
291 );
292 $ERROR = RRDs::error;
293 return "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
294 }
295
296 # Generate the Memory Graph for the current period of time for values given by collecd
297
298 sub updatememorygraph {
299 my $period = $_[0];
300 RRDs::graph(
301 @GRAPH_ARGS,
302 "-",
303 "--start",
304 "-1".$period,
305 "-l 0",
306 "-u 100",
307 "-r",
308 "-t ".$Lang::tr{'memory usage per'}." ".$Lang::tr{$period."-graph"},
309 "-v ".$Lang::tr{'percentage'},
310 "--color=SHADEA".$color{"color19"},
311 "--color=SHADEB".$color{"color19"},
312 "--color=BACK".$color{"color21"},
313 "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
314 "DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
315 "DEF:buffer=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
316 "DEF:cache=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
317 "CDEF:total=used,free,cache,buffer,+,+,+",
318 "CDEF:usedpct=used,total,/,100,*",
319 "CDEF:bufferpct=buffer,total,/,100,*",
320 "CDEF:cachepct=cache,total,/,100,*",
321 "CDEF:freepct=free,total,/,100,*",
322 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
323 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
324 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
325 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
326 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
327 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used memory'}),
328 "GPRINT:usedpct:MAX:%3.2lf%%",
329 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
330 "GPRINT:usedpct:MIN:%3.2lf%%",
331 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
332 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'buffered memory'}),
333 "GPRINT:bufferpct:MAX:%3.2lf%%",
334 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
335 "GPRINT:bufferpct:MIN:%3.2lf%%",
336 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
337 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'cached memory'}),
338 "GPRINT:cachepct:MAX:%3.2lf%%",
339 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
340 "GPRINT:cachepct:MIN:%3.2lf%%",
341 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
342 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free memory'}),
343 "GPRINT:freepct:MAX:%3.2lf%%",
344 "GPRINT:freepct:AVERAGE:%3.2lf%%",
345 "GPRINT:freepct:MIN:%3.2lf%%",
346 "GPRINT:freepct:LAST:%3.2lf%%\\j",
347 );
348 $ERROR = RRDs::error;
349 return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
350 }
351
352 # Generate the Swap Graph for the current period of time for values given by collecd
353
354 sub updateswapgraph {
355 my $period = $_[0];
356 RRDs::graph(
357 @GRAPH_ARGS,
358 "-",
359 "--start",
360 "-1".$period,
361 "-l 0",
362 "-u 100",
363 "-r",
364 "-t ".$Lang::tr{'swap usage per'}." ".$Lang::tr{$period."-graph"},
365 "-v ".$Lang::tr{'percentage'},
366 "--color=SHADEA".$color{"color19"},
367 "--color=SHADEB".$color{"color19"},
368 "--color=BACK".$color{"color21"},
369 "DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
370 "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
371 "DEF:cached=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
372 "CDEF:total=used,free,cached,+,+",
373 "CDEF:usedpct=100,used,total,/,*",
374 "CDEF:freepct=100,free,total,/,*",
375 "CDEF:cachedpct=100,cached,total,/,*",
376 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
377 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
378 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
379 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
380 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
381 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used swap'}),
382 "GPRINT:usedpct:MAX:%3.2lf%%",
383 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
384 "GPRINT:usedpct:MIN:%3.2lf%%",
385 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
386 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}),
387 "GPRINT:cachedpct:MAX:%3.2lf%%",
388 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
389 "GPRINT:cachedpct:MIN:%3.2lf%%",
390 "GPRINT:cachedpct:LAST:%3.2lf%%\\j",
391 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
392 "GPRINT:freepct:MAX:%3.2lf%%",
393 "GPRINT:freepct:AVERAGE:%3.2lf%%",
394 "GPRINT:freepct:MIN:%3.2lf%%",
395 "GPRINT:freepct:LAST:%3.2lf%%\\j",
396 );
397 $ERROR = RRDs::error;
398 return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
399 }
400
401 # Generate the Process Cpu Graph for the current period of time for values given by collecd
402
403 sub updateprocessescpugraph {
404 my @processesgraph = getprocesses();
405 my $period = $_[0];
406 my $count="0";
407
408 my @command = (
409 @GRAPH_ARGS,
410 "-",
411 "--start",
412 "-1".$period,
413 "-l 0",
414 "-r",
415 "-t ".$Lang::tr{'processes'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
416 "--color=SHADEA".$color{"color19"},
417 "--color=SHADEB".$color{"color19"},
418 "--color=BACK".$color{"color21"}
419 );
420
421 foreach(@processesgraph){
422 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
423 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
424 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
425 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");
426 }
427
428 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
429
430 my $colorIndex = 0;
431 foreach(@processesgraph){
432 my $colorIndex = 10 + $count % 15;
433 my $color="$color{\"color$colorIndex\"}";
434 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
435 if ($count eq "0"){
436 push(@command,"AREA:".$name[1].$color."A0:".$name[1]);
437 }else{
438 push(@command,"STACK:".$name[1].$color."A0:".$name[1]);
439 }
440 $count++;
441 }
442
443 RRDs::graph (@command);
444 $ERROR = RRDs::error;
445 return "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
446 }
447
448 # Generate the Process Memory Graph for the current period of time for values given by collecd
449
450 sub updateprocessesmemorygraph {
451 my @processesgraph = getprocesses();
452 my $period = $_[0];
453 my $count="0";
454
455 my @command = (
456 @GRAPH_ARGS,
457 "-",
458 "--start",
459 "-1".$period,
460 "-l 0",
461 "-r",
462 "-t ".$Lang::tr{'processes'}." ".$Lang::tr{'memory'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
463 "-v ".$Lang::tr{'bytes'},
464 "--color=SHADEA".$color{"color19"},
465 "--color=SHADEB".$color{"color19"},
466 "--color=BACK".$color{"color21"}
467 );
468
469 foreach(@processesgraph){
470 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
471 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");
472 }
473
474 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
475
476 my $colorIndex = 0;
477 foreach(@processesgraph){
478 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
479 my $colorIndex = 10 + $count % 15;
480 my $color="$color{\"color$colorIndex\"}";
481 if ($count eq "0"){
482 push(@command,"AREA:".$name[1].$color."A0:".$name[1]);
483 }else{
484 push(@command,"STACK:".$name[1].$color."A0:".$name[1]);
485 }
486 $count++;
487 }
488
489 RRDs::graph (@command);
490 $ERROR = RRDs::error;
491 return "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
492 }
493
494 # Generate the Disk Graph for the current period of time for values given by collecd
495
496 sub updatediskgraph {
497 my $disk = $_[0];
498 my $period = $_[1];
499 RRDs::graph(
500 @GRAPH_ARGS,
501 "-",
502 "--start",
503 "-1".$period,
504 "-r",
505 "-t ".$disk." ".$Lang::tr{'disk access'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
506 "-v ".$Lang::tr{'bytes per second'},
507 "--color=SHADEA".$color{"color19"},
508 "--color=SHADEB".$color{"color19"},
509 "--color=BACK".$color{"color21"},
510 "DEF:read=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
511 "DEF:write=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
512 "CDEF:writen=write,-1,*",
513 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-".$disk.".rrd:standby:AVERAGE",
514 "CDEF:st=standby,INF,*",
515 "CDEF:st1=standby,NEGINF,*",
516 "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}),
517 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
518 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
519 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
520 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
521 "AREA:st".$color{"color20"}."A0:",
522 "AREA:st1".$color{"color20"}."A0:standby\\j",
523 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
524 "GPRINT:read:MAX:%8.1lf %sBps",
525 "GPRINT:read:AVERAGE:%8.1lf %sBps",
526 "GPRINT:read:MIN:%8.1lf %sBps",
527 "GPRINT:read:LAST:%8.1lf %sBps\\j",
528 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
529 "GPRINT:write:MAX:%8.1lf %sBps",
530 "GPRINT:write:AVERAGE:%8.1lf %sBps",
531 "GPRINT:write:MIN:%8.1lf %sBps",
532 "GPRINT:write:LAST:%8.1lf %sBps\\j",
533 );
534 $ERROR = RRDs::error;
535 return "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
536 }
537
538 # Generate the Interface Graph for the current period of time for values given by collecd
539
540 sub updateifgraph {
541 my $interface = $_[0];
542 my $period = $_[1];
543 RRDs::graph(
544 @GRAPH_ARGS,
545 "-",
546 "--start",
547 "-1".$period,
548 "-r",
549 "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
550 "-v ".$Lang::tr{'bytes per second'},
551 "--color=SHADEA".$color{"color19"},
552 "--color=SHADEB".$color{"color19"},
553 "--color=BACK".$color{"color21"},
554 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:rx:AVERAGE",
555 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:tx:AVERAGE",
556 "CDEF:outgoingn=outgoing,-1,*",
557 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
558 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
559 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
560 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
561 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
562 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
563 "GPRINT:incoming:MAX:%8.1lf %sBps",
564 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
565 "GPRINT:incoming:MIN:%8.1lf %sBps",
566 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
567 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
568 "GPRINT:outgoing:MAX:%8.1lf %sBps",
569 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
570 "GPRINT:outgoing:MIN:%8.1lf %sBps",
571 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
572 );
573 $ERROR = RRDs::error;
574 return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
575 }
576
577 sub updatevpngraph {
578 my $interface = $_[0];
579 my $period = $_[1];
580 RRDs::graph(
581 @GRAPH_ARGS,
582 "-",
583 "--start",
584 "-1".$period,
585 "-r",
586 "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
587 "-v ".$Lang::tr{'bytes per second'},
588 "--color=SHADEA".$color{"color19"},
589 "--color=SHADEB".$color{"color19"},
590 "--color=BACK".$color{"color21"},
591 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive.rrd:rx:AVERAGE",
592 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive.rrd:tx:AVERAGE",
593 "CDEF:outgoingn=outgoing,-1,*",
594 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
595 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
596 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
597 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
598 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
599 "AREA:incoming#00dd00:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
600 "GPRINT:incoming:MAX:%8.1lf %sBps",
601 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
602 "GPRINT:incoming:MIN:%8.1lf %sBps",
603 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
604 "AREA:outgoingn#dd0000:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
605 "GPRINT:outgoing:MAX:%8.1lf %sBps",
606 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
607 "GPRINT:outgoing:MIN:%8.1lf %sBps",
608 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
609 );
610 $ERROR = RRDs::error;
611 return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
612 }
613
614 sub updatevpnn2ngraph {
615 my $interface = $_[0];
616 my $period = $_[1];
617 RRDs::graph(
618 @GRAPH_ARGS,
619 "-",
620 "--start",
621 "-1".$period,
622 "-r",
623 "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
624 "-v ".$Lang::tr{'bytes per second'},
625 "--color=SHADEA".$color{"color19"},
626 "--color=SHADEB".$color{"color19"},
627 "--color=BACK".$color{"color21"},
628 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive-traffic.rrd:rx:AVERAGE",
629 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive-traffic.rrd:tx:AVERAGE",
630 "DEF:overhead_in=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive-overhead.rrd:rx:AVERAGE",
631 "DEF:overhead_out=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets_derive-overhead.rrd:tx:AVERAGE",
632 "DEF:compression_in=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/compression_derive-data_in.rrd:uncompressed:AVERAGE",
633 "DEF:compression_out=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/compression_derive-data_out.rrd:uncompressed:AVERAGE",
634 "CDEF:outgoingn=outgoing,-1,*",
635 "CDEF:overhead_outn=overhead_out,-1,*",
636 "CDEF:compression_outn=compression_out,-1,*",
637 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
638 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
639 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
640 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
641 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
642 "AREA:incoming#00dd00:".sprintf("%-23s",$Lang::tr{'incoming traffic in bytes per second'}),
643 "GPRINT:incoming:MAX:%8.1lf %sBps",
644 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
645 "GPRINT:incoming:MIN:%8.1lf %sBps",
646 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
647 "STACK:overhead_in#116B11:".sprintf("%-23s",$Lang::tr{'incoming overhead in bytes per second'}),
648 "GPRINT:overhead_in:MAX:%8.1lf %sBps",
649 "GPRINT:overhead_in:AVERAGE:%8.1lf %sBps",
650 "GPRINT:overhead_in:MIN:%8.1lf %sBps",
651 "GPRINT:overhead_in:LAST:%8.1lf %sBps\\j",
652 "LINE1:compression_in#ff00ff:".sprintf("%-23s",$Lang::tr{'incoming compression in bytes per second'}),
653 "GPRINT:compression_in:MAX:%8.1lf %sBps",
654 "GPRINT:compression_in:AVERAGE:%8.1lf %sBps",
655 "GPRINT:compression_in:MIN:%8.1lf %sBps",
656 "GPRINT:compression_in:LAST:%8.1lf %sBps\\j",
657 "AREA:outgoingn#dd0000:".sprintf("%-23s",$Lang::tr{'outgoing traffic in bytes per second'}),
658 "GPRINT:outgoing:MAX:%8.1lf %sBps",
659 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
660 "GPRINT:outgoing:MIN:%8.1lf %sBps",
661 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
662 "STACK:overhead_outn#870C0C:".sprintf("%-23s",$Lang::tr{'outgoing overhead in bytes per second'}),
663 "GPRINT:overhead_out:MAX:%8.1lf %sBps",
664 "GPRINT:overhead_out:AVERAGE:%8.1lf %sBps",
665 "GPRINT:overhead_out:MIN:%8.1lf %sBps",
666 "GPRINT:overhead_out:LAST:%8.1lf %sBps\\j",
667 "LINE1:compression_outn#000000:".sprintf("%-23s",$Lang::tr{'outgoing compression in bytes per second'}),
668 "GPRINT:compression_out:MAX:%8.1lf %sBps",
669 "GPRINT:compression_out:AVERAGE:%8.1lf %sBps",
670 "GPRINT:compression_out:MIN:%8.1lf %sBps",
671 "GPRINT:compression_out:LAST:%8.1lf %sBps\\j",
672 );
673 $ERROR = RRDs::error;
674 return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
675 }
676
677 # Generate the Firewall Graph for the current period of time for values given by collecd
678
679 sub updatefwhitsgraph {
680 my $period = $_[0];
681 RRDs::graph(
682 @GRAPH_ARGS,
683 "-",
684 "--start",
685 "-1".$period,
686 "-r",
687 "-t ".$Lang::tr{'firewall hits per'}." ".$Lang::tr{$period."-graph"},
688 "-v ".$Lang::tr{'bytes per second'},
689 "--color=SHADEA".$color{"color19"},
690 "--color=SHADEB".$color{"color19"},
691 "--color=BACK".$color{"color21"},
692 "DEF:output=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYOUT/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
693 "DEF:input=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYIN/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
694 "DEF:forward=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYFWD/ipt_bytes-DROP_FORWARD.rrd:value:AVERAGE",
695 "DEF:newnotsyn=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
696 "DEF:portscan=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
697 "COMMENT:".sprintf("%-26s",$Lang::tr{'caption'}),
698 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
699 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
700 "COMMENT:".sprintf("%14s",$Lang::tr{'minimal'}),
701 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
702 "AREA:output".$color{"color25"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (OUTPUT)"),
703 "GPRINT:output:MAX:%8.1lf %sBps",
704 "GPRINT:output:AVERAGE:%8.1lf %sBps",
705 "GPRINT:output:MIN:%8.1lf %sBps",
706 "GPRINT:output:LAST:%8.1lf %sBps\\j",
707 "STACK:forward".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (FORWARD)"),
708 "GPRINT:forward:MAX:%8.1lf %sBps",
709 "GPRINT:forward:AVERAGE:%8.1lf %sBps",
710 "GPRINT:forward:MIN:%8.1lf %sBps",
711 "GPRINT:forward:LAST:%8.1lf %sBps\\j",
712 "STACK:input".$color{"color24"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (INPUT)"),
713 "GPRINT:input:MAX:%8.1lf %sBps",
714 "GPRINT:input:AVERAGE:%8.1lf %sBps",
715 "GPRINT:input:MIN:%8.1lf %sBps",
716 "GPRINT:input:LAST:%8.1lf %sBps\\j",
717 "STACK:newnotsyn".$color{"color14"}."A0:".sprintf("%-25s","NewNotSYN"),
718 "GPRINT:newnotsyn:MAX:%8.1lf %sBps",
719 "GPRINT:newnotsyn:AVERAGE:%8.1lf %sBps",
720 "GPRINT:newnotsyn:MIN:%8.1lf %sBps",
721 "GPRINT:newnotsyn:LAST:%8.1lf %sBps\\j",
722 "STACK:portscan".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'portscans'}),
723 "GPRINT:portscan:MAX:%8.1lf %sBps",
724 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
725 "GPRINT:portscan:MIN:%8.1lf %sBps",
726 "GPRINT:portscan:LAST:%8.1lf %sBps\\j",
727 );
728 $ERROR = RRDs::error;
729 return "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
730 }
731
732 # Generate the Line Quality Graph for the current period of time for values given by collecd
733
734 sub updatepinggraph {
735 my $period = $_[1];
736 my $host = $_[0];
737 RRDs::graph(
738 @GRAPH_ARGS,
739 "-",
740 "--start",
741 "-1".$period,
742 "-l 0",
743 "-r",
744 "-t ".$Lang::tr{'linkq'}." ".$host." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
745 "-v ms",
746 "--color=SHADEA".$color{"color19"},
747 "--color=SHADEB".$color{"color19"},
748 "--color=BACK".$color{"color21"},
749 "DEF:roundtrip=".$mainsettings{'RRDLOG'}."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE",
750 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
751 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
752 "CDEF:r0=roundtrip,30,MIN",
753 "CDEF:r1=roundtrip,70,MIN",
754 "CDEF:r2=roundtrip,150,MIN",
755 "CDEF:r3=roundtrip,300,MIN",
756 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
757 "AREA:r3".$color{"color18"}."A0:150-300 ms",
758 "AREA:r2".$color{"color14"}."A0:70-150 ms",
759 "AREA:r1".$color{"color17"}."A0:30-70 ms",
760 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
761 "COMMENT:$Lang::tr{'maximal'}",
762 "COMMENT:$Lang::tr{'average'}",
763 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
764 "LINE1:roundtrip#707070:",
765 "GPRINT:roundtrip:MAX:%3.2lf ms",
766 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
767 "GPRINT:roundtrip:MIN:%3.2lf ms",
768 "GPRINT:roundtrip:LAST:%3.2lf ms\\j",
769 );
770 $ERROR = RRDs::error;
771 return "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
772 }
773
774 sub updatewirelessgraph {
775 my $period = $_[1];
776 my $interface = $_[0];
777 RRDs::graph(
778 @GRAPH_ARGS,
779 "-",
780 "--start",
781 "-1".$period,
782 "-t Wireless ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
783 "-v dBm",
784 "--color=SHADEA".$color{"color19"},
785 "--color=SHADEB".$color{"color19"},
786 "--color=BACK".$color{"color21"},
787 "DEF:noise=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_noise.rrd:value:AVERAGE",
788 "DEF:power=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_power.rrd:value:AVERAGE",
789 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
790 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
791 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
792 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
793 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
794 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
795 "GPRINT:noise:MAX:%5.1lf %sdBm",
796 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
797 "GPRINT:noise:MIN:%5.1lf %sdBm",
798 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
799 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
800 "GPRINT:power:MAX:%5.1lf %sdBm",
801 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
802 "GPRINT:power:MIN:%5.1lf %sdBm",
803 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
804 );
805 $ERROR = RRDs::error;
806 return "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
807 }
808
809 # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
810
811 sub updatehddgraph {
812 my $disk = $_[0];
813 my $period = $_[1];
814 RRDs::graph(
815 @GRAPH_ARGS,
816 "-",
817 "--start",
818 "-1".$period,
819 "-r",
820 "-t ".$disk." ".$Lang::tr{'harddisk temperature'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
821 "-v Celsius",
822 "--color=SHADEA".$color{"color19"},
823 "--color=SHADEB".$color{"color19"},
824 "--color=BACK".$color{"color21"},
825 "DEF:temperature=".$mainsettings{'RRDLOG'}."/hddtemp-$disk.rrd:temperature:AVERAGE",
826 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-$disk.rrd:standby:AVERAGE",
827 "CDEF:st=standby,INF,*",
828 "AREA:st".$color{"color20"}."A0:standby",
829 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} °C\\j",
830 "COMMENT:$Lang::tr{'maximal'}",
831 "COMMENT:$Lang::tr{'average'}",
832 "COMMENT:$Lang::tr{'minimal'}",
833 "COMMENT:$Lang::tr{'current'}\\j",
834 "GPRINT:temperature:MAX:%3.0lf °C",
835 "GPRINT:temperature:AVERAGE:%3.0lf °C",
836 "GPRINT:temperature:MIN:%3.0lf °C",
837 "GPRINT:temperature:LAST:%3.0lf °C\\j",
838 );
839 $ERROR = RRDs::error;
840 return "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
841 }
842
843 # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
844
845 sub updatehwtempgraph {
846 my $period = $_[0];
847
848 my @command = (
849 @GRAPH_ARGS,
850 "-",
851 "--start",
852 "-1".$period,
853 "-r",
854 "-t ".$Lang::tr{'mbmon temp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
855 "-v Celsius",
856 "--color=SHADEA".$color{"color19"},
857 "--color=SHADEB".$color{"color19"},
858 "--color=BACK".$color{"color21"},
859 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
860 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
861 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
862 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
863 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
864 );
865
866 foreach(@sensorsgraphs){
867 chomp($_);
868 if ( $_ =~ /temperature/ ) {
869 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
870 my $label = $2.$3;$label=~ s/-//g;
871 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
872 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
873 }
874 }
875
876 foreach(@sensorsgraphs){
877 chomp($_);
878 if ( $_ =~ /temperature/ ){
879 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
880 my $label = $2.$3;$label=~ s/-//g;
881 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
882 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",);
883 }
884 }
885
886 RRDs::graph (@command);
887 $ERROR = RRDs::error;
888 return "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
889 }
890
891 # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
892
893 sub updatehwfangraph {
894 my $period = $_[0];
895
896 my @command = (
897 @GRAPH_ARGS,
898 "-",
899 "--start",
900 "-1".$period,
901 "-r",
902 "-t ".$Lang::tr{'mbmon fan'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
903 "--color=SHADEA".$color{"color19"},
904 "--color=SHADEB".$color{"color19"},
905 "--color=BACK".$color{"color21"},
906 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
907 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
908 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
909 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
910 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
911 );
912
913 foreach(@sensorsgraphs){
914 chomp($_);
915 if ( $_ =~ /fanspeed/ ) {
916 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
917 my $label = $2.$3;$label=~ s/-//g;
918 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
919 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
920 }
921 }
922
923 foreach(@sensorsgraphs){
924 chomp($_);
925 if ( $_ =~ /fanspeed/ ){
926 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
927 my $label = $2.$3;$label=~ s/-//g;
928 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
929 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",);
930 }
931 }
932
933 RRDs::graph (@command);
934 $ERROR = RRDs::error;
935 return "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
936 }
937
938 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
939
940 sub updatehwvoltgraph {
941 my $period = $_[0];
942
943 my @command = (
944 @GRAPH_ARGS,
945 "-",
946 "--start",
947 "-1".$period,
948 "-r",
949 "-t ".$Lang::tr{'mbmon volt'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
950 "--color=SHADEA".$color{"color19"},
951 "--color=SHADEB".$color{"color19"},
952 "--color=BACK".$color{"color21"},
953 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
954 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
955 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
956 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
957 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
958 );
959
960 foreach(@sensorsgraphs){
961 chomp($_);
962 if ( $_ =~ /voltage/ ) {
963 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
964 my $label = $2.$3;$label=~ s/-//g;
965 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
966 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
967 }
968 }
969
970 foreach(@sensorsgraphs){
971 chomp($_);
972 if ( $_ =~ /voltage/ ){
973 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
974 my $label = $2.$3;$label=~ s/-//g;
975 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
976 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",);
977 }
978 }
979
980 RRDs::graph (@command);
981 $ERROR = RRDs::error;
982 return "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
983 }
984
985
986 # Generate the QoS Graph for the current period of time
987
988 sub updateqosgraph {
989
990 my $period = $_[1];
991 my %qossettings = ();
992 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
993
994 my $classentry = "";
995 my @classes = ();
996 my @classline = ();
997 my $classfile = "/var/ipfire/qos/classes";
998
999 $qossettings{'DEV'} = $_[0];
1000 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
1001 $qossettings{'CLASSPRFX'} = '1';
1002 } else {
1003 $qossettings{'CLASSPRFX'} = '2';
1004 }
1005
1006 my $ERROR="";
1007 my $count="1";
1008 my %colorMap = (); # maps traffic classes to graph colors
1009
1010 my @command = (
1011 @GRAPH_ARGS,
1012 "-",
1013 "--start",
1014 "-1".$period,
1015 "-r",
1016 "-t ".$Lang::tr{'Utilization on'}." (".$qossettings{'DEV'}.") ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
1017 "-v ".$Lang::tr{'bytes per second'},
1018 "--color=SHADEA".$color{"color19"},
1019 "--color=SHADEB".$color{"color19"},
1020 "--color=BACK".$color{"color21"},
1021 "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}),
1022 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1023 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1024 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
1025 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
1026 );
1027
1028 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
1029 @classes = <FILE>;
1030 close FILE;
1031
1032 foreach $classentry (sort @classes){
1033 @classline = split( /\;/, $classentry );
1034
1035 # create class <-> color mapping
1036 my $colorKey = uc $classline[8]; # upper case class name as key
1037 if(! exists $colorMap{$colorKey}) {
1038 # add missing color to table, use colors 11-25
1039 my $colorIndex = 11 + ((scalar keys %colorMap) % 15);
1040 $colorMap{$colorKey} = "$color{\"color$colorIndex\"}";
1041 }
1042
1043 if ( $classline[0] eq $qossettings{'DEV'} ){
1044 push(@command, "DEF:$classline[1]=$mainsettings{'RRDLOG'}/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
1045
1046 # get color to be used for this graph
1047 my $graphColor = $colorMap{$colorKey};
1048
1049 if ($count eq "1") {
1050 push(@command, "AREA:$classline[1]$graphColor:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8]));
1051 } else {
1052 push(@command, "STACK:$classline[1]$graphColor:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8]));
1053 }
1054
1055 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps"
1056 , "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps"
1057 , "GPRINT:$classline[1]:MIN:%8.1lf %sBps"
1058 , "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
1059 $count++;
1060 }
1061 }
1062 RRDs::graph (@command);
1063 $ERROR = RRDs::error;
1064 return "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR;
1065 }
1066
1067 # Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
1068
1069 sub updatecpufreqgraph {
1070 my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`;
1071 my $period = $_[0];
1072 my @command = (
1073 @GRAPH_ARGS,
1074 "-",
1075 "--start",
1076 "-1".$period,
1077 "-r",
1078 "-t ".$Lang::tr{'cpu frequency per'}." ".$Lang::tr{$period."-graph"},
1079 "-v MHz",
1080 "--color=SHADEA".$color{"color19"},
1081 "--color=SHADEB".$color{"color19"},
1082 "--color=BACK".$color{"color21"},
1083 "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
1084 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1085 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1086 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
1087 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
1088 );
1089
1090 for(my $i = 0; $i < $cpucount; $i++) {
1091 my $j=$i+1;
1092 push(@command,"DEF:cpu".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpufreq/cpufreq-".$i.".rrd:value:AVERAGE"
1093 ,"CDEF:cpu".$i."=cpu".$i."_,1000000,/"
1094 ,"LINE1:cpu".$i.$color{"color1$j"}."A0:cpu ".$i." "
1095 ,"GPRINT:cpu".$i.":MAX:%3.0lf Mhz"
1096 ,"GPRINT:cpu".$i.":AVERAGE:%3.0lf Mhz"
1097 ,"GPRINT:cpu".$i.":MIN:%3.0lf Mhz"
1098 ,"GPRINT:cpu".$i.":LAST:%3.0lf Mhz\\j");
1099 }
1100
1101 RRDs::graph (@command);
1102 $ERROR = RRDs::error;
1103 return "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
1104 }
1105
1106 # Generate the Thermal Zone Temp CPU Graph
1107
1108 sub updatethermaltempgraph {
1109 my $thermalcount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone* 2>/dev/null | wc -l`;
1110 my $period = $_[0];
1111 my @command = (
1112 @GRAPH_ARGS,
1113 "-",
1114 "--start",
1115 "-1".$period,
1116 "-r",
1117 "-t ".$Lang::tr{'acpitemp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
1118 "-v Celsius",
1119 "--color=SHADEA".$color{"color19"},
1120 "--color=SHADEB".$color{"color19"},
1121 "--color=BACK".$color{"color21"},
1122 "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
1123 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1124 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1125 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
1126 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
1127 );
1128
1129 for(my $i = 0; $i < $thermalcount; $i++) {
1130 my $j=$i+1;
1131 push(@command,"DEF:temp".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/thermal-thermal_zone".$i."/temperature-temperature.rrd:value:AVERAGE"
1132 ,"CDEF:temp".$i."=temp".$i."_,1,/"
1133 ,"LINE3:temp".$i.$color{"color1$j"}."A0:Temp ".$i." "
1134 ,"GPRINT:temp".$i.":MAX:%3.0lf °C"
1135 ,"GPRINT:temp".$i.":AVERAGE:%3.0lf °C"
1136 ,"GPRINT:temp".$i.":MIN:%3.0lf °C"
1137 ,"GPRINT:temp".$i.":LAST:%3.0lf °C\\j");
1138 }
1139
1140 RRDs::graph (@command);
1141 $ERROR = RRDs::error;
1142 return "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR;
1143 }
1144
1145
1146 # Generate a random color, used by Qos Graph to be independent from the amount of values
1147
1148 sub random_hex_color {
1149 my $size = shift;
1150 $size = 6 if $size !~ /^3|6$/;
1151 my @hex = ( 0 .. 9, 'a' .. 'f' );
1152 my @color;
1153 push @color, @hex[rand(@hex)] for 1 .. $size;
1154 return join('', '#', @color);
1155 }
1156
1157 sub getprocesses {
1158 my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/ 2>/dev/null`;
1159 return @processesgraph;
1160 }
1161
1162 sub updateentropygraph {
1163 my $period = $_[0];
1164 my @command = (
1165 @GRAPH_ARGS,
1166 "-",
1167 "--start",
1168 "-1".$period,
1169 "-r",
1170 "--lower-limit","0",
1171 "-t ".$Lang::tr{'entropy'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
1172 "-v $Lang::tr{'bit'}",
1173 "DEF:entropy=$mainsettings{'RRDLOG'}/collectd/localhost/entropy/entropy.rrd:entropy:AVERAGE",
1174 "LINE3:entropy#ff0000:" . sprintf("%-15s", $Lang::tr{'entropy'}),
1175 "VDEF:entrmin=entropy,MINIMUM",
1176 "VDEF:entrmax=entropy,MAXIMUM",
1177 "VDEF:entravg=entropy,AVERAGE",
1178 "GPRINT:entrmax:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'maximum'}),
1179 "GPRINT:entrmin:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'minimum'}),
1180 "GPRINT:entravg:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'average'}) . "\\n",
1181 "--color=BACK".$color{"color21"},
1182 );
1183
1184 RRDs::graph (@command);
1185 $ERROR = RRDs::error;
1186
1187 return "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR;
1188 }
1189
1190 sub updateconntrackgraph {
1191 my $period = $_[0];
1192 my @command = (
1193 @GRAPH_ARGS,
1194 "-",
1195 "--start",
1196 "-1" . $period,
1197 "-r",
1198 "--lower-limit","0",
1199 "-t $Lang::tr{'connection tracking'}",
1200 "-v $Lang::tr{'open connections'}",
1201 "DEF:conntrack=$mainsettings{'RRDLOG'}/collectd/localhost/conntrack/conntrack.rrd:entropy:AVERAGE",
1202 "LINE3:conntrack#ff0000:" . sprintf("%-15s", $Lang::tr{'open connections'}),
1203 "VDEF:ctmin=conntrack,MINIMUM",
1204 "VDEF:ctmax=conntrack,MAXIMUM",
1205 "VDEF:ctavg=conntrack,AVERAGE",
1206 "GPRINT:ctmax:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'maximum'}),
1207 "GPRINT:ctmin:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'minimum'}),
1208 "GPRINT:ctavg:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'average'}) . "\\n",
1209 "--color=BACK" . $color{"color21"},
1210 );
1211
1212 RRDs::graph(@command);
1213 $ERROR = RRDs::error;
1214
1215 return "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR;
1216 }