2 # Generate Graphs exported from Makegraphs to minimize system load an only generate the Graphs when displayed
3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
21 ###############################################################################
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
33 my $rrdlog = "/var/log/rrd";
34 my $graphs = "/srv/web/ipfire/html/graphs";
35 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
37 # Read the global settings files to get the current theme and after this load
38 # colors for this theme
41 my %mainsettings = ();
42 my %sensorsettings = ();
43 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
44 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
46 # If the collection deamon is working and collecting lm_sensors data there will be
47 # some data source named after a common scheme, with the sensorssettingsfile
48 # the user is able to deactivate some of this parameters, in case not to show
49 # false collected values may be disable. The user has the ability to enter
50 # custom graph names in order to change temp0 to cpu or motherboard
56 my @sensorsgraphs = ();
57 my $cpucount = `ls -dA /media/ramd/rrd/collectd/localhost/cpu-*/ | wc -l`;
58 my @processesgraph = `ls -dA $rrdlog/collectd/localhost/processes-*/`;
59 my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`;
65 push(@sensorsgraphs,$_);
66 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
67 my $label = $2.$3;$label=~ s/-//g;
68 $sensorsettings{'LABEL-'.$label}="$label";
69 $sensorsettings{'LINE-'.$label}="checked";
73 &General
::readhash
("${General::swroot}/sensors/settings", \
%sensorsettings);
77 if ((${Lang
::language
} eq 'el') ||
78 (${Lang
::language
} eq 'fa') ||
79 (${Lang
::language
} eq 'ru') ||
80 (${Lang
::language
} eq 'th') ||
81 (${Lang
::language
} eq 'vi') ||
82 (${Lang
::language
} eq 'zh') ||
83 (${Lang
::language
} eq 'zt')) {
84 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
85 } else {%tr=%Lang::tr
;}
87 # Generate a nice box for selection of time range in graphs
88 # this will generate a nice iframe for the cgi every klick for
89 # the graph will be handled inside the iframe
90 # 0 is the cgi refering to
92 # 2 is the time range for the graph
93 # 3 if given is the height of the iframe default if nothing is given
99 if ( $_[3] ne "" ){ $height = $_[3]; }
102 print "<a href='".$_[0]."?".$_[1]."?hour' target='".$_[1]."box'>Hour</a>";
104 print "<a href='".$_[0]."?".$_[1]."?day' target='".$_[1]."box'>Day</a>";
106 print "<a href='".$_[0]."?".$_[1]."?week' target='".$_[1]."box'>Week</a>";
108 print "<a href='".$_[0]."?".$_[1]."?month' target='".$_[1]."box'>Month</a>";
110 print "<a href='".$_[0]."?".$_[1]."?year' target='".$_[1]."box'>Year</a>";
111 print "<iframe src='".$_[0]."?".$_[1]."?".$_[2]."' width='".$width."' height='".$height."' scrolling='no' frameborder='no' marginheight='0' name='".$_[1]."box'></iframe>";
115 # Generate the CPU Graph for the current period of time for values given by
116 # collectd we are now able to handle any kind of cpucount
134 "-t ".$Lang::tr
{'cpu usage per'}." ".$Lang::tr
{$period},
135 "-v ".$Lang::tr
{'percentage'},
136 "--color=SHADEA".$color{"color19"},
137 "--color=SHADEB".$color{"color19"},
138 "--color=BACK".$color{"color21"},
139 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
140 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
141 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
142 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
143 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
146 my $nice = "CDEF:nice=";
147 my $interrupt = "CDEF:interrupt=";
148 my $steal = "CDEF:steal=";
149 my $user = "CDEF:user=";
150 my $system = "CDEF:system=";
151 my $idle = "CDEF:idle=";
152 my $iowait = "CDEF:iowait=";
153 my $irq = "CDEF:irq=";
156 for(my $i = 0; $i < $cpucount; $i++) {
157 push(@command,"DEF:iowait".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-wait.rrd:value:AVERAGE");
158 push(@command,"DEF:nice".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-nice.rrd:value:AVERAGE");
159 push(@command,"DEF:interrupt".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-interrupt.rrd:value:AVERAGE");
160 push(@command,"DEF:steal".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-steal.rrd:value:AVERAGE");
161 push(@command,"DEF:user".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-user.rrd:value:AVERAGE");
162 push(@command,"DEF:system".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-system.rrd:value:AVERAGE");
163 push(@command,"DEF:idle".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-idle.rrd:value:AVERAGE");
164 push(@command,"DEF:irq".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-softirq.rrd:value:AVERAGE");
165 $nice .= "nice".$i.",";
166 $interrupt .= "interrupt".$i.",";
167 $steal .= "steal".$i.",";
168 $user .= "user".$i.",";
169 $system .= "system".$i.",";
170 $idle .= "idle".$i.",";
171 $iowait .= "iowait".$i.",";
172 $irq .= "irq".$i.",";
175 for(my $i = 2; $i < $cpucount; $i++) {
181 push(@command,$nice.$addstring);
182 push(@command,$interrupt.$addstring);
183 push(@command,$steal.$addstring);
184 push(@command,$user.$addstring);
185 push(@command,$system.$addstring);
186 push(@command,$idle.$addstring);
187 push(@command,$iowait.$addstring);
188 push(@command,$irq.$addstring);
190 push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+");
191 push(@command,"CDEF:userpct=100,user,total,/,*");
192 push(@command,"CDEF:nicepct=100,nice,total,/,*");
193 push(@command,"CDEF:interruptpct=100,interrupt,total,/,*");
194 push(@command,"CDEF:stealpct=100,steal,total,/,*");
195 push(@command,"CDEF:systempct=100,system,total,/,*");
196 push(@command,"CDEF:idlepct=100,idle,total,/,*");
197 push(@command,"CDEF:iowaitpct=100,iowait,total,/,*");
198 push(@command,"CDEF:irqpct=100,irq,total,/,*");
199 push(@command,"AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr
{'cpu iowait usage'}));
200 push(@command,"GPRINT:iowaitpct:MAX:%3.2lf%%");
201 push(@command,"GPRINT:iowaitpct:AVERAGE:%3.2lf%%");
202 push(@command,"GPRINT:iowaitpct:MIN:%3.2lf%%");
203 push(@command,"GPRINT:iowaitpct:LAST:%3.2lf%%\\j");
204 push(@command,"STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu irq usage'}));
205 push(@command,"GPRINT:irqpct:MAX:%3.2lf%%");
206 push(@command,"GPRINT:irqpct:AVERAGE:%3.2lf%%");
207 push(@command,"GPRINT:irqpct:MIN:%3.2lf%%");
208 push(@command,"GPRINT:irqpct:LAST:%3.2lf%%\\j");
209 push(@command,"STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu nice usage'}));
210 push(@command,"GPRINT:nicepct:MAX:%3.2lf%%");
211 push(@command,"GPRINT:nicepct:AVERAGE:%3.2lf%%");
212 push(@command,"GPRINT:nicepct:MIN:%3.2lf%%");
213 push(@command,"GPRINT:nicepct:LAST:%3.2lf%%\\j");
214 push(@command,"STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu interrupt usage'}));
215 push(@command,"GPRINT:interruptpct:MAX:%3.2lf%%");
216 push(@command,"GPRINT:interruptpct:AVERAGE:%3.2lf%%");
217 push(@command,"GPRINT:interruptpct:MIN:%3.2lf%%");
218 push(@command,"GPRINT:interruptpct:LAST:%3.2lf%%\\j");
219 push(@command,"STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu steal usage'}));
220 push(@command,"GPRINT:stealpct:MAX:%3.2lf%%");
221 push(@command,"GPRINT:stealpct:AVERAGE:%3.2lf%%");
222 push(@command,"GPRINT:stealpct:MIN:%3.2lf%%");
223 push(@command,"GPRINT:stealpct:LAST:%3.2lf%%\\j");
224 push(@command,"STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu user usage'}));
225 push(@command,"GPRINT:userpct:MAX:%3.2lf%%");
226 push(@command,"GPRINT:userpct:AVERAGE:%3.2lf%%");
227 push(@command,"GPRINT:userpct:MIN:%3.2lf%%");
228 push(@command,"GPRINT:userpct:LAST:%3.2lf%%\\j");
229 push(@command,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu system usage'}));
230 push(@command,"GPRINT:systempct:MAX:%3.2lf%%");
231 push(@command,"GPRINT:systempct:AVERAGE:%3.2lf%%");
232 push(@command,"GPRINT:systempct:MIN:%3.2lf%%");
233 push(@command,"GPRINT:systempct:LAST:%3.2lf%%\\j");
234 push(@command,"STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu idle usage'}));
235 push(@command,"GPRINT:idlepct:MAX:%3.2lf%%");
236 push(@command,"GPRINT:idlepct:AVERAGE:%3.2lf%%");
237 push(@command,"GPRINT:idlepct:MIN:%3.2lf%%");
238 push(@command,"GPRINT:idlepct:LAST:%3.2lf%%\\j");
240 RRDs
::graph
(@command);
241 $ERROR = RRDs
::error
;
242 print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
245 # Generate the Load Graph for the current period of time for values given by collecd
247 sub updateloadgraph
{
262 "-t Load Average".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
263 "-v ".$Lang::tr
{'processes'},
264 "--color=SHADEA".$color{"color19"},
265 "--color=SHADEB".$color{"color19"},
266 "--color=BACK".$color{"color21"},
267 "DEF:load1=".$rrdlog."/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
268 "DEF:load5=".$rrdlog."/collectd/localhost/load/load.rrd:midterm:AVERAGE",
269 "DEF:load15=".$rrdlog."/collectd/localhost/load/load.rrd:longterm:AVERAGE",
270 "AREA:load1".$color{"color13"}."A0:1 Minute:",
271 "GPRINT:load1:LAST:%5.2lf",
272 "AREA:load5".$color{"color18"}."A0:5 Minuten:",
273 "GPRINT:load5:LAST:%5.2lf",
274 "AREA:load15".$color{"color14"}."A0:15 Minuten:",
275 "GPRINT:load15:LAST:%5.2lf\\j",
276 "LINE1:load5".$color{"color13"},
277 "LINE1:load1".$color{"color18"},
279 $ERROR = RRDs
::error
;
280 print "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
283 # Generate the Memory Graph for the current period of time for values given by collecd
285 sub updatememorygraph
{
301 "-t ".$Lang::tr
{'memory usage per'}." ".$Lang::tr
{$period},
302 "-v ".$Lang::tr
{'percentage'},
303 "--color=SHADEA".$color{"color19"},
304 "--color=SHADEB".$color{"color19"},
305 "--color=BACK".$color{"color21"},
306 "DEF:used=".$rrdlog."/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
307 "DEF:free=".$rrdlog."/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
308 "DEF:buffer=".$rrdlog."/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
309 "DEF:cache=".$rrdlog."/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
310 "CDEF:total=used,free,cache,buffer,+,+,+",
311 "CDEF:usedpct=used,total,/,100,*",
312 "CDEF:bufferpct=buffer,total,/,100,*",
313 "CDEF:cachepct=cache,total,/,100,*",
314 "CDEF:freepct=free,total,/,100,*",
315 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
316 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
317 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
318 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
319 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
320 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used memory'}),
321 "GPRINT:usedpct:MAX:%3.2lf%%",
322 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
323 "GPRINT:usedpct:MIN:%3.2lf%%",
324 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
325 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'buffered memory'}),
326 "GPRINT:bufferpct:MAX:%3.2lf%%",
327 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
328 "GPRINT:bufferpct:MIN:%3.2lf%%",
329 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
330 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr
{'cached memory'}),
331 "GPRINT:cachepct:MAX:%3.2lf%%",
332 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
333 "GPRINT:cachepct:MIN:%3.2lf%%",
334 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
335 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free memory'}),
336 "GPRINT:freepct:MAX:%3.2lf%%",
337 "GPRINT:freepct:AVERAGE:%3.2lf%%",
338 "GPRINT:freepct:MIN:%3.2lf%%",
339 "GPRINT:freepct:LAST:%3.2lf%%\\j",
341 $ERROR = RRDs
::error
;
342 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
345 # Generate the Swap Graph for the current period of time for values given by collecd
347 sub updateswapgraph
{
363 "-t ".$Lang::tr
{'swap usage per'}." ".$Lang::tr
{$period},
364 "-v ".$Lang::tr
{'percentage'},
365 "--color=SHADEA".$color{"color19"},
366 "--color=SHADEB".$color{"color19"},
367 "--color=BACK".$color{"color21"},
368 "DEF:used=".$rrdlog."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
369 "DEF:free=".$rrdlog."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
370 "DEF:cached=".$rrdlog."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
371 "CDEF:total=used,free,cached,+,+",
372 "CDEF:usedpct=100,used,total,/,*",
373 "CDEF:freepct=100,free,total,/,*",
374 "CDEF:cachedpct=100,cached,total,/,*",
375 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
376 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
377 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
378 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
379 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
380 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used swap'}),
381 "GPRINT:usedpct:MAX:%3.2lf%%",
382 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
383 "GPRINT:usedpct:MIN:%3.2lf%%",
384 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
385 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free swap'}),
386 "GPRINT:freepct:MAX:%3.2lf%%",
387 "GPRINT:freepct:AVERAGE:%3.2lf%%",
388 "GPRINT:freepct:MIN:%3.2lf%%",
389 "GPRINT:freepct:LAST:%3.2lf%%\\j",
390 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cached swap'}),
391 "GPRINT:cachedpct:MAX:%3.2lf%%",
392 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
393 "GPRINT:cachedpct:MIN:%3.2lf%%",
394 "GPRINT:cachedpct:LAST:%3.2lf%%\\j",
396 $ERROR = RRDs
::error
;
397 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
400 # Generate the Process Cpu Graph for the current period of time for values given by collecd
402 sub updateprocessescpugraph
{
419 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
420 "--color=SHADEA".$color{"color19"},
421 "--color=SHADEB".$color{"color19"},
422 "--color=BACK".$color{"color21"}
425 foreach(@processesgraph){
426 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
427 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
428 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
429 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");
432 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
434 foreach(@processesgraph){
435 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
437 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
439 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
444 RRDs
::graph
(@command);
445 $ERROR = RRDs
::error
;
446 print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
449 # Generate the Process Memory Graph for the current period of time for values given by collecd
451 sub updateprocessesmemorygraph
{
468 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'memory'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
469 "-v ".$Lang::tr
{'bytes'},
470 "--color=SHADEA".$color{"color19"},
471 "--color=SHADEB".$color{"color19"},
472 "--color=BACK".$color{"color21"}
475 foreach(@processesgraph){
476 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
477 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");
480 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
482 foreach(@processesgraph){
483 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
485 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
487 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
492 RRDs
::graph
(@command);
493 $ERROR = RRDs
::error
;
494 print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
497 # Generate the Disk Graph for the current period of time for values given by collecd
499 sub updatediskgraph
{
514 "-t ".$disk." ".$Lang::tr
{'disk access per'}." ".$Lang::tr
{$period},
515 "-v ".$Lang::tr
{'bytes per second'},
516 "--color=SHADEA".$color{"color19"},
517 "--color=SHADEB".$color{"color19"},
518 "--color=BACK".$color{"color21"},
519 "DEF:read=".$rrdlog."/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
520 "DEF:write=".$rrdlog."/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
521 "CDEF:writen=write,-1,*",
522 "DEF:standby=".$rrdlog."/hddshutdown-".$disk.".rrd:standby:AVERAGE",
523 "CDEF:st=standby,INF,*",
524 "CDEF:st1=standby,-INF,*",
525 "COMMENT:".sprintf("%-25s",$Lang::tr
{'caption'}),
526 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
527 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
528 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
529 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
530 "AREA:st".$color{"color20"}."A0:",
531 "AREA:st1".$color{"color20"}."A0:standby\\j",
532 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'read bytes'}),
533 "GPRINT:read:MAX:%8.1lf %sBps",
534 "GPRINT:read:AVERAGE:%8.1lf %sBps",
535 "GPRINT:read:MIN:%8.1lf %sBps",
536 "GPRINT:read:LAST:%8.1lf %sBps\\j",
537 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'written bytes'}),
538 "GPRINT:write:MAX:%8.1lf %sBps",
539 "GPRINT:write:AVERAGE:%8.1lf %sBps",
540 "GPRINT:write:MIN:%8.1lf %sBps",
541 "GPRINT:write:LAST:%8.1lf %sBps\\j",
543 $ERROR = RRDs
::error
;
544 print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
547 # Generate the Interface Graph for the current period of time for values given by collecd
550 my $interface = $_[0];
564 "-t ".$Lang::tr
{'traffic on'}." ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
565 "-v ".$Lang::tr
{'bytes per second'},
566 "--color=SHADEA".$color{"color19"},
567 "--color=SHADEB".$color{"color19"},
568 "--color=BACK".$color{"color21"},
569 "DEF:incoming=".$rrdlog."/collectd/localhost/interface/if_octets-".$interface.".rrd:rx:AVERAGE",
570 "DEF:outgoing=".$rrdlog."/collectd/localhost/interface/if_octets-".$interface.".rrd:tx:AVERAGE",
571 "CDEF:outgoingn=outgoing,-1,*",
572 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
573 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
574 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
575 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
576 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
577 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr
{'incoming traffic in bytes per second'}),
578 "GPRINT:incoming:MAX:%8.1lf %sBps",
579 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
580 "GPRINT:incoming:MIN:%8.1lf %sBps",
581 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
582 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr
{'outgoing traffic in bytes per second'}),
583 "GPRINT:outgoing:MAX:%8.1lf %sBps",
584 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
585 "GPRINT:outgoing:MIN:%8.1lf %sBps",
586 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
588 $ERROR = RRDs
::error
;
589 print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
592 # Generate the Firewall Graph for the current period of time for values given by collecd
594 sub updatefwhitsgraph
{
608 "-t ".$Lang::tr
{'firewall hits per'}." ".$Lang::tr
{$period},
609 "-v ".$Lang::tr
{'bytes per second'},
610 "--color=SHADEA".$color{"color19"},
611 "--color=SHADEB".$color{"color19"},
612 "--color=BACK".$color{"color21"},
613 "DEF:output=".$rrdlog."/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
614 "DEF:input=".$rrdlog."/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
615 "DEF:newnotsyn=".$rrdlog."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
616 "DEF:portscan=".$rrdlog."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
617 "CDEF:amount=output,input,newnotsyn,+,+",
618 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
619 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
620 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
621 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
622 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
623 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr
{'firewallhits'}),
624 "GPRINT:amount:MAX:%8.1lf %sBps",
625 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
626 "GPRINT:amount:MIN:%8.1lf %sBps",
627 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
628 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr
{'portscans'}),
629 "GPRINT:portscan:MAX:%8.1lf %sBps",
630 "GPRINT:portscan:MIN:%8.1lf %sBps",
631 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
632 "GPRINT:portscan:LAST:%8.1lf %sBps\\j",
634 $ERROR = RRDs
::error
;
635 print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
638 # Generate the Line Quality Graph for the current period of time for values given by collecd
640 sub updatepinggraph
{
656 "-t ".$Lang::tr
{'linkq'}." ".$host." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
658 "--color=SHADEA".$color{"color19"},
659 "--color=SHADEB".$color{"color19"},
660 "--color=BACK".$color{"color21"},
661 "DEF:roundtrip=".$rrdlog."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE",
662 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'})."\\j",
663 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
664 "CDEF:r0=roundtrip,30,MIN",
665 "CDEF:r1=roundtrip,70,MIN",
666 "CDEF:r2=roundtrip,150,MIN",
667 "CDEF:r3=roundtrip,300,MIN",
668 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
669 "AREA:r3".$color{"color18"}."A0:150-300 ms",
670 "AREA:r2".$color{"color14"}."A0:70-150 ms",
671 "AREA:r1".$color{"color17"}."A0:30-70 ms",
672 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
673 "COMMENT:$Lang::tr{'maximal'}",
674 "COMMENT:$Lang::tr{'average'}",
675 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
676 "LINE1:roundtrip#707070:",
677 "GPRINT:roundtrip:MAX:%3.2lf ms",
678 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
679 "GPRINT:roundtrip:MIN:%3.2lf ms",
680 "GPRINT:roundtrip:LAST:%3.2lf ms\\j",
682 $ERROR = RRDs
::error
;
683 print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
686 sub updatewirelessgraph
{
688 my $interface = $_[0];
700 "-t Wireless ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
702 "--color=SHADEA".$color{"color19"},
703 "--color=SHADEB".$color{"color19"},
704 "--color=BACK".$color{"color21"},
705 "DEF:noise=".$rrdlog."/collectd/localhost/wireless-".$interface."/signal_noise.rrd:value:AVERAGE",
706 "DEF:power=".$rrdlog."/collectd/localhost/wireless-".$interface."/signal_power.rrd:value:AVERAGE",
707 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
708 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
709 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
710 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
711 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
712 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
713 "GPRINT:noise:MAX:%5.1lf %sdBm",
714 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
715 "GPRINT:noise:MIN:%5.1lf %sdBm",
716 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
717 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
718 "GPRINT:power:MAX:%5.1lf %sdBm",
719 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
720 "GPRINT:power:MIN:%5.1lf %sdBm",
721 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
723 $ERROR = RRDs
::error
;
724 print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
727 # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
744 "-t ".$disk." ".$Lang::tr
{'harddisk temperature'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
746 "--color=SHADEA".$color{"color19"},
747 "--color=SHADEB".$color{"color19"},
748 "--color=BACK".$color{"color21"},
749 "DEF:temperature=".$rrdlog."/hddtemp-$disk.rrd:temperature:AVERAGE",
750 "DEF:standby=".$rrdlog."/hddshutdown-$disk.rrd:standby:AVERAGE",
751 "CDEF:st=standby,INF,*",
752 "AREA:st".$color{"color20"}."A0:standby",
753 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
754 "COMMENT:$Lang::tr{'maximal'}",
755 "COMMENT:$Lang::tr{'average'}",
756 "COMMENT:$Lang::tr{'minimal'}",
757 "COMMENT:$Lang::tr{'current'}\\j",
758 "GPRINT:temperature:MAX:%3.0lf Grad C",
759 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
760 "GPRINT:temperature:MIN:%3.0lf Grad C",
761 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
763 $ERROR = RRDs
::error
;
764 print "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
767 # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
769 sub updatehwtempgraph
{
784 "-t ".$Lang::tr
{'sensors temp'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
785 "--color=SHADEA".$color{"color19"},
786 "--color=SHADEB".$color{"color19"},
787 "--color=BACK".$color{"color21"},
788 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
789 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
790 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
791 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
792 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
795 foreach(@sensorsgraphs){
797 if ( $_ =~ /temperature/ ) {
798 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
799 my $label = $2.$3;$label=~ s/-//g;
800 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
801 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
805 foreach(@sensorsgraphs){
807 if ( $_ =~ /temperature/ ){
808 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
809 my $label = $2.$3;$label=~ s/-//g;
810 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
811 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",);
815 RRDs
::graph
(@command);
816 $ERROR = RRDs
::error
;
817 print "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
820 # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
822 sub updatehwfangraph
{
837 "-t ".$Lang::tr
{'mbmon fan'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
838 "--color=SHADEA".$color{"color19"},
839 "--color=SHADEB".$color{"color19"},
840 "--color=BACK".$color{"color21"},
841 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
842 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
843 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
844 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
845 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
848 foreach(@sensorsgraphs){
850 if ( $_ =~ /fanspeed/ ) {
851 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
852 my $label = $2.$3;$label=~ s/-//g;
853 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
854 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
858 foreach(@sensorsgraphs){
860 if ( $_ =~ /fanspeed/ ){
861 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
862 my $label = $2.$3;$label=~ s/-//g;
863 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
864 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",);
868 RRDs
::graph
(@command);
869 $ERROR = RRDs
::error
;
870 print "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
873 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
875 sub updatehwvoltgraph
{
890 "-t ".$Lang::tr
{'mbmon volt'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
891 "--color=SHADEA".$color{"color19"},
892 "--color=SHADEB".$color{"color19"},
893 "--color=BACK".$color{"color21"},
894 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
895 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
896 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
897 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
898 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
901 foreach(@sensorsgraphs){
903 if ( $_ =~ /voltage/ ) {
904 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
905 my $label = $2.$3;$label=~ s/-//g;
906 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
907 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
911 foreach(@sensorsgraphs){
913 if ( $_ =~ /voltage/ ){
914 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
915 my $label = $2.$3;$label=~ s/-//g;
916 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
917 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",);
921 RRDs
::graph
(@command);
922 $ERROR = RRDs
::error
;
923 print "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
941 # Generate the CPU Frequency Graph for the current period of time for values given by
942 # only 1 or 2 cpus is working
943 sub updatecpufreqgraph
{
944 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd" ){
947 my @command = ("$graphs/cpufreq-$period.png",
948 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v Mhz",
949 "-w 600", "-h 125", "-r",
950 "--color", "SHADEA".$color{"color19"},
951 "--color", "SHADEB".$color{"color19"},
952 "--color", "BACK".$color{"color21"},
953 "-t $Lang::tr{'cpu frequency per'} $Lang::tr{$period}");
955 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
956 push(@command,"DEF:cpu1_=$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd:value:AVERAGE");
958 push(@command,"DEF:cpu0_=$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd:value:AVERAGE");
960 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
961 push(@command,"CDEF:cpu1=cpu1_,1000000,/");
963 push(@command,"CDEF:cpu0=cpu0_,1000000,/",
965 "COMMENT:$Lang::tr{'maximal'}",
966 "COMMENT:$Lang::tr{'average'}",
967 "COMMENT:$Lang::tr{'minimal'}",
968 "COMMENT:$Lang::tr{'current'}\\j",);
971 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
972 push(@command,"LINE3:cpu1".$color{"color12"}."A0:1",
973 "GPRINT:cpu1:MAX:%3.0lf Mhz",
974 "GPRINT:cpu1:AVERAGE:%3.0lf Mhz",
975 "GPRINT:cpu1:MIN:%3.0lf Mhz",
976 "GPRINT:cpu1:LAST:%3.0lf Mhz\\j",);
978 push(@command,"LINE2:cpu0".$color{"color11"}."A1:0",
979 "GPRINT:cpu0:MAX:%3.0lf Mhz",
980 "GPRINT:cpu0:AVERAGE:%3.0lf Mhz",
981 "GPRINT:cpu0:MIN:%3.0lf Mhz",
982 "GPRINT:cpu0:LAST:%3.0lf Mhz\\j",);
984 RRDs
::graph
(@command);
985 $ERROR = RRDs
::error
;
986 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
990 # Generate the QoS Graph for the current period of time
997 my %qossettings = ();
998 &General
::readhash
("${General::swroot}/qos/settings", \
%qossettings);
1002 my $classfile = "/var/ipfire/qos/classes";
1004 $qossettings{'DEV'} = $_[1];
1005 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
1006 $qossettings{'CLASSPRFX'} = '1';
1008 $qossettings{'CLASSPRFX'} = '2';
1011 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
1012 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'})";}
1016 my $color="#000000";
1017 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
1018 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
1019 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
1020 "--color", "SHADEA".$color{"color19"},
1021 "--color", "SHADEB".$color{"color19"},
1022 "--color", "BACK".$color{"color21"},
1023 "COMMENT:".sprintf("%-28s",$Lang::tr
{'caption'}),
1024 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
1025 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
1026 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
1027 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
1030 open( FILE
, "< $classfile" ) or die "Unable to read $classfile";
1033 foreach $classentry (sort @classes)
1035 @classline = split( /\;/, $classentry );
1036 if ( $classline[0] eq $qossettings{'DEV'} )
1038 $color=random_hex_color
(6);
1039 push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
1041 if ($count eq "1") {
1042 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
1044 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
1047 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps");
1048 push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps");
1049 push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps");
1050 push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
1054 RRDs
::graph
(@command);
1055 $ERROR = RRDs
::error
;
1059 # Generate a random color, used by Qos Graph to be independent from the amount of values
1061 sub random_hex_color
{
1063 $size = 6 if $size !~ /^3|6$/;
1064 my @hex = ( 0 .. 9, 'a' .. 'f' );
1066 push @color, @hex[rand(@hex)] for 1 .. $size;
1067 return join('', '#', @color);