]> git.ipfire.org Git - ipfire-2.x.git/blame - config/cfgroot/graphs.pl
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into vpn-statistic1
[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>";
af433268 95 print "<br></center>";
e5533475 96 print "<iframe src='".$_[0]."?".$_[1]."?".$_[2]."' width='".$width."' height='".$height."' scrolling='no' frameborder='no' marginheight='0' name='".$_[1]."box'></iframe>";
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
e06986e8 425 my $colorIndex = 0;
4e481c3a 426 foreach(@processesgraph){
e06986e8
AH
427 my $colorIndex = 10 + $count % 15;
428 my $color="$color{\"color$colorIndex\"}";
4e481c3a
CS
429 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
430 if ($count eq "0"){
e06986e8 431 push(@command,"AREA:".$name[1].$color."A0:".$name[1]);
4e481c3a 432 }else{
e06986e8 433 push(@command,"STACK:".$name[1].$color."A0:".$name[1]);
4e481c3a
CS
434 }
435 $count++;
436 }
437
438 RRDs::graph (@command);
439 $ERROR = RRDs::error;
440 print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
3961e831
AF
441}
442
4e481c3a
CS
443# Generate the Process Memory Graph for the current period of time for values given by collecd
444
445sub updateprocessesmemorygraph {
1c163c04 446 my @processesgraph = getprocesses();
4e481c3a
CS
447 my $period = $_[0];
448 my $count="0";
449
450 my @command = (
451 "-",
452 "--start",
453 "-1".$period,
454 "-aPNG",
455 "-i",
456 "-z",
457 "-W www.ipfire.org",
458 "--alt-y-grid",
459 "-w 600",
460 "-h 125",
461 "-l 0",
462 "-r",
527a5a77 463 "-t ".$Lang::tr{'processes'}." ".$Lang::tr{'memory'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
464 "-v ".$Lang::tr{'bytes'},
465 "--color=SHADEA".$color{"color19"},
466 "--color=SHADEB".$color{"color19"},
467 "--color=BACK".$color{"color21"}
468 );
469
470 foreach(@processesgraph){
471 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
472 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");
473 }
474
475 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
476
e06986e8 477 my $colorIndex = 0;
4e481c3a
CS
478 foreach(@processesgraph){
479 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
e06986e8
AH
480 my $colorIndex = 10 + $count % 15;
481 my $color="$color{\"color$colorIndex\"}";
4e481c3a 482 if ($count eq "0"){
e06986e8 483 push(@command,"AREA:".$name[1].$color."A0:".$name[1]);
4e481c3a 484 }else{
e06986e8 485 push(@command,"STACK:".$name[1].$color."A0:".$name[1]);
4e481c3a
CS
486 }
487 $count++;
488 }
0950b1ec 489
4e481c3a
CS
490 RRDs::graph (@command);
491 $ERROR = RRDs::error;
492 print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
3961e831
AF
493}
494
495# Generate the Disk Graph for the current period of time for values given by collecd
496
497sub updatediskgraph {
4e481c3a
CS
498 my $disk = $_[0];
499 my $period = $_[1];
500 RRDs::graph(
501 "-",
502 "--start",
503 "-1".$period,
504 "-aPNG",
505 "-i",
506 "-z",
507 "-W www.ipfire.org",
508 "--alt-y-grid",
509 "-w 600",
510 "-h 125",
511 "-r",
527a5a77 512 "-t ".$disk." ".$Lang::tr{'disk access per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
513 "-v ".$Lang::tr{'bytes per second'},
514 "--color=SHADEA".$color{"color19"},
515 "--color=SHADEB".$color{"color19"},
516 "--color=BACK".$color{"color21"},
bcad0fd0
CS
517 "DEF:read=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
518 "DEF:write=".$mainsettings{'RRDLOG'}."/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
4e481c3a 519 "CDEF:writen=write,-1,*",
bcad0fd0 520 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-".$disk.".rrd:standby:AVERAGE",
4e481c3a
CS
521 "CDEF:st=standby,INF,*",
522 "CDEF:st1=standby,-INF,*",
523 "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}),
524 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
525 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
526 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
527 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
528 "AREA:st".$color{"color20"}."A0:",
529 "AREA:st1".$color{"color20"}."A0:standby\\j",
530 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
531 "GPRINT:read:MAX:%8.1lf %sBps",
532 "GPRINT:read:AVERAGE:%8.1lf %sBps",
533 "GPRINT:read:MIN:%8.1lf %sBps",
534 "GPRINT:read:LAST:%8.1lf %sBps\\j",
535 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
536 "GPRINT:write:MAX:%8.1lf %sBps",
537 "GPRINT:write:AVERAGE:%8.1lf %sBps",
538 "GPRINT:write:MIN:%8.1lf %sBps",
539 "GPRINT:write:LAST:%8.1lf %sBps\\j",
540 );
541 $ERROR = RRDs::error;
542 print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
3961e831
AF
543}
544
545# Generate the Interface Graph for the current period of time for values given by collecd
546
547sub updateifgraph {
4e481c3a
CS
548 my $interface = $_[0];
549 my $period = $_[1];
550 RRDs::graph(
551 "-",
552 "--start",
553 "-1".$period,
554 "-aPNG",
555 "-i",
556 "-z",
557 "-W www.ipfire.org",
558 "--alt-y-grid",
559 "-w 600",
560 "-h 125",
561 "-r",
527a5a77 562 "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
563 "-v ".$Lang::tr{'bytes per second'},
564 "--color=SHADEA".$color{"color19"},
565 "--color=SHADEB".$color{"color19"},
566 "--color=BACK".$color{"color21"},
bcad0fd0
CS
567 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:rx:AVERAGE",
568 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/interface/if_octets-".$interface.".rrd:tx:AVERAGE",
4e481c3a
CS
569 "CDEF:outgoingn=outgoing,-1,*",
570 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
571 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
572 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
573 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
574 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
575 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
576 "GPRINT:incoming:MAX:%8.1lf %sBps",
577 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
578 "GPRINT:incoming:MIN:%8.1lf %sBps",
579 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
5795fc1b
AM
580 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
581 "GPRINT:outgoing:MAX:%8.1lf %sBps",
582 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
583 "GPRINT:outgoing:MIN:%8.1lf %sBps",
584 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
585 );
586 $ERROR = RRDs::error;
587 print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
588}
589sub updatevpngraph {
590 my $interface = $_[0];
591 my $period = $_[1];
592 RRDs::graph(
593 "-",
594 "--start",
595 "-1".$period,
596 "-aPNG",
597 "-i",
598 "-z",
599 "-W www.ipfire.org",
600 "--alt-y-grid",
601 "-w 600",
602 "-h 125",
603 "-r",
604 "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
605 "-v ".$Lang::tr{'bytes per second'},
606 "--color=SHADEA".$color{"color19"},
607 "--color=SHADEB".$color{"color19"},
608 "--color=BACK".$color{"color21"},
609 "DEF:incoming=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets.rrd:rx:AVERAGE",
610 "DEF:outgoing=".$mainsettings{'RRDLOG'}."/collectd/localhost/openvpn-$interface/if_octets.rrd:tx:AVERAGE",
611 "CDEF:outgoingn=outgoing,-1,*",
612 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
613 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
614 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
615 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
616 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
617 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
618 "GPRINT:incoming:MAX:%8.1lf %sBps",
619 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
620 "GPRINT:incoming:MIN:%8.1lf %sBps",
621 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
4e481c3a
CS
622 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
623 "GPRINT:outgoing:MAX:%8.1lf %sBps",
624 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
625 "GPRINT:outgoing:MIN:%8.1lf %sBps",
626 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
627 );
628 $ERROR = RRDs::error;
629 print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
3961e831
AF
630}
631
632# Generate the Firewall Graph for the current period of time for values given by collecd
633
634sub updatefwhitsgraph {
4e481c3a
CS
635 my $period = $_[0];
636 RRDs::graph(
637 "-",
638 "--start",
639 "-1".$period,
640 "-aPNG",
641 "-i",
642 "-z",
643 "-W www.ipfire.org",
644 "--alt-y-grid",
645 "-w 600",
646 "-h 125",
647 "-r",
527a5a77 648 "-t ".$Lang::tr{'firewall hits per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
649 "-v ".$Lang::tr{'bytes per second'},
650 "--color=SHADEA".$color{"color19"},
651 "--color=SHADEB".$color{"color19"},
652 "--color=BACK".$color{"color21"},
94ea1f03
AM
653 "DEF:output=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYOUT/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
654 "DEF:input=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYIN/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
655 "DEF:forward=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYFWD/ipt_bytes-DROP_FORWARD.rrd:value:AVERAGE",
bcad0fd0
CS
656 "DEF:newnotsyn=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
657 "DEF:portscan=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
94ea1f03 658 "COMMENT:".sprintf("%-26s",$Lang::tr{'caption'}),
4e481c3a
CS
659 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
660 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
94ea1f03 661 "COMMENT:".sprintf("%14s",$Lang::tr{'minimal'}),
4e481c3a 662 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
94ea1f03
AM
663 "AREA:output".$color{"color25"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}."-OUTPUT"),
664 "GPRINT:output:MAX:%8.1lf %sBps",
665 "GPRINT:output:AVERAGE:%8.1lf %sBps",
666 "GPRINT:output:MIN:%8.1lf %sBps",
667 "GPRINT:output:LAST:%8.1lf %sBps\\j",
9468a6f7 668 "STACK:forward".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}."-FORWARD"),
94ea1f03
AM
669 "GPRINT:forward:MAX:%8.1lf %sBps",
670 "GPRINT:forward:AVERAGE:%8.1lf %sBps",
671 "GPRINT:forward:MIN:%8.1lf %sBps",
672 "GPRINT:forward:LAST:%8.1lf %sBps\\j",
9468a6f7
AM
673 "STACK:input".$color{"color24"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}."-INPUT"),
674 "GPRINT:input:MAX:%8.1lf %sBps",
675 "GPRINT:input:AVERAGE:%8.1lf %sBps",
676 "GPRINT:input:MIN:%8.1lf %sBps",
677 "GPRINT:input:LAST:%8.1lf %sBps\\j",
cb614898 678 "STACK:newnotsyn".$color{"color14"}."A0:".sprintf("%-25s","NewNotSyn"),
94ea1f03
AM
679 "GPRINT:newnotsyn:MAX:%8.1lf %sBps",
680 "GPRINT:newnotsyn:MIN:%8.1lf %sBps",
681 "GPRINT:newnotsyn:AVERAGE:%8.1lf %sBps",
682 "GPRINT:newnotsyn:LAST:%8.1lf %sBps\\j",
cb614898 683 "STACK:portscan".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'portscans'}),
4e481c3a
CS
684 "GPRINT:portscan:MAX:%8.1lf %sBps",
685 "GPRINT:portscan:MIN:%8.1lf %sBps",
686 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
687 "GPRINT:portscan:LAST:%8.1lf %sBps\\j",
688 );
689 $ERROR = RRDs::error;
690 print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
3961e831
AF
691}
692
693# Generate the Line Quality Graph for the current period of time for values given by collecd
694
cee25dda 695sub updatepinggraph {
4e481c3a
CS
696 my $period = $_[1];
697 my $host = $_[0];
698 RRDs::graph(
699 "-",
700 "--start",
701 "-1".$period,
702 "-aPNG",
703 "-i",
704 "-z",
705 "-W www.ipfire.org",
706 "--alt-y-grid",
707 "-w 600",
708 "-h 125",
709 "-l 0",
710 "-r",
527a5a77 711 "-t ".$Lang::tr{'linkq'}." ".$host." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
712 "-v ms",
713 "--color=SHADEA".$color{"color19"},
714 "--color=SHADEB".$color{"color19"},
715 "--color=BACK".$color{"color21"},
bcad0fd0 716 "DEF:roundtrip=".$mainsettings{'RRDLOG'}."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE",
4e481c3a
CS
717 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
718 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
719 "CDEF:r0=roundtrip,30,MIN",
720 "CDEF:r1=roundtrip,70,MIN",
721 "CDEF:r2=roundtrip,150,MIN",
722 "CDEF:r3=roundtrip,300,MIN",
723 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
724 "AREA:r3".$color{"color18"}."A0:150-300 ms",
725 "AREA:r2".$color{"color14"}."A0:70-150 ms",
726 "AREA:r1".$color{"color17"}."A0:30-70 ms",
727 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
728 "COMMENT:$Lang::tr{'maximal'}",
729 "COMMENT:$Lang::tr{'average'}",
730 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
731 "LINE1:roundtrip#707070:",
732 "GPRINT:roundtrip:MAX:%3.2lf ms",
733 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
734 "GPRINT:roundtrip:MIN:%3.2lf ms",
735 "GPRINT:roundtrip:LAST:%3.2lf ms\\j",
736 );
737 $ERROR = RRDs::error;
738 print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
3961e831
AF
739}
740
4e481c3a
CS
741sub updatewirelessgraph {
742 my $period = $_[1];
743 my $interface = $_[0];
744 RRDs::graph(
745 "-",
746 "--start",
747 "-1".$period,
748 "-aPNG",
749 "-i",
750 "-z",
751 "-W www.ipfire.org",
752 "--alt-y-grid",
753 "-w 600",
754 "-h 125",
527a5a77 755 "-t Wireless ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
4e481c3a
CS
756 "-v dBm",
757 "--color=SHADEA".$color{"color19"},
758 "--color=SHADEB".$color{"color19"},
759 "--color=BACK".$color{"color21"},
bcad0fd0
CS
760 "DEF:noise=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_noise.rrd:value:AVERAGE",
761 "DEF:power=".$mainsettings{'RRDLOG'}."/collectd/localhost/wireless-".$interface."/signal_power.rrd:value:AVERAGE",
4e481c3a
CS
762 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
763 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
764 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
765 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
766 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
767 "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"),
768 "GPRINT:noise:MAX:%5.1lf %sdBm",
769 "GPRINT:noise:AVERAGE:%5.1lf %sdBm",
770 "GPRINT:noise:MIN:%5.1lf %sdBm",
771 "GPRINT:noise:LAST:%5.1lf %sdBm\\j",
772 "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"),
773 "GPRINT:power:MAX:%5.1lf %sdBm",
774 "GPRINT:power:AVERAGE:%5.1lf %sdBm",
775 "GPRINT:power:MIN:%5.1lf %sdBm",
776 "GPRINT:power:LAST:%5.1lf %sdBm\\j",
777 );
778 $ERROR = RRDs::error;
779 print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
780}
781
2d281532 782# Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
4e481c3a 783
2d281532
CS
784sub updatehddgraph {
785 my $disk = $_[0];
786 my $period = $_[1];
787 RRDs::graph(
788 "-",
789 "--start",
790 "-1".$period,
791 "-aPNG",
792 "-i",
793 "-z",
794 "-W www.ipfire.org",
795 "--alt-y-grid",
796 "-w 600",
797 "-h 125",
798 "-r",
527a5a77 799 "-t ".$disk." ".$Lang::tr{'harddisk temperature'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
2d281532
CS
800 "-v Celsius",
801 "--color=SHADEA".$color{"color19"},
802 "--color=SHADEB".$color{"color19"},
803 "--color=BACK".$color{"color21"},
bcad0fd0
CS
804 "DEF:temperature=".$mainsettings{'RRDLOG'}."/hddtemp-$disk.rrd:temperature:AVERAGE",
805 "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-$disk.rrd:standby:AVERAGE",
2d281532
CS
806 "CDEF:st=standby,INF,*",
807 "AREA:st".$color{"color20"}."A0:standby",
808 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
809 "COMMENT:$Lang::tr{'maximal'}",
810 "COMMENT:$Lang::tr{'average'}",
811 "COMMENT:$Lang::tr{'minimal'}",
812 "COMMENT:$Lang::tr{'current'}\\j",
813 "GPRINT:temperature:MAX:%3.0lf Grad C",
814 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
815 "GPRINT:temperature:MIN:%3.0lf Grad C",
816 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
817 );
818 $ERROR = RRDs::error;
819 print "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
820}
4e481c3a 821
2d281532 822# Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
4e481c3a 823
2d281532
CS
824sub updatehwtempgraph {
825 my $period = $_[0];
4e481c3a 826
2d281532
CS
827 my @command = (
828 "-",
829 "--start",
830 "-1".$period,
831 "-aPNG",
832 "-i",
833 "-z",
834 "-W www.ipfire.org",
835 "--alt-y-grid",
836 "-w 600",
837 "-h 125",
838 "-r",
527a5a77 839 "-t ".$Lang::tr{'mbmon temp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
2d281532
CS
840 "--color=SHADEA".$color{"color19"},
841 "--color=SHADEB".$color{"color19"},
842 "--color=BACK".$color{"color21"},
843 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
844 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
845 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
846 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
847 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
848 );
4e481c3a 849
2d281532
CS
850 foreach(@sensorsgraphs){
851 chomp($_);
852 if ( $_ =~ /temperature/ ) {
853 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
854 my $label = $2.$3;$label=~ s/-//g;
855 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
856 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
857 }
858 }
4e481c3a 859
2d281532
CS
860 foreach(@sensorsgraphs){
861 chomp($_);
862 if ( $_ =~ /temperature/ ){
863 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
864 my $label = $2.$3;$label=~ s/-//g;
865 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
866 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",);
867 }
868 }
4e481c3a 869
2d281532
CS
870 RRDs::graph (@command);
871 $ERROR = RRDs::error;
872 print "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
873}
4e481c3a 874
2d281532
CS
875# Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
876
877sub updatehwfangraph {
878 my $period = $_[0];
879
880 my @command = (
881 "-",
882 "--start",
883 "-1".$period,
884 "-aPNG",
885 "-i",
886 "-z",
887 "-W www.ipfire.org",
888 "--alt-y-grid",
889 "-w 600",
890 "-h 125",
891 "-r",
527a5a77 892 "-t ".$Lang::tr{'mbmon fan'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
2d281532
CS
893 "--color=SHADEA".$color{"color19"},
894 "--color=SHADEB".$color{"color19"},
895 "--color=BACK".$color{"color21"},
896 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
897 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
898 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
899 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
900 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
901 );
902
903 foreach(@sensorsgraphs){
904 chomp($_);
905 if ( $_ =~ /fanspeed/ ) {
906 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
907 my $label = $2.$3;$label=~ s/-//g;
908 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
909 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
910 }
911 }
912
913 foreach(@sensorsgraphs){
914 chomp($_);
915 if ( $_ =~ /fanspeed/ ){
916 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
917 my $label = $2.$3;$label=~ s/-//g;
918 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
919 push(@command,"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",);
920 }
921 }
922
923 RRDs::graph (@command);
924 $ERROR = RRDs::error;
925 print "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
926}
927
928# Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
929
930sub updatehwvoltgraph {
931 my $period = $_[0];
932
933 my @command = (
934 "-",
935 "--start",
936 "-1".$period,
937 "-aPNG",
938 "-i",
939 "-z",
940 "-W www.ipfire.org",
941 "--alt-y-grid",
942 "-w 600",
943 "-h 125",
944 "-r",
527a5a77 945 "-t ".$Lang::tr{'mbmon volt'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
2d281532
CS
946 "--color=SHADEA".$color{"color19"},
947 "--color=SHADEB".$color{"color19"},
948 "--color=BACK".$color{"color21"},
949 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
950 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
951 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
952 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
953 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
954 );
955
956 foreach(@sensorsgraphs){
957 chomp($_);
958 if ( $_ =~ /voltage/ ) {
959 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
960 my $label = $2.$3;$label=~ s/-//g;
961 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
962 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
963 }
964 }
965
966 foreach(@sensorsgraphs){
967 chomp($_);
968 if ( $_ =~ /voltage/ ){
969 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
970 my $label = $2.$3;$label=~ s/-//g;
971 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
972 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",);
973 }
974 }
975
976 RRDs::graph (@command);
977 $ERROR = RRDs::error;
978 print "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
979}
4e481c3a
CS
980
981
3961e831
AF
982# Generate the QoS Graph for the current period of time
983
4e481c3a 984sub updateqosgraph {
3961e831 985
bcad0fd0
CS
986 my $period = $_[1];
987 my %qossettings = ();
988 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
989
990 my $classentry = "";
991 my @classes = ();
992 my @classline = ();
993 my $classfile = "/var/ipfire/qos/classes";
994
995 $qossettings{'DEV'} = $_[0];
3961e831
AF
996 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
997 $qossettings{'CLASSPRFX'} = '1';
998 } else {
999 $qossettings{'CLASSPRFX'} = '2';
1000 }
1001
3961e831
AF
1002 my $ERROR="";
1003 my $count="1";
1004 my $color="#000000";
bcad0fd0
CS
1005
1006 my @command = (
1007 "-",
1008 "--start",
1009 "-1".$period,
1010 "-aPNG",
1011 "-i",
1012 "-z",
1013 "-W www.ipfire.org",
1014 "--alt-y-grid",
1015 "-w 600",
1016 "-h 125",
1017 "-r",
527a5a77 1018 "-t ".$Lang::tr{'Utilization on'}." (".$qossettings{'DEV'}.") ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"},
bcad0fd0
CS
1019 "-v ".$Lang::tr{'bytes per second'},
1020 "--color=SHADEA".$color{"color19"},
1021 "--color=SHADEB".$color{"color19"},
1022 "--color=BACK".$color{"color21"},
3961e831
AF
1023 "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}),
1024 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1025 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1026 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
bcad0fd0 1027 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
3961e831 1028 );
3961e831 1029
bcad0fd0
CS
1030 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
1031 @classes = <FILE>;
1032 close FILE;
1033
e06986e8 1034 my $colorIndex = 0;
bcad0fd0
CS
1035 foreach $classentry (sort @classes){
1036 @classline = split( /\;/, $classentry );
1037 if ( $classline[0] eq $qossettings{'DEV'} ){
e06986e8
AH
1038 my $colorIndex = 10 + $count % 15;
1039 $color="$color{\"color$colorIndex\"}";
bcad0fd0
CS
1040 push(@command, "DEF:$classline[1]=$mainsettings{'RRDLOG'}/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
1041
1042 if ($count eq "1") {
491957ac 1043 push(@command, "AREA:$classline[1]$color:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8]));
bcad0fd0 1044 } else {
491957ac 1045 push(@command, "STACK:$classline[1]$color:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8]));
bcad0fd0
CS
1046 }
1047
1048 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps"
1049 , "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps"
1050 , "GPRINT:$classline[1]:MIN:%8.1lf %sBps"
1051 , "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
1052 $count++;
3961e831 1053 }
3961e831 1054 }
bcad0fd0
CS
1055 RRDs::graph (@command);
1056 $ERROR = RRDs::error;
1057 print "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR;
1058}
1059
1060# Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
1061
1062sub updatecpufreqgraph {
0d08de33 1063 my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`;
bcad0fd0
CS
1064 my $period = $_[0];
1065 my @command = (
1066 "-",
1067 "--start",
1068 "-1".$period,
1069 "-aPNG",
1070 "-i",
1071 "-z",
1072 "-W www.ipfire.org",
1073 "--alt-y-grid",
1074 "-w 600",
1075 "-h 125",
bcad0fd0 1076 "-r",
527a5a77 1077 "-t ".$Lang::tr{'cpu frequency per'}." ".$Lang::tr{$period."-graph"},
bcad0fd0
CS
1078 "-v MHz",
1079 "--color=SHADEA".$color{"color19"},
1080 "--color=SHADEB".$color{"color19"},
1081 "--color=BACK".$color{"color21"},
3e966054 1082 "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
bcad0fd0
CS
1083 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1084 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1085 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
1086 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
1087 );
1088
1089 for(my $i = 0; $i < $cpucount; $i++) {
5dcc7ad7 1090 my $j=$i+1;
bcad0fd0
CS
1091 push(@command,"DEF:cpu".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpufreq/cpufreq-".$i.".rrd:value:AVERAGE"
1092 ,"CDEF:cpu".$i."=cpu".$i."_,1000000,/"
5dcc7ad7 1093 ,"LINE1:cpu".$i.$color{"color1$j"}."A0:cpu ".$i." "
bcad0fd0
CS
1094 ,"GPRINT:cpu".$i.":MAX:%3.0lf Mhz"
1095 ,"GPRINT:cpu".$i.":AVERAGE:%3.0lf Mhz"
1096 ,"GPRINT:cpu".$i.":MIN:%3.0lf Mhz"
1097 ,"GPRINT:cpu".$i.":LAST:%3.0lf Mhz\\j");
3961e831 1098 }
bcad0fd0 1099
3961e831
AF
1100 RRDs::graph (@command);
1101 $ERROR = RRDs::error;
bcad0fd0 1102 print "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
3961e831
AF
1103}
1104
30189c50
AF
1105# Generate the Thermal Zone Temp CPU Graph
1106
1107sub updatethermaltempgraph {
0d08de33 1108 my $thermalcount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone* 2>/dev/null | wc -l`;
30189c50
AF
1109 my $period = $_[0];
1110 my @command = (
1111 "-",
1112 "--start",
1113 "-1".$period,
1114 "-aPNG",
1115 "-i",
1116 "-z",
1117 "-W www.ipfire.org",
1118 "--alt-y-grid",
1119 "-w 600",
1120 "-h 125",
30189c50 1121 "-r",
527a5a77 1122 "-t "."ACPI Thermal-Zone Temperature"." - ".$Lang::tr{$period."-graph"},
30189c50
AF
1123 "-v Grad Celsius",
1124 "--color=SHADEA".$color{"color19"},
1125 "--color=SHADEB".$color{"color19"},
1126 "--color=BACK".$color{"color21"},
3e966054 1127 "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
30189c50
AF
1128 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
1129 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
1130 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
1131 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
1132 );
1133
1134 for(my $i = 0; $i < $thermalcount; $i++) {
1135 my $j=$i+1;
1136 push(@command,"DEF:temp".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/thermal-thermal_zone".$i."/temperature-temperature.rrd:value:AVERAGE"
1137 ,"CDEF:temp".$i."=temp".$i."_,1,/"
3e966054 1138 ,"LINE3:temp".$i.$color{"color1$j"}."A0:Temp ".$i." "
30189c50
AF
1139 ,"GPRINT:temp".$i.":MAX:%3.0lf Grad C"
1140 ,"GPRINT:temp".$i.":AVERAGE:%3.0lf Grad C"
1141 ,"GPRINT:temp".$i.":MIN:%3.0lf Grad C"
1142 ,"GPRINT:temp".$i.":LAST:%3.0lf Grad C\\j");
1143 }
1144
1145 RRDs::graph (@command);
1146 $ERROR = RRDs::error;
1147 print "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR;
1148}
1149
30189c50 1150
3961e831
AF
1151# Generate a random color, used by Qos Graph to be independent from the amount of values
1152
1153sub random_hex_color {
4e481c3a
CS
1154 my $size = shift;
1155 $size = 6 if $size !~ /^3|6$/;
1156 my @hex = ( 0 .. 9, 'a' .. 'f' );
1157 my @color;
1158 push @color, @hex[rand(@hex)] for 1 .. $size;
1159 return join('', '#', @color);
3961e831 1160}
1c163c04
CS
1161
1162sub getprocesses {
0d08de33 1163 my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/ 2>/dev/null`;
1c163c04
CS
1164 return @processesgraph;
1165}
15b023b9
MT
1166
1167sub updateentropygraph {
1168 my $period = $_[0];
1169 my @command = (
1170 "-",
1171 "--start",
1172 "-1".$period,
1173 "-aPNG",
1174 "-i",
1175 "-z",
1176 "-W www.ipfire.org",
1177 "--alt-y-grid",
1178 "-w 600",
1179 "-h 225",
1180 "-r",
1181 "--lower-limit","0",
1182 "-t $Lang::tr{'entropy'}",
1183 "-v $Lang::tr{'bit'}",
1184 "DEF:entropy=$mainsettings{'RRDLOG'}/collectd/localhost/entropy/entropy.rrd:entropy:AVERAGE",
15b023b9
MT
1185 "LINE3:entropy#ff0000:" . sprintf("%-15s", $Lang::tr{'entropy'}),
1186 "VDEF:entrmin=entropy,MINIMUM",
1187 "VDEF:entrmax=entropy,MAXIMUM",
1188 "VDEF:entravg=entropy,AVERAGE",
1189 "GPRINT:entrmax:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'maximum'}),
1190 "GPRINT:entrmin:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'minimum'}),
1191 "GPRINT:entravg:" . sprintf("%12s\\: %%5.0lf", $Lang::tr{'average'}) . "\\n",
15b023b9
MT
1192 );
1193
1194 RRDs::graph (@command);
1195 $ERROR = RRDs::error;
1196
1197 print "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR;
1198}