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