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 value´s may be disable. The user has the ability to ente
50 # custom graph names in order to change temp0 to cpu or motherboad
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 requesting every klick for
89 # the graph will be handled inside the iframe
90 # 0 is the cgi revering 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"}
141 my $nice = "CDEF:nice=";
142 my $interrupt = "CDEF:interrupt=";
143 my $steal = "CDEF:steal=";
144 my $user = "CDEF:user=";
145 my $system = "CDEF:system=";
146 my $idle = "CDEF:idle=";
147 my $iowait = "CDEF:iowait=";
148 my $irq = "CDEF:irq=";
151 for(my $i = 0; $i < $cpucount; $i++) {
152 push(@command,"DEF:iowait".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-wait.rrd:value:AVERAGE");
153 push(@command,"DEF:nice".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-nice.rrd:value:AVERAGE");
154 push(@command,"DEF:interrupt".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-interrupt.rrd:value:AVERAGE");
155 push(@command,"DEF:steal".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-steal.rrd:value:AVERAGE");
156 push(@command,"DEF:user".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-user.rrd:value:AVERAGE");
157 push(@command,"DEF:system".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-system.rrd:value:AVERAGE");
158 push(@command,"DEF:idle".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-idle.rrd:value:AVERAGE");
159 push(@command,"DEF:irq".$i."=".$rrdlog."/collectd/localhost/cpu-".$i."/cpu-softirq.rrd:value:AVERAGE");
160 $nice .= "nice".$i.",";
161 $interrupt .= "interrupt".$i.",";
162 $steal .= "steal".$i.",";
163 $user .= "user".$i.",";
164 $system .= "system".$i.",";
165 $idle .= "idle".$i.",";
166 $iowait .= "iowait".$i.",";
167 $irq .= "irq".$i.",";
170 for(my $i = 2; $i < $cpucount; $i++) {
176 push(@command,$nice.$addstring);
177 push(@command,$interrupt.$addstring);
178 push(@command,$steal.$addstring);
179 push(@command,$user.$addstring);
180 push(@command,$system.$addstring);
181 push(@command,$idle.$addstring);
182 push(@command,$iowait.$addstring);
183 push(@command,$irq.$addstring);
185 push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+");
186 push(@command,"CDEF:userpct=100,user,total,/,*");
187 push(@command,"CDEF:nicepct=100,nice,total,/,*");
188 push(@command,"CDEF:interruptpct=100,interrupt,total,/,*");
189 push(@command,"CDEF:stealpct=100,steal,total,/,*");
190 push(@command,"CDEF:systempct=100,system,total,/,*");
191 push(@command,"CDEF:idlepct=100,idle,total,/,*");
192 push(@command,"CDEF:iowaitpct=100,iowait,total,/,*");
193 push(@command,"CDEF:irqpct=100,irq,total,/,*");
194 push(@command,"AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr
{'cpu iowait usage'}));
195 push(@command,"GPRINT:iowaitpct:MAX:%3.2lf%%");
196 push(@command,"GPRINT:iowaitpct:AVERAGE:%3.2lf%%");
197 push(@command,"GPRINT:iowaitpct:MIN:%3.2lf%%");
198 push(@command,"GPRINT:iowaitpct:LAST:%3.2lf%%\\j");
199 push(@command,"STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu irq usage'}));
200 push(@command,"GPRINT:irqpct:MAX:%3.2lf%%");
201 push(@command,"GPRINT:irqpct:AVERAGE:%3.2lf%%");
202 push(@command,"GPRINT:irqpct:MIN:%3.2lf%%");
203 push(@command,"GPRINT:irqpct:LAST:%3.2lf%%\\j");
204 push(@command,"STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu nice usage'}));
205 push(@command,"GPRINT:nicepct:MAX:%3.2lf%%");
206 push(@command,"GPRINT:nicepct:AVERAGE:%3.2lf%%");
207 push(@command,"GPRINT:nicepct:MIN:%3.2lf%%");
208 push(@command,"GPRINT:nicepct:LAST:%3.2lf%%\\j");
209 push(@command,"STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu interrupt usage'}));
210 push(@command,"GPRINT:interruptpct:MAX:%3.2lf%%");
211 push(@command,"GPRINT:interruptpct:AVERAGE:%3.2lf%%");
212 push(@command,"GPRINT:interruptpct:MIN:%3.2lf%%");
213 push(@command,"GPRINT:interruptpct:LAST:%3.2lf%%\\j");
214 push(@command,"STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu steal usage'}));
215 push(@command,"GPRINT:stealpct:MAX:%3.2lf%%");
216 push(@command,"GPRINT:stealpct:AVERAGE:%3.2lf%%");
217 push(@command,"GPRINT:stealpct:MIN:%3.2lf%%");
218 push(@command,"GPRINT:stealpct:LAST:%3.2lf%%\\j");
219 push(@command,"STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu user usage'}));
220 push(@command,"GPRINT:userpct:MAX:%3.2lf%%");
221 push(@command,"GPRINT:userpct:AVERAGE:%3.2lf%%");
222 push(@command,"GPRINT:userpct:MIN:%3.2lf%%");
223 push(@command,"GPRINT:userpct:LAST:%3.2lf%%\\j");
224 push(@command,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu system usage'}));
225 push(@command,"GPRINT:systempct:MAX:%3.2lf%%");
226 push(@command,"GPRINT:systempct:AVERAGE:%3.2lf%%");
227 push(@command,"GPRINT:systempct:MIN:%3.2lf%%");
228 push(@command,"GPRINT:systempct:LAST:%3.2lf%%\\j");
229 push(@command,"STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'cpu idle usage'}));
230 push(@command,"GPRINT:idlepct:MAX:%3.2lf%%");
231 push(@command,"GPRINT:idlepct:AVERAGE:%3.2lf%%");
232 push(@command,"GPRINT:idlepct:MIN:%3.2lf%%");
233 push(@command,"GPRINT:idlepct:LAST:%3.2lf%%\\j");
235 RRDs
::graph
(@command);
236 $ERROR = RRDs
::error
;
237 print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
240 # Generate the Load Graph for the current period of time for values given by collecd
242 sub updateloadgraph
{
257 "-t Load Average".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
258 "-v ".$Lang::tr
{'processes'},
259 "--color=SHADEA".$color{"color19"},
260 "--color=SHADEB".$color{"color19"},
261 "--color=BACK".$color{"color21"},
262 "DEF:load1=".$rrdlog."/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
263 "DEF:load5=".$rrdlog."/collectd/localhost/load/load.rrd:midterm:AVERAGE",
264 "DEF:load15=".$rrdlog."/collectd/localhost/load/load.rrd:longterm:AVERAGE",
265 "AREA:load1".$color{"color13"}."A0:1 Minute:",
266 "GPRINT:load1:LAST:%5.2lf",
267 "AREA:load5".$color{"color18"}."A0:5 Minuten:",
268 "GPRINT:load5:LAST:%5.2lf",
269 "AREA:load15".$color{"color14"}."A0:15 Minuten:",
270 "GPRINT:load15:LAST:%5.2lf\\j",
271 "LINE1:load5".$color{"color13"},
272 "LINE1:load1".$color{"color18"},
274 $ERROR = RRDs
::error
;
275 print "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
278 # Generate the Memory Graph for the current period of time for values given by collecd
280 sub updatememorygraph
{
296 "-t ".$Lang::tr
{'memory usage per'}." ".$Lang::tr
{$period},
297 "-v ".$Lang::tr
{'percentage'},
298 "--color=SHADEA".$color{"color19"},
299 "--color=SHADEB".$color{"color19"},
300 "--color=BACK".$color{"color21"},
301 "DEF:used=".$rrdlog."/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
302 "DEF:free=".$rrdlog."/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
303 "DEF:buffer=".$rrdlog."/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
304 "DEF:cache=".$rrdlog."/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
305 "CDEF:total=used,free,cache,buffer,+,+,+",
306 "CDEF:usedpct=used,total,/,100,*",
307 "CDEF:bufferpct=buffer,total,/,100,*",
308 "CDEF:cachepct=cache,total,/,100,*",
309 "CDEF:freepct=free,total,/,100,*",
310 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
311 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
312 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
313 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
314 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
315 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used memory'}),
316 "GPRINT:usedpct:MAX:%3.2lf%%",
317 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
318 "GPRINT:usedpct:MIN:%3.2lf%%",
319 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
320 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr
{'buffered memory'}),
321 "GPRINT:bufferpct:MAX:%3.2lf%%",
322 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
323 "GPRINT:bufferpct:MIN:%3.2lf%%",
324 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
325 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr
{'cached memory'}),
326 "GPRINT:cachepct:MAX:%3.2lf%%",
327 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
328 "GPRINT:cachepct:MIN:%3.2lf%%",
329 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
330 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free memory'}),
331 "GPRINT:freepct:MAX:%3.2lf%%",
332 "GPRINT:freepct:AVERAGE:%3.2lf%%",
333 "GPRINT:freepct:MIN:%3.2lf%%",
334 "GPRINT:freepct:LAST:%3.2lf%%\\j",
336 $ERROR = RRDs
::error
;
337 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
340 # Generate the Swap Graph for the current period of time for values given by collecd
342 sub updateswapgraph
{
358 "-t ".$Lang::tr
{'swap usage per'}." ".$Lang::tr
{$period},
359 "-v ".$Lang::tr
{'percentage'},
360 "--color=SHADEA".$color{"color19"},
361 "--color=SHADEB".$color{"color19"},
362 "--color=BACK".$color{"color21"},
363 "DEF:used=".$rrdlog."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
364 "DEF:free=".$rrdlog."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
365 "DEF:cached=".$rrdlog."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
366 "CDEF:total=used,free,cached,+,+",
367 "CDEF:usedpct=100,used,total,/,*",
368 "CDEF:freepct=100,free,total,/,*",
369 "CDEF:cachedpct=100,cached,total,/,*",
370 "COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),
371 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
372 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
373 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
374 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
375 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr
{'used swap'}),
376 "GPRINT:usedpct:MAX:%3.2lf%%",
377 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
378 "GPRINT:usedpct:MIN:%3.2lf%%",
379 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
380 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'free swap'}),
381 "GPRINT:freepct:MAX:%3.2lf%%",
382 "GPRINT:freepct:AVERAGE:%3.2lf%%",
383 "GPRINT:freepct:MIN:%3.2lf%%",
384 "GPRINT:freepct:LAST:%3.2lf%%\\j",
385 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'cached swap'}),
386 "GPRINT:cachedpct:MAX:%3.2lf%%",
387 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
388 "GPRINT:cachedpct:MIN:%3.2lf%%",
389 "GPRINT:cachedpct:LAST:%3.2lf%%\\j",
391 $ERROR = RRDs
::error
;
392 print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
395 # Generate the Process Cpu Graph for the current period of time for values given by collecd
397 sub updateprocessescpugraph
{
414 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
415 "--color=SHADEA".$color{"color19"},
416 "--color=SHADEB".$color{"color19"},
417 "--color=BACK".$color{"color21"}
420 foreach(@processesgraph){
421 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
422 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
423 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
424 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");
427 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
429 foreach(@processesgraph){
430 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
432 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
434 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
439 RRDs
::graph
(@command);
440 $ERROR = RRDs
::error
;
441 print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
444 # Generate the Process Memory Graph for the current period of time for values given by collecd
446 sub updateprocessesmemorygraph
{
463 "-t ".$Lang::tr
{'processes'}." ".$Lang::tr
{'memory'}." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
464 "-v ".$Lang::tr
{'bytes'},
465 "--color=SHADEA".$color{"color19"},
466 "--color=SHADEB".$color{"color19"},
467 "--color=BACK".$color{"color21"}
470 foreach(@processesgraph){
471 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
472 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");
475 push(@command,"COMMENT:".$Lang::tr
{'caption'}."\\j");
477 foreach(@processesgraph){
478 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
480 push(@command,"AREA:".$name[1].random_hex_color
(6)."A0:".$name[1]);
482 push(@command,"STACK:".$name[1].random_hex_color
(6)."A0:".$name[1]);
487 RRDs
::graph
(@command);
488 $ERROR = RRDs
::error
;
489 print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
492 # Generate the Disk Graph for the current period of time for values given by collecd
494 sub updatediskgraph
{
509 "-t ".$disk." ".$Lang::tr
{'disk access per'}." ".$Lang::tr
{$period},
510 "-v ".$Lang::tr
{'bytes per second'},
511 "--color=SHADEA".$color{"color19"},
512 "--color=SHADEB".$color{"color19"},
513 "--color=BACK".$color{"color21"},
514 "DEF:read=".$rrdlog."/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
515 "DEF:write=".$rrdlog."/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
516 "CDEF:writen=write,-1,*",
517 "DEF:standby=".$rrdlog."/hddshutdown-".$disk.".rrd:standby:AVERAGE",
518 "CDEF:st=standby,INF,*",
519 "CDEF:st1=standby,-INF,*",
520 "COMMENT:".sprintf("%-25s",$Lang::tr
{'caption'}),
521 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
522 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
523 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
524 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
525 "AREA:st".$color{"color20"}."A0:",
526 "AREA:st1".$color{"color20"}."A0:standby\\j",
527 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr
{'read bytes'}),
528 "GPRINT:read:MAX:%8.1lf %sBps",
529 "GPRINT:read:AVERAGE:%8.1lf %sBps",
530 "GPRINT:read:MIN:%8.1lf %sBps",
531 "GPRINT:read:LAST:%8.1lf %sBps\\j",
532 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr
{'written bytes'}),
533 "GPRINT:write:MAX:%8.1lf %sBps",
534 "GPRINT:write:AVERAGE:%8.1lf %sBps",
535 "GPRINT:write:MIN:%8.1lf %sBps",
536 "GPRINT:write:LAST:%8.1lf %sBps\\j",
538 $ERROR = RRDs
::error
;
539 print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
542 # Generate the Interface Graph for the current period of time for values given by collecd
545 my $interface = $_[0];
559 "-t ".$Lang::tr
{'traffic on'}." ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
560 "-v ".$Lang::tr
{'bytes per second'},
561 "--color=SHADEA".$color{"color19"},
562 "--color=SHADEB".$color{"color19"},
563 "--color=BACK".$color{"color21"},
564 "DEF:incoming=".$rrdlog."/collectd/localhost/interface/if_octets-".$interface.".rrd:rx:AVERAGE",
565 "DEF:outgoing=".$rrdlog."/collectd/localhost/interface/if_octets-".$interface.".rrd:tx:AVERAGE",
566 "CDEF:outgoingn=outgoing,-1,*",
567 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
568 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
569 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
570 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
571 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
572 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr
{'incoming traffic in bytes per second'}),
573 "GPRINT:incoming:MAX:%8.1lf %sBps",
574 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
575 "GPRINT:incoming:MIN:%8.1lf %sBps",
576 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
577 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr
{'outgoing traffic in bytes per second'}),
578 "GPRINT:outgoing:MAX:%8.1lf %sBps",
579 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
580 "GPRINT:outgoing:MIN:%8.1lf %sBps",
581 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
583 $ERROR = RRDs
::error
;
584 print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
587 # Generate the Firewall Graph for the current period of time for values given by collecd
589 sub updatefwhitsgraph
{
603 "-t ".$Lang::tr
{'firewall hits per'}." ".$Lang::tr
{$period},
604 "-v ".$Lang::tr
{'bytes per second'},
605 "--color=SHADEA".$color{"color19"},
606 "--color=SHADEB".$color{"color19"},
607 "--color=BACK".$color{"color21"},
608 "DEF:output=".$rrdlog."/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
609 "DEF:input=".$rrdlog."/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
610 "DEF:newnotsyn=".$rrdlog."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
611 "DEF:portscan=".$rrdlog."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
612 "CDEF:amount=output,input,newnotsyn,+,+",
613 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
614 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
615 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
616 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
617 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
618 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr
{'firewallhits'}),
619 "GPRINT:amount:MAX:%8.1lf %sBps",
620 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
621 "GPRINT:amount:MIN:%8.1lf %sBps",
622 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
623 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr
{'portscans'}),
624 "GPRINT:portscan:MAX:%8.1lf %sBps",
625 "GPRINT:portscan:MIN:%8.1lf %sBps",
626 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
627 "GPRINT:portscan:LAST:%8.1lf %sBps\\j",
629 $ERROR = RRDs
::error
;
630 print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
633 # Generate the Line Quality Graph for the current period of time for values given by collecd
635 sub updatepinggraph
{
651 "-t ".$Lang::tr
{'linkq'}." ".$host." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
653 "--color=SHADEA".$color{"color19"},
654 "--color=SHADEB".$color{"color19"},
655 "--color=BACK".$color{"color21"},
656 "DEF:roundtrip=".$rrdlog."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE",
657 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'})."\\j",
658 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
659 "CDEF:r0=roundtrip,30,MIN",
660 "CDEF:r1=roundtrip,70,MIN",
661 "CDEF:r2=roundtrip,150,MIN",
662 "CDEF:r3=roundtrip,300,MIN",
663 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
664 "AREA:r3".$color{"color18"}."A0:150-300 ms",
665 "AREA:r2".$color{"color14"}."A0:70-150 ms",
666 "AREA:r1".$color{"color17"}."A0:30-70 ms",
667 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
668 "COMMENT:$Lang::tr{'maximal'}",
669 "COMMENT:$Lang::tr{'average'}",
670 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
671 "LINE1:roundtrip#707070:",
672 "GPRINT:roundtrip:MAX:%3.2lf ms",
673 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
674 "GPRINT:roundtrip:MIN:%3.2lf ms",
675 "GPRINT:roundtrip:LAST:%3.2lf ms\\j",
677 $ERROR = RRDs
::error
;
678 print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
681 sub updatewirelessgraph
{
683 my $interface = $_[0];
696 "-t Wireless ".$interface." ".$Lang::tr
{'graph per'}." ".$Lang::tr
{$period},
698 "--color=SHADEA".$color{"color19"},
699 "--color=SHADEB".$color{"color19"},
700 "--color=BACK".$color{"color21"},
701 "DEF:noise=".$rrdlog."/collectd/localhost/wireless-".$interface."/signal_noise.rrd:value:AVERAGE",
702 "DEF:power=".$rrdlog."/collectd/localhost/wireless-".$interface."/signal_power.rrd:value:AVERAGE",
703 "COMMENT:".sprintf("%-20s",$Lang::tr
{'caption'}),
704 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
705 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
706 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
707 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
708 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
709 "GPRINT:noise:MAX:%5.1lf %sdBm",
710 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
711 "GPRINT:noise:MIN:%5.1lf %sdBm",
712 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
713 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
714 "GPRINT:power:MAX:%5.1lf %sdBm",
715 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
716 "GPRINT:power:MIN:%5.1lf %sdBm",
717 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
719 $ERROR = RRDs
::error
;
720 print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
747 # Generate the CPU Frequency Graph for the current period of time for values given by
748 # only 1 or 2 cpus is working
749 sub updatecpufreqgraph
{
750 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd" ){
753 my @command = ("$graphs/cpufreq-$period.png",
754 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v Mhz",
755 "-w 600", "-h 125", "-r",
756 "--color", "SHADEA".$color{"color19"},
757 "--color", "SHADEB".$color{"color19"},
758 "--color", "BACK".$color{"color21"},
759 "-t $Lang::tr{'cpu frequency per'} $Lang::tr{$period}");
761 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
762 push(@command,"DEF:cpu1_=$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd:value:AVERAGE");
764 push(@command,"DEF:cpu0_=$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd:value:AVERAGE");
766 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
767 push(@command,"CDEF:cpu1=cpu1_,1000000,/");
769 push(@command,"CDEF:cpu0=cpu0_,1000000,/",
771 "COMMENT:$Lang::tr{'maximal'}",
772 "COMMENT:$Lang::tr{'average'}",
773 "COMMENT:$Lang::tr{'minimal'}",
774 "COMMENT:$Lang::tr{'current'}\\j",);
777 if ( -e
"$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){
778 push(@command,"LINE3:cpu1".$color{"color12"}."A0:1",
779 "GPRINT:cpu1:MAX:%3.0lf Mhz",
780 "GPRINT:cpu1:AVERAGE:%3.0lf Mhz",
781 "GPRINT:cpu1:MIN:%3.0lf Mhz",
782 "GPRINT:cpu1:LAST:%3.0lf Mhz\\j",);
784 push(@command,"LINE2:cpu0".$color{"color11"}."A1:0",
785 "GPRINT:cpu0:MAX:%3.0lf Mhz",
786 "GPRINT:cpu0:AVERAGE:%3.0lf Mhz",
787 "GPRINT:cpu0:MIN:%3.0lf Mhz",
788 "GPRINT:cpu0:LAST:%3.0lf Mhz\\j",);
790 RRDs
::graph
(@command);
791 $ERROR = RRDs
::error
;
792 print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
814 # Generate the QoS Graph for the current period of time
821 my %qossettings = ();
822 &General
::readhash
("${General::swroot}/qos/settings", \
%qossettings);
826 my $classfile = "/var/ipfire/qos/classes";
828 $qossettings{'DEV'} = $_[1];
829 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
830 $qossettings{'CLASSPRFX'} = '1';
832 $qossettings{'CLASSPRFX'} = '2';
835 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
836 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'})";}
841 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
842 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
843 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
844 "--color", "SHADEA".$color{"color19"},
845 "--color", "SHADEB".$color{"color19"},
846 "--color", "BACK".$color{"color21"},
847 "COMMENT:".sprintf("%-28s",$Lang::tr
{'caption'}),
848 "COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),
849 "COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),
850 "COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),
851 "COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j",
854 open( FILE
, "< $classfile" ) or die "Unable to read $classfile";
857 foreach $classentry (sort @classes)
859 @classline = split( /\;/, $classentry );
860 if ( $classline[0] eq $qossettings{'DEV'} )
862 $color=random_hex_color
(6);
863 push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
866 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
868 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
871 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps");
872 push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps");
873 push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps");
874 push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
878 RRDs
::graph
(@command);
879 $ERROR = RRDs
::error
;
883 # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
890 RRDs
::graph
("$graphs/hddtemp-$disk-$period.png",
891 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
892 "--alt-y-grid", "-w 600", "-h 125",
893 "--color", "SHADEA".$color{"color19"},
894 "--color", "SHADEB".$color{"color19"},
895 "--color", "BACK".$color{"color21"},
896 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
897 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
898 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
899 "CDEF:st=standby,INF,*",
900 "AREA:st".$color{"color20"}."A0:standby",
901 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
902 "COMMENT:$Lang::tr{'maximal'}",
903 "COMMENT:$Lang::tr{'average'}",
904 "COMMENT:$Lang::tr{'minimal'}",
905 "COMMENT:$Lang::tr{'current'}\\j",
906 "GPRINT:temperature:MAX:%3.0lf Grad C",
907 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
908 "GPRINT:temperature:MIN:%3.0lf Grad C",
909 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
911 $ERROR = RRDs
::error
;
912 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
915 # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
917 sub updatehwtempgraph
{
921 my @command = ("$graphs/sensors-hwtemp-$period.png",
922 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
923 "--alt-y-grid", "-w 600", "-h 125",
924 "--color", "SHADEA".$color{"color19"},"--color",
925 "SHADEB".$color{"color19"},"--color",
926 "BACK".$color{"color21"},
927 "-t $Lang::tr{'sensors temp'} $Lang::tr{'graph per'} $Lang::tr{$period}");
929 foreach(@sensorsgraphs){
931 if ( $_ =~ /temperature/ ) {
932 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
933 my $label = $2.$3;$label=~ s/-//g;
934 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
935 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
938 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j");
939 foreach(@sensorsgraphs){
941 if ( $_ =~ /temperature/ ){
942 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
943 my $label = $2.$3;$label=~ s/-//g;
944 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
945 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",);
948 RRDs
::graph
(@command);
949 $ERROR = RRDs
::error
;
953 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
955 sub updatehwvoltgraph
{
959 my @command = ("$graphs/sensors-hwvolt-$period.png",
960 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
961 "--alt-y-grid", "-w 600", "-h 125",
962 "--color", "SHADEA".$color{"color19"},"--color",
963 "SHADEB".$color{"color19"},"--color",
964 "BACK".$color{"color21"},
965 "-t $Lang::tr{'mbmon volt'} $Lang::tr{'graph per'} $Lang::tr{$period}");
967 foreach(@sensorsgraphs){
969 if ( $_ =~ /voltage/ ) {
970 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
971 my $label = $2.$3;$label=~ s/-//g;
972 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
973 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
976 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j");
977 foreach(@sensorsgraphs){
979 if ( $_ =~ /voltage/ ){
980 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
981 my $label = $2.$3;$label=~ s/-//g;
982 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
983 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",);
986 RRDs
::graph
(@command);
987 $ERROR = RRDs
::error
;
991 # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
993 sub updatehwfangraph
{
997 my @command = ("$graphs/sensors-hwfan-$period.png",
998 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
999 "--alt-y-grid", "-w 600", "-h 125",
1000 "--color", "SHADEA".$color{"color19"},"--color",
1001 "SHADEB".$color{"color19"},"--color",
1002 "BACK".$color{"color21"},
1003 "-t $Lang::tr{'mbmon fan'} $Lang::tr{'graph per'} $Lang::tr{$period}");
1005 foreach(@sensorsgraphs){
1007 if ( $_ =~ /fanspeed/ ) {
1008 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
1009 my $label = $2.$3;$label=~ s/-//g;
1010 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
1011 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
1014 push(@command,"COMMENT:".sprintf("%-29s",$Lang::tr
{'caption'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'maximal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'average'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'minimal'}),"COMMENT:".sprintf("%15s",$Lang::tr
{'current'})."\\j");
1015 foreach(@sensorsgraphs){
1017 if ( $_ =~ /fanspeed/ ){
1018 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
1019 my $label = $2.$3;$label=~ s/-//g;
1020 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
1021 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",);
1024 RRDs
::graph
(@command);
1025 $ERROR = RRDs
::error
;
1031 # Generate a random color, used by Qos Graph to be independent from the amount of values
1033 sub random_hex_color
{
1035 $size = 6 if $size !~ /^3|6$/;
1036 my @hex = ( 0 .. 9, 'a' .. 'f' );
1038 push @color, @hex[rand(@hex)] for 1 .. $size;
1039 return join('', '#', @color);