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 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
35 # Read the global settings files to get the current theme and after this load
36 # colors for this theme
39 my %mainsettings = ();
40 my %sensorsettings = ();
41 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
42 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
44 if ( $mainsettings{'RRDLOG'} eq "" ){
45 $mainsettings{'RRDLOG'}="/var/log/rrd";
46 &General
::writehash
("${General::swroot}/main/settings", \
%mainsettings);
49 # If the collection deamon is working and collecting lm_sensors data there will be
50 # some data source named after a common scheme, with the sensorssettingsfile
51 # the user is able to deactivate some of this parameters, in case not to show
52 # false collected values may be disable. The user has the ability to enter
53 # custom graph names in order to change temp0 to cpu or motherboard
59 my @sensorsgraphs = ();
60 my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ | wc -l`;
61 my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/`;
62 my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/`;
68 push(@sensorsgraphs,$_);
69 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
70 my $label = $2.$3;$label=~ s/-//g;
71 $sensorsettings{'LABEL-'.$label}="$label";
72 $sensorsettings{'LINE-'.$label}="checked";
76 &General
::readhash
("${General::swroot}/sensors/settings", \
%sensorsettings);
80 if ((${Lang
::language
} eq 'el') ||
81 (${Lang
::language
} eq 'fa') ||
82 (${Lang
::language
} eq 'ru') ||
83 (${Lang
::language
} eq 'th') ||
84 (${Lang
::language
} eq 'vi') ||
85 (${Lang
::language
} eq 'zh') ||
86 (${Lang
::language
} eq 'zt')) {
87 eval `/bin/cat "${General::swroot}/langs/en.pl"`;
88 } else {%tr=%Lang::tr
;}
90 # Generate a nice box for selection of time range in graphs
91 # this will generate a nice iframe for the cgi every klick for
92 # the graph will be handled inside the iframe
93 # 0 is the cgi refering to
95 # 2 is the time range for the graph
96 # 3 if given is the height of the iframe default if nothing is given
102 if ( $_[3] ne "" ){ $height = $_[3]; }
105 print "<a href='".$_[0]."?".$_[1]."?hour' target='".$_[1]."box'>Hour</a>";
107 print "<a href='".$_[0]."?".$_[1]."?day' target='".$_[1]."box'>Day</a>";
109 print "<a href='".$_[0]."?".$_[1]."?week' target='".$_[1]."box'>Week</a>";
111 print "<a href='".$_[0]."?".$_[1]."?month' target='".$_[1]."box'>Month</a>";
113 print "<a href='".$_[0]."?".$_[1]."?year' target='".$_[1]."box'>Year</a>";
114 print "<iframe src='".$_[0]."?".$_[1]."?".$_[2]."' width='".$width."' height='".$height."' scrolling='no' frameborder='no' marginheight='0' name='".$_[1]."box'></iframe>";
118 # Generate the CPU Graph for the current period of time for values given by
119 # collectd we are now able to handle any kind of cpucount
137 "-t ".$Lang::tr
{'cpu usage per'}." ".$Lang::tr
{$period},
138 "-v ".$Lang::tr
{'percentage'},
139 "--color=SHADEA".$color{"color19"},
140 "--color=SHADEB".$color{"color19"},
141 "--color=BACK".$color{"color21"},
142 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
143 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
144 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
145 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
146 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
149 my $nice = "CDEF:nice=";
150 my $interrupt = "CDEF:interrupt=";
151 my $steal = "CDEF:steal=";
152 my $user = "CDEF:user=";
153 my $system = "CDEF:system=";
154 my $idle = "CDEF:idle=";
155 my $iowait = "CDEF:iowait=";
156 my $irq = "CDEF:irq=";
159 for(my $i = 0; $i < $cpucount; $i++) {
160 push(@command,"DEF:iowait".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-wait.rrd:value:AVERAGE"
161 ,"DEF:nice".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-nice.rrd:value:AVERAGE"
162 ,"DEF:interrupt".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-interrupt.rrd:value:AVERAGE"
163 ,"DEF:steal".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-steal.rrd:value:AVERAGE"
164 ,"DEF:user".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-user.rrd:value:AVERAGE"
165 ,"DEF:system".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-system.rrd:value:AVERAGE"
166 ,"DEF:idle".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-idle.rrd:value:AVERAGE"
167 ,"DEF:irq".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-softirq.rrd:value:AVERAGE");
169 $nice .= "nice".$i.",";
170 $interrupt .= "interrupt".$i.",";
171 $steal .= "steal".$i.",";
172 $user .= "user".$i.",";
173 $system .= "system".$i.",";
174 $idle .= "idle".$i.",";
175 $iowait .= "iowait".$i.",";
176 $irq .= "irq".$i.",";
179 for(my $i = 2; $i < $cpucount; $i++) {
185 push(@command,$nice.$addstring
186 ,$interrupt.$addstring
194 push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+"
195 ,"CDEF:userpct=100,user,total,/,*"
196 ,"CDEF:nicepct=100,nice,total,/,*"
197 ,"CDEF:interruptpct=100,interrupt,total,/,*"
198 ,"CDEF:stealpct=100,steal,total,/,*"
199 ,"CDEF:systempct=100,system,total,/,*"
200 ,"CDEF:idlepct=100,idle,total,/,*"
201 ,"CDEF:iowaitpct=100,iowait,total,/,*"
202 ,"CDEF:irqpct=100,irq,total,/,*"
203 ,"AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr
{'cpu iowait usage'})
204 ,"GPRINT:iowaitpct:MAX:%3.2lf%%"
205 ,"GPRINT:iowaitpct:AVERAGE:%3.2lf%%"
206 ,"GPRINT:iowaitpct:MIN:%3.2lf%%"
207 ,"GPRINT:iowaitpct:LAST:%3.2lf%%\\j"
208 ,"STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu irq usage'})
209 ,"GPRINT:irqpct:MAX:%3.2lf%%"
210 ,"GPRINT:irqpct:AVERAGE:%3.2lf%%"
211 ,"GPRINT:irqpct:MIN:%3.2lf%%"
212 ,"GPRINT:irqpct:LAST:%3.2lf%%\\j"
213 ,"STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu nice usage'})
214 ,"GPRINT:nicepct:MAX:%3.2lf%%"
215 ,"GPRINT:nicepct:AVERAGE:%3.2lf%%"
216 ,"GPRINT:nicepct:MIN:%3.2lf%%"
217 ,"GPRINT:nicepct:LAST:%3.2lf%%\\j"
218 ,"STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu interrupt usage'})
219 ,"GPRINT:interruptpct:MAX:%3.2lf%%"
220 ,"GPRINT:interruptpct:AVERAGE:%3.2lf%%"
221 ,"GPRINT:interruptpct:MIN:%3.2lf%%"
222 ,"GPRINT:interruptpct:LAST:%3.2lf%%\\j"
223 ,"STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu steal usage'})
224 ,"GPRINT:stealpct:MAX:%3.2lf%%"
225 ,"GPRINT:stealpct:AVERAGE:%3.2lf%%"
226 ,"GPRINT:stealpct:MIN:%3.2lf%%"
227 ,"GPRINT:stealpct:LAST:%3.2lf%%\\j"
228 ,"STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu user usage'})
229 ,"GPRINT:userpct:MAX:%3.2lf%%"
230 ,"GPRINT:userpct:AVERAGE:%3.2lf%%"
231 ,"GPRINT:userpct:MIN:%3.2lf%%"
232 ,"GPRINT:userpct:LAST:%3.2lf%%\\j"
233 ,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu system usage'})
234 ,"GPRINT:systempct:MAX:%3.2lf%%"
235 ,"GPRINT:systempct:AVERAGE:%3.2lf%%"
236 ,"GPRINT:systempct:MIN:%3.2lf%%"
237 ,"GPRINT:systempct:LAST:%3.2lf%%\\j"
238 ,"STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu idle usage'})
239 ,"GPRINT:idlepct:MAX:%3.2lf%%"
240 ,"GPRINT:idlepct:AVERAGE:%3.2lf%%"
241 ,"GPRINT:idlepct:MIN:%3.2lf%%"
242 ,"GPRINT:idlepct:LAST:%3.2lf%%\\j");
244 RRDs
::graph
(@command);
245 $ERROR = RRDs
::error
;
246 print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
249 # Generate the Load Graph for the current period of time for values given by collecd
251 sub updateloadgraph
{
266 "-t Load Average".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
267 "-v ".$Lang::tr
{'processes'},
268 "--color=SHADEA".$color{"color19"},
269 "--color=SHADEB".$color{"color19"},
270 "--color=BACK".$color{"color21"},
271 "DEF:load1=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
272 "DEF:load5=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:midterm:AVERAGE",
273 "DEF:load15=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:longterm:AVERAGE",
274 "AREA:load1".$color{"color13"}."A0:1 Minute:",
275 "GPRINT:load1:LAST:%5.2lf",
276 "AREA:load5".$color{"color18"}."A0:5 Minuten:",
277 "GPRINT:load5:LAST:%5.2lf",
278 "AREA:load15".$color{"color14"}."A0:15 Minuten:",
279 "GPRINT:load15:LAST:%5.2lf\\j",
280 "LINE1:load5".$color{"color13"},
281 "LINE1:load1".$color{"color18"},
283 $ERROR = RRDs
::error
;
284 print "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
287 # Generate the Memory Graph for the current period of time for values given by collecd
289 sub updatememorygraph
{
305 "-t ".$Lang::tr
{'memory usage per'}." ".$Lang::tr
{$period},
306 "-v ".$Lang::tr
{'percentage'},
307 "--color=SHADEA".$color{"color19"},
308 "--color=SHADEB".$color{"color19"},
309 "--color=BACK".$color{"color21"},
310 "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
311 "DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
312 "DEF:buffer=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
313 "DEF:cache=".$mainsettings{'RRDLOG'}."/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
314 "CDEF:total=used,free,cache,buffer,+,+,+",
315 "CDEF:usedpct=used,total,/,100,*",
316 "CDEF:bufferpct=buffer,total,/,100,*",
317 "CDEF:cachepct=cache,total,/,100,*",
318 "CDEF:freepct=free,total,/,100,*",
319 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
320 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
321 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
322 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
323 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
324 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used memory'}),
325 "GPRINT:usedpct:MAX:%3.2lf%%",
326 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
327 "GPRINT:usedpct:MIN:%3.2lf%%",
328 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
329 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'buffered memory'}),
330 "GPRINT:bufferpct:MAX:%3.2lf%%",
331 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
332 "GPRINT:bufferpct:MIN:%3.2lf%%",
333 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
334 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr
{'cached memory'}),
335 "GPRINT:cachepct:MAX:%3.2lf%%",
336 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
337 "GPRINT:cachepct:MIN:%3.2lf%%",
338 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
339 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free memory'}),
340 "GPRINT:freepct:MAX:%3.2lf%%",
341 "GPRINT:freepct:AVERAGE:%3.2lf%%",
342 "GPRINT:freepct:MIN:%3.2lf%%",
343 "GPRINT:freepct:LAST:%3.2lf%%\\j",
345 $ERROR = RRDs
::error
;
346 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
349 # Generate the Swap Graph for the current period of time for values given by collecd
351 sub updateswapgraph
{
367 "-t ".$Lang::tr
{'swap usage per'}." ".$Lang::tr
{$period},
368 "-v ".$Lang::tr
{'percentage'},
369 "--color=SHADEA".$color{"color19"},
370 "--color=SHADEB".$color{"color19"},
371 "--color=BACK".$color{"color21"},
372 "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
373 "DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
374 "DEF:cached=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
375 "CDEF:total=used,free,cached,+,+",
376 "CDEF:usedpct=100,used,total,/,*",
377 "CDEF:freepct=100,free,total,/,*",
378 "CDEF:cachedpct=100,cached,total,/,*",
379 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
380 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
381 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
382 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
383 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
384 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used swap'}),
385 "GPRINT:usedpct:MAX:%3.2lf%%",
386 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
387 "GPRINT:usedpct:MIN:%3.2lf%%",
388 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
389 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free swap'}),
390 "GPRINT:freepct:MAX:%3.2lf%%",
391 "GPRINT:freepct:AVERAGE:%3.2lf%%",
392 "GPRINT:freepct:MIN:%3.2lf%%",
393 "GPRINT:freepct:LAST:%3.2lf%%\\j",
394 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cached swap'}),
395 "GPRINT:cachedpct:MAX:%3.2lf%%",
396 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
397 "GPRINT:cachedpct:MIN:%3.2lf%%",
398 "GPRINT:cachedpct:LAST:%3.2lf%%\\j",
400 $ERROR = RRDs
::error
;
401 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
404 # Generate the Process Cpu Graph for the current period of time for values given by collecd
406 sub updateprocessescpugraph
{
423 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
424 "--color=SHADEA".$color{"color19"},
425 "--color=SHADEB".$color{"color19"},
426 "--color=BACK".$color{"color21"}
429 foreach(@processesgraph){
430 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
431 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
432 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
433 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");
436 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
438 foreach(@processesgraph){
439 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
441 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
443 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
448 RRDs
::graph
(@command);
449 $ERROR = RRDs
::error
;
450 print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
453 # Generate the Process Memory Graph for the current period of time for values given by collecd
455 sub updateprocessesmemorygraph
{
472 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'memory'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
473 "-v ".$Lang::tr
{'bytes'},
474 "--color=SHADEA".$color{"color19"},
475 "--color=SHADEB".$color{"color19"},
476 "--color=BACK".$color{"color21"}
479 foreach(@processesgraph){
480 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
481 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");
484 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
486 foreach(@processesgraph){
487 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
489 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
491 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
496 RRDs
::graph
(@command);
497 $ERROR = RRDs
::error
;
498 print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
501 # Generate the Disk Graph for the current period of time for values given by collecd
503 sub updatediskgraph
{
518 "-t ".$disk." ".$Lang::tr
{'disk access per'}." ".$Lang::tr
{$period},
519 "-v ".$Lang::tr
{'bytes per second'},
520 "--color=SHADEA".$color{"color19"},
521 "--color=SHADEB".$color{"color19"},
522 "--color=BACK".$color{"color21"},
523 "DEF:read=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
524 "DEF:write=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
525 "CDEF:writen=write,-1,*",
526 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-".$disk.".rrd:standby:AVERAGE",
527 "CDEF:st=standby,INF,*",
528 "CDEF:st1=standby,-INF,*",
529 "COMMENT:".sprintf("%-25s",$Lang::tr
{'caption'}),
530 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
531 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
532 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
533 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
534 "AREA:st".$color{"color20"}."A0:",
535 "AREA:st1".$color{"color20"}."A0:standby\\j",
536 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'read bytes'}),
537 "GPRINT:read:MAX:%8.1lf %sBps",
538 "GPRINT:read:AVERAGE:%8.1lf %sBps",
539 "GPRINT:read:MIN:%8.1lf %sBps",
540 "GPRINT:read:LAST:%8.1lf %sBps\\j",
541 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'written bytes'}),
542 "GPRINT:write:MAX:%8.1lf %sBps",
543 "GPRINT:write:AVERAGE:%8.1lf %sBps",
544 "GPRINT:write:MIN:%8.1lf %sBps",
545 "GPRINT:write:LAST:%8.1lf %sBps\\j",
547 $ERROR = RRDs
::error
;
548 print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
551 # Generate the Interface Graph for the current period of time for values given by collecd
554 my $interface = $_[0];
568 "-t ".$Lang::tr
{'traffic on'}." ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
569 "-v ".$Lang::tr
{'bytes per second'},
570 "--color=SHADEA".$color{"color19"},
571 "--color=SHADEB".$color{"color19"},
572 "--color=BACK".$color{"color21"},
573 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:rx:AVERAGE",
574 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:tx:AVERAGE",
575 "CDEF:outgoingn=outgoing,-1,*",
576 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
577 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
578 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
579 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
580 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
581 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr
{'incoming traffic in bytes per second'}),
582 "GPRINT:incoming:MAX:%8.1lf %sBps",
583 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
584 "GPRINT:incoming:MIN:%8.1lf %sBps",
585 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
586 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr
{'outgoing traffic in bytes per second'}),
587 "GPRINT:outgoing:MAX:%8.1lf %sBps",
588 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
589 "GPRINT:outgoing:MIN:%8.1lf %sBps",
590 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
592 $ERROR = RRDs
::error
;
593 print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
596 # Generate the Firewall Graph for the current period of time for values given by collecd
598 sub updatefwhitsgraph
{
612 "-t ".$Lang::tr
{'firewall hits per'}." ".$Lang::tr
{$period},
613 "-v ".$Lang::tr
{'bytes per second'},
614 "--color=SHADEA".$color{"color19"},
615 "--color=SHADEB".$color{"color19"},
616 "--color=BACK".$color{"color21"},
617 "DEF:output=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
618 "DEF:input=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
619 "DEF:newnotsyn=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
620 "DEF:portscan=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
621 "CDEF:amount=output,input,newnotsyn,+,+",
622 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
623 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
624 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
625 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
626 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
627 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr
{'firewallhits'}),
628 "GPRINT:amount:MAX:%8.1lf %sBps",
629 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
630 "GPRINT:amount:MIN:%8.1lf %sBps",
631 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
632 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr
{'portscans'}),
633 "GPRINT:portscan:MAX:%8.1lf %sBps",
634 "GPRINT:portscan:MIN:%8.1lf %sBps",
635 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
636 "GPRINT:portscan:LAST:%8.1lf %sBps\\j",
638 $ERROR = RRDs
::error
;
639 print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
642 # Generate the Line Quality Graph for the current period of time for values given by collecd
644 sub updatepinggraph
{
660 "-t ".$Lang::tr
{'linkq'}." ".$host." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
662 "--color=SHADEA".$color{"color19"},
663 "--color=SHADEB".$color{"color19"},
664 "--color=BACK".$color{"color21"},
665 "DEF:roundtrip=".$mainsettings{'RRDLOG'}."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE",
666 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'})."\\j",
667 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
668 "CDEF:r0=roundtrip,30,MIN",
669 "CDEF:r1=roundtrip,70,MIN",
670 "CDEF:r2=roundtrip,150,MIN",
671 "CDEF:r3=roundtrip,300,MIN",
672 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
673 "AREA:r3".$color{"color18"}."A0:150-300 ms",
674 "AREA:r2".$color{"color14"}."A0:70-150 ms",
675 "AREA:r1".$color{"color17"}."A0:30-70 ms",
676 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
677 "COMMENT:$Lang::tr{'maximal'}",
678 "COMMENT:$Lang::tr{'average'}",
679 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
680 "LINE1:roundtrip#707070:",
681 "GPRINT:roundtrip:MAX:%3.2lf ms",
682 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
683 "GPRINT:roundtrip:MIN:%3.2lf ms",
684 "GPRINT:roundtrip:LAST:%3.2lf ms\\j",
686 $ERROR = RRDs
::error
;
687 print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
690 sub updatewirelessgraph
{
692 my $interface = $_[0];
704 "-t Wireless ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
706 "--color=SHADEA".$color{"color19"},
707 "--color=SHADEB".$color{"color19"},
708 "--color=BACK".$color{"color21"},
709 "DEF:noise=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_noise.rrd:value:AVERAGE",
710 "DEF:power=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_power.rrd:value:AVERAGE",
711 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
712 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
713 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
714 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
715 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
716 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
717 "GPRINT:noise:MAX:%5.1lf %sdBm",
718 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
719 "GPRINT:noise:MIN:%5.1lf %sdBm",
720 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
721 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
722 "GPRINT:power:MAX:%5.1lf %sdBm",
723 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
724 "GPRINT:power:MIN:%5.1lf %sdBm",
725 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
727 $ERROR = RRDs
::error
;
728 print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
731 # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
748 "-t ".$disk." ".$Lang::tr
{'harddisk temperature'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
750 "--color=SHADEA".$color{"color19"},
751 "--color=SHADEB".$color{"color19"},
752 "--color=BACK".$color{"color21"},
753 "DEF:temperature=".$mainsettings{'RRDLOG'}."/hddtemp-$disk.rrd:temperature:AVERAGE",
754 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-$disk.rrd:standby:AVERAGE",
755 "CDEF:st=standby,INF,*",
756 "AREA:st".$color{"color20"}."A0:standby",
757 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
758 "COMMENT:$Lang::tr{'maximal'}",
759 "COMMENT:$Lang::tr{'average'}",
760 "COMMENT:$Lang::tr{'minimal'}",
761 "COMMENT:$Lang::tr{'current'}\\j",
762 "GPRINT:temperature:MAX:%3.0lf Grad C",
763 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
764 "GPRINT:temperature:MIN:%3.0lf Grad C",
765 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
767 $ERROR = RRDs
::error
;
768 print "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
771 # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
773 sub updatehwtempgraph
{
788 "-t ".$Lang::tr
{'sensors temp'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
789 "--color=SHADEA".$color{"color19"},
790 "--color=SHADEB".$color{"color19"},
791 "--color=BACK".$color{"color21"},
792 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
793 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
794 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
795 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
796 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
799 foreach(@sensorsgraphs){
801 if ( $_ =~ /temperature/ ) {
802 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
803 my $label = $2.$3;$label=~ s/-//g;
804 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
805 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
809 foreach(@sensorsgraphs){
811 if ( $_ =~ /temperature/ ){
812 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
813 my $label = $2.$3;$label=~ s/-//g;
814 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
815 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",);
819 RRDs
::graph
(@command);
820 $ERROR = RRDs
::error
;
821 print "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
824 # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
826 sub updatehwfangraph
{
841 "-t ".$Lang::tr
{'mbmon fan'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
842 "--color=SHADEA".$color{"color19"},
843 "--color=SHADEB".$color{"color19"},
844 "--color=BACK".$color{"color21"},
845 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
846 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
847 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
848 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
849 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
852 foreach(@sensorsgraphs){
854 if ( $_ =~ /fanspeed/ ) {
855 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
856 my $label = $2.$3;$label=~ s/-//g;
857 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
858 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
862 foreach(@sensorsgraphs){
864 if ( $_ =~ /fanspeed/ ){
865 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
866 my $label = $2.$3;$label=~ s/-//g;
867 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
868 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",);
872 RRDs
::graph
(@command);
873 $ERROR = RRDs
::error
;
874 print "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
877 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
879 sub updatehwvoltgraph
{
894 "-t ".$Lang::tr
{'mbmon volt'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
895 "--color=SHADEA".$color{"color19"},
896 "--color=SHADEB".$color{"color19"},
897 "--color=BACK".$color{"color21"},
898 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
899 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
900 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
901 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
902 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
905 foreach(@sensorsgraphs){
907 if ( $_ =~ /voltage/ ) {
908 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
909 my $label = $2.$3;$label=~ s/-//g;
910 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
911 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
915 foreach(@sensorsgraphs){
917 if ( $_ =~ /voltage/ ){
918 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
919 my $label = $2.$3;$label=~ s/-//g;
920 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
921 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",);
925 RRDs
::graph
(@command);
926 $ERROR = RRDs
::error
;
927 print "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
931 # Generate the QoS Graph for the current period of time
936 my %qossettings = ();
937 &General
::readhash
("${General::swroot}/qos/settings", \
%qossettings);
942 my $classfile = "/var/ipfire/qos/classes";
944 $qossettings{'DEV'} = $_[0];
945 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
946 $qossettings{'CLASSPRFX'} = '1';
948 $qossettings{'CLASSPRFX'} = '2';
967 "-t ".$Lang::tr
{'Utilization on'}." (".$qossettings{'DEV'}.") ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
968 "-v ".$Lang::tr
{'bytes per second'},
969 "--color=SHADEA".$color{"color19"},
970 "--color=SHADEB".$color{"color19"},
971 "--color=BACK".$color{"color21"},
972 "COMMENT:".sprintf("%-28s",$Lang::tr
{'caption'}),
973 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
974 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
975 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
976 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
979 open( FILE
, "< $classfile" ) or die "Unable to read $classfile";
983 foreach $classentry (sort @classes){
984 @classline = split( /\;/, $classentry );
985 if ( $classline[0] eq $qossettings{'DEV'} ){
986 $color=random_hex_color
(6);
987 push(@command, "DEF:$classline[1]=$mainsettings{'RRDLOG'}/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
990 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
992 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
996 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps"
997 , "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps"
998 , "GPRINT:$classline[1]:MIN:%8.1lf %sBps"
999 , "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
1003 RRDs
::graph
(@command);
1004 $ERROR = RRDs
::error
;
1005 print "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR;
1008 # Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
1010 sub updatecpufreqgraph
{
1019 "-W www.ipfire.org",
1026 "-t ".$Lang::tr
{'cpu frequency per'}." ".$Lang::tr
{$period},
1028 "--color=SHADEA".$color{"color19"},
1029 "--color=SHADEB".$color{"color19"},
1030 "--color=BACK".$color{"color21"},
1031 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
1032 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
1033 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
1034 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
1035 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j"
1038 for(my $i = 0; $i < $cpucount; $i++) {
1039 push(@command,"DEF:cpu".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpufreq/cpufreq-".$i.".rrd:value:AVERAGE"
1040 ,"CDEF:cpu".$i."=cpu".$i."_,1000000,/"
1041 ,"LINE3:cpu".$i.$color{"color12"}."A0:1"
1042 ,"GPRINT:cpu".$i.":MAX:%3.0lf Mhz"
1043 ,"GPRINT:cpu".$i.":AVERAGE:%3.0lf Mhz"
1044 ,"GPRINT:cpu".$i.":MIN:%3.0lf Mhz"
1045 ,"GPRINT:cpu".$i.":LAST:%3.0lf Mhz\\j");
1048 RRDs
::graph
(@command);
1049 $ERROR = RRDs
::error
;
1050 print "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
1053 # Generate a random color, used by Qos Graph to be independent from the amount of values
1055 sub random_hex_color
{
1057 $size = 6 if $size !~ /^3|6$/;
1058 my @hex = ( 0 .. 9, 'a' .. 'f' );
1060 push @color, @hex[rand(@hex)] for 1 .. $size;
1061 return join('', '#', @color);