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