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