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