]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | # Generate Graphs exported from Makegraphs to minimize system load an only generate the Graphs when displayed | |
3 | ############################################################################### | |
4 | # # | |
5 | # IPFire.org - A linux based firewall # | |
6 | # Copyright (C) 2005-2021 IPFire Team # | |
7 | # # | |
8 | # This program is free software: you can redistribute it and/or modify # | |
9 | # it under the terms of the GNU General Public License as published by # | |
10 | # the Free Software Foundation, either version 3 of the License, or # | |
11 | # (at your option) any later version. # | |
12 | # # | |
13 | # This program is distributed in the hope that it will be useful, # | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
16 | # GNU General Public License for more details. # | |
17 | # # | |
18 | # You should have received a copy of the GNU General Public License # | |
19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
20 | # # | |
21 | ############################################################################### | |
22 | ||
23 | package Graphs; | |
24 | ||
25 | use strict; | |
26 | use RRDs; | |
27 | use experimental 'smartmatch'; | |
28 | ||
29 | require '/var/ipfire/general-functions.pl'; | |
30 | require "${General::swroot}/lang.pl"; | |
31 | require "${General::swroot}/header.pl"; | |
32 | ||
33 | # Graph image size in pixel | |
34 | our %image_size = ('width' => 910, 'height' => 300); | |
35 | ||
36 | # List of all available time ranges | |
37 | our @time_ranges = ("hour", "day", "week", "month", "year"); | |
38 | ||
39 | my $ERROR; | |
40 | ||
41 | my @GRAPH_ARGS = ( | |
42 | # Output format | |
43 | "--imgformat", "SVG", | |
44 | ||
45 | # No border | |
46 | "--border", "0", | |
47 | ||
48 | # For a more 'organic' look | |
49 | "--slope-mode", | |
50 | ||
51 | # HxW define the size of the output image | |
52 | "--full-size-mode", | |
53 | ||
54 | # Watermark | |
55 | "-W www.ipfire.org", | |
56 | ||
57 | # Default size | |
58 | "-w $image_size{'width'}", | |
59 | "-h $image_size{'height'}", | |
60 | ||
61 | # Use alternative grid | |
62 | "--alt-y-grid", | |
63 | ); | |
64 | ||
65 | ||
66 | my %color = (); | |
67 | my %mainsettings = (); | |
68 | my %sensorsettings = (); | |
69 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
70 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); | |
71 | ||
72 | if ( $mainsettings{'RRDLOG'} eq "" ){ | |
73 | $mainsettings{'RRDLOG'}="/var/log/rrd"; | |
74 | &General::writehash("${General::swroot}/main/settings", \%mainsettings); | |
75 | } | |
76 | ||
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 | |
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 | |
82 | ||
83 | my $count = 0; | |
84 | my @sensorsgraphs = (); | |
85 | my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/ 2>/dev/null`; | |
86 | foreach (@sensorsdir){ | |
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); | |
99 | ||
100 | # Generate a nice box for selection of time range in graphs | |
101 | # this will generate a nice div box for the cgi every klick for | |
102 | # the graph will be handled by javascript | |
103 | # 0 is the cgi refering to | |
104 | # 1 is the graph name | |
105 | # 2 is the time range for the graph (optional) | |
106 | ||
107 | sub makegraphbox { | |
108 | my ($origin, $name, $default_range) = @_; | |
109 | ||
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> | |
116 | END | |
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> | |
122 | END | |
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> | |
129 | END | |
130 | } | |
131 | ||
132 | # Generate the CPU Graph for the current period of time for values given by | |
133 | # collectd we are now able to handle any kind of cpucount | |
134 | ||
135 | sub updatecpugraph { | |
136 | my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`; | |
137 | my $period = $_[0]; | |
138 | my @command = ( | |
139 | @GRAPH_ARGS, | |
140 | "-", | |
141 | "--start", | |
142 | "-1".$period, | |
143 | "-l 0", | |
144 | "-u 100", | |
145 | "-r", | |
146 | "-t ".$Lang::tr{'cpu usage per'}." ".$Lang::tr{$period."-graph"}, | |
147 | "-v ".$Lang::tr{'percentage'}, | |
148 | "--color=SHADEA".$color{"color19"}, | |
149 | "--color=SHADEB".$color{"color19"}, | |
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" | |
156 | ); | |
157 | ||
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 = ""; | |
167 | ||
168 | for(my $i = 0; $i < $cpucount; $i++) { | |
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 | ||
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.","; | |
186 | } | |
187 | ||
188 | for(my $i = 2; $i < $cpucount; $i++) { | |
189 | $addstring .= "ADDNAN,"; | |
190 | } | |
191 | ||
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 | } | |
206 | ||
207 | push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN,ADDNAN" | |
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'}) | |
242 | ,"GPRINT:userpct:MAX:%3.1lf%%" | |
243 | ,"GPRINT:userpct:AVERAGE:%3.2lf%%" | |
244 | ,"GPRINT:userpct:MIN:%3.2lf%%" | |
245 | ,"GPRINT:userpct:LAST:%3.2lf%%\\j" | |
246 | ,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'}) | |
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"); | |
256 | ||
257 | RRDs::graph (@command); | |
258 | $ERROR = RRDs::error; | |
259 | return "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR; | |
260 | } | |
261 | ||
262 | # Generate the Load Graph for the current period of time for values given by collecd | |
263 | ||
264 | sub updateloadgraph { | |
265 | my $period = $_[0]; | |
266 | RRDs::graph( | |
267 | @GRAPH_ARGS, | |
268 | "-", | |
269 | "--start", | |
270 | "-1".$period, | |
271 | "-l 0", | |
272 | "-r", | |
273 | "-t ".$Lang::tr{'uptime load average'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
274 | "-v ".$Lang::tr{'processes'}, | |
275 | "--color=SHADEA".$color{"color19"}, | |
276 | "--color=SHADEB".$color{"color19"}, | |
277 | "--color=BACK".$color{"color21"}, | |
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", | |
281 | "AREA:load1".$color{"color13"}."A0:1 ".$Lang::tr{'minute'}, | |
282 | "GPRINT:load1:LAST:%5.2lf", | |
283 | "AREA:load5".$color{"color18"}."A0:5 ".$Lang::tr{'minutes'}, | |
284 | "GPRINT:load5:LAST:%5.2lf", | |
285 | "AREA:load15".$color{"color14"}."A0:15 ".$Lang::tr{'minutes'}, | |
286 | "GPRINT:load15:LAST:%5.2lf\\j", | |
287 | "LINE1:load5".$color{"color13"}, | |
288 | "LINE1:load1".$color{"color18"}, | |
289 | ); | |
290 | $ERROR = RRDs::error; | |
291 | return "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR; | |
292 | } | |
293 | ||
294 | # Generate the Memory Graph for the current period of time for values given by collecd | |
295 | ||
296 | sub updatememorygraph { | |
297 | my $period = $_[0]; | |
298 | RRDs::graph( | |
299 | @GRAPH_ARGS, | |
300 | "-", | |
301 | "--start", | |
302 | "-1".$period, | |
303 | "-l 0", | |
304 | "-u 100", | |
305 | "-r", | |
306 | "-t ".$Lang::tr{'memory usage per'}." ".$Lang::tr{$period."-graph"}, | |
307 | "-v ".$Lang::tr{'percentage'}, | |
308 | "--color=SHADEA".$color{"color19"}, | |
309 | "--color=SHADEB".$color{"color19"}, | |
310 | "--color=BACK".$color{"color21"}, | |
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", | |
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; | |
347 | return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; | |
348 | } | |
349 | ||
350 | # Generate the Swap Graph for the current period of time for values given by collecd | |
351 | ||
352 | sub updateswapgraph { | |
353 | my $period = $_[0]; | |
354 | RRDs::graph( | |
355 | @GRAPH_ARGS, | |
356 | "-", | |
357 | "--start", | |
358 | "-1".$period, | |
359 | "-l 0", | |
360 | "-u 100", | |
361 | "-r", | |
362 | "-t ".$Lang::tr{'swap usage per'}." ".$Lang::tr{$period."-graph"}, | |
363 | "-v ".$Lang::tr{'percentage'}, | |
364 | "--color=SHADEA".$color{"color19"}, | |
365 | "--color=SHADEB".$color{"color19"}, | |
366 | "--color=BACK".$color{"color21"}, | |
367 | "DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE", | |
368 | "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE", | |
369 | "DEF:cached=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE", | |
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", | |
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", | |
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", | |
394 | ); | |
395 | $ERROR = RRDs::error; | |
396 | return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; | |
397 | } | |
398 | ||
399 | # Generate the Process Cpu Graph for the current period of time for values given by collecd | |
400 | ||
401 | sub updateprocessescpugraph { | |
402 | my @processesgraph = getprocesses(); | |
403 | my $period = $_[0]; | |
404 | my $count="0"; | |
405 | ||
406 | my @command = ( | |
407 | @GRAPH_ARGS, | |
408 | "-", | |
409 | "--start", | |
410 | "-1".$period, | |
411 | "-l 0", | |
412 | "-r", | |
413 | "-t ".$Lang::tr{'processes'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
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 | ||
428 | my $colorIndex = 0; | |
429 | foreach(@processesgraph){ | |
430 | my $colorIndex = 10 + $count % 15; | |
431 | my $color="$color{\"color$colorIndex\"}"; | |
432 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
433 | if ($count eq "0"){ | |
434 | push(@command,"AREA:".$name[1].$color."A0:".$name[1]); | |
435 | }else{ | |
436 | push(@command,"STACK:".$name[1].$color."A0:".$name[1]); | |
437 | } | |
438 | $count++; | |
439 | } | |
440 | ||
441 | RRDs::graph (@command); | |
442 | $ERROR = RRDs::error; | |
443 | return "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR; | |
444 | } | |
445 | ||
446 | # Generate the Process Memory Graph for the current period of time for values given by collecd | |
447 | ||
448 | sub updateprocessesmemorygraph { | |
449 | my @processesgraph = getprocesses(); | |
450 | my $period = $_[0]; | |
451 | my $count="0"; | |
452 | ||
453 | my @command = ( | |
454 | @GRAPH_ARGS, | |
455 | "-", | |
456 | "--start", | |
457 | "-1".$period, | |
458 | "-l 0", | |
459 | "-r", | |
460 | "-t ".$Lang::tr{'processes'}." ".$Lang::tr{'memory'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
461 | "-v ".$Lang::tr{'bytes'}, | |
462 | "--color=SHADEA".$color{"color19"}, | |
463 | "--color=SHADEB".$color{"color19"}, | |
464 | "--color=BACK".$color{"color21"} | |
465 | ); | |
466 | ||
467 | foreach(@processesgraph){ | |
468 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
469 | push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE"); | |
470 | } | |
471 | ||
472 | push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j"); | |
473 | ||
474 | my $colorIndex = 0; | |
475 | foreach(@processesgraph){ | |
476 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
477 | my $colorIndex = 10 + $count % 15; | |
478 | my $color="$color{\"color$colorIndex\"}"; | |
479 | if ($count eq "0"){ | |
480 | push(@command,"AREA:".$name[1].$color."A0:".$name[1]); | |
481 | }else{ | |
482 | push(@command,"STACK:".$name[1].$color."A0:".$name[1]); | |
483 | } | |
484 | $count++; | |
485 | } | |
486 | ||
487 | RRDs::graph (@command); | |
488 | $ERROR = RRDs::error; | |
489 | return "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR; | |
490 | } | |
491 | ||
492 | # Generate the Disk Graph for the current period of time for values given by collecd | |
493 | ||
494 | sub updatediskgraph { | |
495 | my $disk = $_[0]; | |
496 | my $period = $_[1]; | |
497 | RRDs::graph( | |
498 | @GRAPH_ARGS, | |
499 | "-", | |
500 | "--start", | |
501 | "-1".$period, | |
502 | "-r", | |
503 | "-t ".$disk." ".$Lang::tr{'disk access'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
504 | "-v ".$Lang::tr{'bytes per second'}, | |
505 | "--color=SHADEA".$color{"color19"}, | |
506 | "--color=SHADEB".$color{"color19"}, | |
507 | "--color=BACK".$color{"color21"}, | |
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", | |
510 | "CDEF:writen=write,-1,*", | |
511 | "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-".$disk.".rrd:standby:AVERAGE", | |
512 | "CDEF:st=standby,INF,*", | |
513 | "CDEF:st1=standby,NEGINF,*", | |
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; | |
533 | return "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR; | |
534 | } | |
535 | ||
536 | # Generate the Interface Graph for the current period of time for values given by collecd | |
537 | ||
538 | sub updateifgraph { | |
539 | my $interface = $_[0]; | |
540 | my $period = $_[1]; | |
541 | RRDs::graph( | |
542 | @GRAPH_ARGS, | |
543 | "-", | |
544 | "--start", | |
545 | "-1".$period, | |
546 | "-r", | |
547 | "-t ".$Lang::tr{'traffic on'}." ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
548 | "-v ".$Lang::tr{'bytes per second'}, | |
549 | "--color=SHADEA".$color{"color19"}, | |
550 | "--color=SHADEB".$color{"color19"}, | |
551 | "--color=BACK".$color{"color21"}, | |
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", | |
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", | |
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; | |
572 | return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; | |
573 | } | |
574 | ||
575 | sub updatevpngraph { | |
576 | my $interface = $_[0]; | |
577 | my $period = $_[1]; | |
578 | RRDs::graph( | |
579 | @GRAPH_ARGS, | |
580 | "-", | |
581 | "--start", | |
582 | "-1".$period, | |
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"}, | |
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", | |
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", | |
597 | "AREA:incoming#00dd00:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}), | |
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", | |
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; | |
609 | return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; | |
610 | } | |
611 | ||
612 | sub updatevpnn2ngraph { | |
613 | my $interface = $_[0]; | |
614 | my $period = $_[1]; | |
615 | RRDs::graph( | |
616 | @GRAPH_ARGS, | |
617 | "-", | |
618 | "--start", | |
619 | "-1".$period, | |
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", | |
640 | "AREA:incoming#00dd00:".sprintf("%-23s",$Lang::tr{'incoming traffic in bytes per second'}), | |
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", | |
645 | "STACK:overhead_in#116B11:".sprintf("%-23s",$Lang::tr{'incoming overhead in bytes per second'}), | |
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", | |
650 | "LINE1:compression_in#ff00ff:".sprintf("%-23s",$Lang::tr{'incoming compression in bytes per second'}), | |
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", | |
655 | "AREA:outgoingn#dd0000:".sprintf("%-23s",$Lang::tr{'outgoing traffic in bytes per second'}), | |
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", | |
660 | "STACK:overhead_outn#870C0C:".sprintf("%-23s",$Lang::tr{'outgoing overhead in bytes per second'}), | |
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", | |
665 | "LINE1:compression_outn#000000:".sprintf("%-23s",$Lang::tr{'outgoing compression in bytes per second'}), | |
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", | |
670 | ); | |
671 | $ERROR = RRDs::error; | |
672 | return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; | |
673 | } | |
674 | ||
675 | # Generate the Firewall Graph for the current period of time for values given by collecd | |
676 | ||
677 | sub updatefwhitsgraph { | |
678 | my $period = $_[0]; | |
679 | RRDs::graph( | |
680 | @GRAPH_ARGS, | |
681 | "-", | |
682 | "--start", | |
683 | "-1".$period, | |
684 | "-r", | |
685 | "-t ".$Lang::tr{'firewall hits per'}." ".$Lang::tr{$period."-graph"}, | |
686 | "-v ".$Lang::tr{'bytes per second'}, | |
687 | "--color=SHADEA".$color{"color19"}, | |
688 | "--color=SHADEB".$color{"color19"}, | |
689 | "--color=BACK".$color{"color21"}, | |
690 | "DEF:output=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYOUT/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE", | |
691 | "DEF:input=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYIN/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE", | |
692 | "DEF:forward=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-POLICYFWD/ipt_bytes-DROP_FORWARD.rrd:value:AVERAGE", | |
693 | "DEF:newnotsyn=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE", | |
694 | "DEF:portscan=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE", | |
695 | "DEF:spoofedmartian=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-SPOOFED_MARTIAN/ipt_bytes-DROP_SPOOFED_MARTIAN.rrd:value:AVERAGE", | |
696 | "DEF:hostile=".$mainsettings{'RRDLOG'}."/collectd/localhost/iptables-filter-HOSTILE_DROP/ipt_bytes-DROP_HOSTILE.rrd:value:AVERAGE", | |
697 | "COMMENT:".sprintf("%-26s",$Lang::tr{'caption'}), | |
698 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
699 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
700 | "COMMENT:".sprintf("%14s",$Lang::tr{'minimal'}), | |
701 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
702 | "AREA:output".$color{"color25"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (OUTPUT)"), | |
703 | "GPRINT:output:MAX:%8.1lf %sBps", | |
704 | "GPRINT:output:AVERAGE:%8.1lf %sBps", | |
705 | "GPRINT:output:MIN:%8.1lf %sBps", | |
706 | "GPRINT:output:LAST:%8.1lf %sBps\\j", | |
707 | "STACK:forward".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (FORWARD)"), | |
708 | "GPRINT:forward:MAX:%8.1lf %sBps", | |
709 | "GPRINT:forward:AVERAGE:%8.1lf %sBps", | |
710 | "GPRINT:forward:MIN:%8.1lf %sBps", | |
711 | "GPRINT:forward:LAST:%8.1lf %sBps\\j", | |
712 | "STACK:input".$color{"color24"}."A0:".sprintf("%-25s",$Lang::tr{'firewallhits'}." (INPUT)"), | |
713 | "GPRINT:input:MAX:%8.1lf %sBps", | |
714 | "GPRINT:input:AVERAGE:%8.1lf %sBps", | |
715 | "GPRINT:input:MIN:%8.1lf %sBps", | |
716 | "GPRINT:input:LAST:%8.1lf %sBps\\j", | |
717 | "STACK:newnotsyn".$color{"color14"}."A0:".sprintf("%-25s","NewNotSYN"), | |
718 | "GPRINT:newnotsyn:MAX:%8.1lf %sBps", | |
719 | "GPRINT:newnotsyn:AVERAGE:%8.1lf %sBps", | |
720 | "GPRINT:newnotsyn:MIN:%8.1lf %sBps", | |
721 | "GPRINT:newnotsyn:LAST:%8.1lf %sBps\\j", | |
722 | "STACK:portscan".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'portscans'}), | |
723 | "GPRINT:portscan:MAX:%8.1lf %sBps", | |
724 | "GPRINT:portscan:AVERAGE:%8.1lf %sBps", | |
725 | "GPRINT:portscan:MIN:%8.1lf %sBps", | |
726 | "GPRINT:portscan:LAST:%8.1lf %sBps\\j", | |
727 | "STACK:spoofedmartian".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'spoofed or martians'}), | |
728 | "GPRINT:spoofedmartian:MAX:%8.1lf %sBps", | |
729 | "GPRINT:spoofedmartian:AVERAGE:%8.1lf %sBps", | |
730 | "GPRINT:spoofedmartian:MIN:%8.1lf %sBps", | |
731 | "GPRINT:spoofedmartian:LAST:%8.1lf %sBps\\j", | |
732 | "STACK:hostile".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'hostile networks'}), | |
733 | "GPRINT:hostile:MAX:%8.1lf %sBps", | |
734 | "GPRINT:hostile:AVERAGE:%8.1lf %sBps", | |
735 | "GPRINT:hostile:MIN:%8.1lf %sBps", | |
736 | "GPRINT:hostile:LAST:%8.1lf %sBps\\j", | |
737 | ); | |
738 | $ERROR = RRDs::error; | |
739 | return "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR; | |
740 | } | |
741 | ||
742 | # Generate the Line Quality Graph for the current period of time for values given by collecd | |
743 | ||
744 | sub updatepinggraph { | |
745 | my $period = $_[1]; | |
746 | my $host = $_[0]; | |
747 | RRDs::graph( | |
748 | @GRAPH_ARGS, | |
749 | "-", | |
750 | "--start", | |
751 | "-1".$period, | |
752 | "-l 0", | |
753 | "-r", | |
754 | "-t ".$Lang::tr{'linkq'}." ".$host." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
755 | "-v ms", | |
756 | "--color=SHADEA".$color{"color19"}, | |
757 | "--color=SHADEB".$color{"color19"}, | |
758 | "--color=BACK".$color{"color21"}, | |
759 | "DEF:roundtrip=".$mainsettings{'RRDLOG'}."/collectd/localhost/ping/ping-".$host.".rrd:ping:AVERAGE", | |
760 | "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'})."\\j", | |
761 | "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/", | |
762 | "CDEF:r0=roundtrip,30,MIN", | |
763 | "CDEF:r1=roundtrip,70,MIN", | |
764 | "CDEF:r2=roundtrip,150,MIN", | |
765 | "CDEF:r3=roundtrip,300,MIN", | |
766 | "AREA:roundtrip".$color{"color25"}."A0:>300 ms", | |
767 | "AREA:r3".$color{"color18"}."A0:150-300 ms", | |
768 | "AREA:r2".$color{"color14"}."A0:70-150 ms", | |
769 | "AREA:r1".$color{"color17"}."A0:30-70 ms", | |
770 | "AREA:r0".$color{"color12"}."A0:<30 ms\\j", | |
771 | "COMMENT:$Lang::tr{'maximal'}", | |
772 | "COMMENT:$Lang::tr{'average'}", | |
773 | "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j", | |
774 | "LINE1:roundtrip#707070:", | |
775 | "GPRINT:roundtrip:MAX:%3.2lf ms", | |
776 | "GPRINT:roundtrip:AVERAGE:%3.2lf ms", | |
777 | "GPRINT:roundtrip:MIN:%3.2lf ms", | |
778 | "GPRINT:roundtrip:LAST:%3.2lf ms\\j", | |
779 | ); | |
780 | $ERROR = RRDs::error; | |
781 | return "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR; | |
782 | } | |
783 | ||
784 | sub updatewirelessgraph { | |
785 | my $period = $_[1]; | |
786 | my $interface = $_[0]; | |
787 | RRDs::graph( | |
788 | @GRAPH_ARGS, | |
789 | "-", | |
790 | "--start", | |
791 | "-1".$period, | |
792 | "-t Wireless ".$interface." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
793 | "-v dBm", | |
794 | "--color=SHADEA".$color{"color19"}, | |
795 | "--color=SHADEB".$color{"color19"}, | |
796 | "--color=BACK".$color{"color21"}, | |
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", | |
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; | |
816 | return "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR; | |
817 | } | |
818 | ||
819 | # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors | |
820 | ||
821 | sub updatehddgraph { | |
822 | my $disk = $_[0]; | |
823 | my $period = $_[1]; | |
824 | RRDs::graph( | |
825 | @GRAPH_ARGS, | |
826 | "-", | |
827 | "--start", | |
828 | "-1".$period, | |
829 | "-r", | |
830 | "-t ".$disk." ".$Lang::tr{'harddisk temperature'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
831 | "-v Celsius", | |
832 | "--color=SHADEA".$color{"color19"}, | |
833 | "--color=SHADEB".$color{"color19"}, | |
834 | "--color=BACK".$color{"color21"}, | |
835 | "DEF:temperature=".$mainsettings{'RRDLOG'}."/hddtemp-$disk.rrd:temperature:AVERAGE", | |
836 | "DEF:standby=".$mainsettings{'RRDLOG'}."/hddshutdown-$disk.rrd:standby:AVERAGE", | |
837 | "CDEF:st=standby,INF,*", | |
838 | "AREA:st".$color{"color20"}."A0:standby", | |
839 | "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} °C\\j", | |
840 | "COMMENT:$Lang::tr{'maximal'}", | |
841 | "COMMENT:$Lang::tr{'average'}", | |
842 | "COMMENT:$Lang::tr{'minimal'}", | |
843 | "COMMENT:$Lang::tr{'current'}\\j", | |
844 | "GPRINT:temperature:MAX:%3.0lf °C", | |
845 | "GPRINT:temperature:AVERAGE:%3.0lf °C", | |
846 | "GPRINT:temperature:MIN:%3.0lf °C", | |
847 | "GPRINT:temperature:LAST:%3.0lf °C\\j", | |
848 | ); | |
849 | $ERROR = RRDs::error; | |
850 | return "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR; | |
851 | } | |
852 | ||
853 | # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors | |
854 | ||
855 | sub updatehwtempgraph { | |
856 | my $period = $_[0]; | |
857 | ||
858 | my @command = ( | |
859 | @GRAPH_ARGS, | |
860 | "-", | |
861 | "--start", | |
862 | "-1".$period, | |
863 | "-r", | |
864 | "-t ".$Lang::tr{'mbmon temp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
865 | "-v Celsius", | |
866 | "--color=SHADEA".$color{"color19"}, | |
867 | "--color=SHADEB".$color{"color19"}, | |
868 | "--color=BACK".$color{"color21"}, | |
869 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
870 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
871 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
872 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
873 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
874 | ); | |
875 | ||
876 | foreach(@sensorsgraphs){ | |
877 | chomp($_); | |
878 | if ( $_ =~ /temperature/ ) { | |
879 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
880 | my $label = $2.$3;$label=~ s/-//g; | |
881 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
882 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
883 | } | |
884 | } | |
885 | ||
886 | foreach(@sensorsgraphs){ | |
887 | chomp($_); | |
888 | if ( $_ =~ /temperature/ ){ | |
889 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
890 | my $label = $2.$3;$label=~ s/-//g; | |
891 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
892 | 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",); | |
893 | } | |
894 | } | |
895 | ||
896 | RRDs::graph (@command); | |
897 | $ERROR = RRDs::error; | |
898 | return "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR; | |
899 | } | |
900 | ||
901 | # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors | |
902 | ||
903 | sub updatehwfangraph { | |
904 | my $period = $_[0]; | |
905 | ||
906 | my @command = ( | |
907 | @GRAPH_ARGS, | |
908 | "-", | |
909 | "--start", | |
910 | "-1".$period, | |
911 | "-r", | |
912 | "-t ".$Lang::tr{'mbmon fan'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
913 | "--color=SHADEA".$color{"color19"}, | |
914 | "--color=SHADEB".$color{"color19"}, | |
915 | "--color=BACK".$color{"color21"}, | |
916 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
917 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
918 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
919 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
920 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
921 | ); | |
922 | ||
923 | foreach(@sensorsgraphs){ | |
924 | chomp($_); | |
925 | if ( $_ =~ /fanspeed/ ) { | |
926 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
927 | my $label = $2.$3;$label=~ s/-//g; | |
928 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
929 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
930 | } | |
931 | } | |
932 | ||
933 | foreach(@sensorsgraphs){ | |
934 | chomp($_); | |
935 | if ( $_ =~ /fanspeed/ ){ | |
936 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
937 | my $label = $2.$3;$label=~ s/-//g; | |
938 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
939 | 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",); | |
940 | } | |
941 | } | |
942 | ||
943 | RRDs::graph (@command); | |
944 | $ERROR = RRDs::error; | |
945 | return "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR; | |
946 | } | |
947 | ||
948 | # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors | |
949 | ||
950 | sub updatehwvoltgraph { | |
951 | my $period = $_[0]; | |
952 | ||
953 | my @command = ( | |
954 | @GRAPH_ARGS, | |
955 | "-", | |
956 | "--start", | |
957 | "-1".$period, | |
958 | "-r", | |
959 | "-t ".$Lang::tr{'mbmon volt'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
960 | "--color=SHADEA".$color{"color19"}, | |
961 | "--color=SHADEB".$color{"color19"}, | |
962 | "--color=BACK".$color{"color21"}, | |
963 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
964 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
965 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
966 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
967 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
968 | ); | |
969 | ||
970 | foreach(@sensorsgraphs){ | |
971 | chomp($_); | |
972 | if ( $_ =~ /voltage/ ) { | |
973 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
974 | my $label = $2.$3;$label=~ s/-//g; | |
975 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
976 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
977 | } | |
978 | } | |
979 | ||
980 | foreach(@sensorsgraphs){ | |
981 | chomp($_); | |
982 | if ( $_ =~ /voltage/ ){ | |
983 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
984 | my $label = $2.$3;$label=~ s/-//g; | |
985 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
986 | 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",); | |
987 | } | |
988 | } | |
989 | ||
990 | RRDs::graph (@command); | |
991 | $ERROR = RRDs::error; | |
992 | return "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR; | |
993 | } | |
994 | ||
995 | ||
996 | # Generate the QoS Graph for the current period of time | |
997 | ||
998 | sub updateqosgraph { | |
999 | ||
1000 | my $period = $_[1]; | |
1001 | my %qossettings = (); | |
1002 | &General::readhash("${General::swroot}/qos/settings", \%qossettings); | |
1003 | ||
1004 | my $classentry = ""; | |
1005 | my @classes = (); | |
1006 | my @classline = (); | |
1007 | my $classfile = "/var/ipfire/qos/classes"; | |
1008 | ||
1009 | $qossettings{'DEV'} = $_[0]; | |
1010 | if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) { | |
1011 | $qossettings{'CLASSPRFX'} = '1'; | |
1012 | } else { | |
1013 | $qossettings{'CLASSPRFX'} = '2'; | |
1014 | } | |
1015 | ||
1016 | my $ERROR=""; | |
1017 | my $count="1"; | |
1018 | my %colorMap = (); # maps traffic classes to graph colors | |
1019 | ||
1020 | my @command = ( | |
1021 | @GRAPH_ARGS, | |
1022 | "-", | |
1023 | "--start", | |
1024 | "-1".$period, | |
1025 | "-r", | |
1026 | "-t ".$Lang::tr{'Utilization on'}." (".$qossettings{'DEV'}.") ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
1027 | "-v ".$Lang::tr{'bytes per second'}, | |
1028 | "--color=SHADEA".$color{"color19"}, | |
1029 | "--color=SHADEB".$color{"color19"}, | |
1030 | "--color=BACK".$color{"color21"}, | |
1031 | "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}), | |
1032 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
1033 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
1034 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
1035 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
1036 | ); | |
1037 | ||
1038 | open( FILE, "< $classfile" ) or die "Unable to read $classfile"; | |
1039 | @classes = <FILE>; | |
1040 | close FILE; | |
1041 | ||
1042 | foreach $classentry (sort @classes){ | |
1043 | @classline = split( /\;/, $classentry ); | |
1044 | ||
1045 | # create class <-> color mapping | |
1046 | my $colorKey = uc $classline[8]; # upper case class name as key | |
1047 | if(! exists $colorMap{$colorKey}) { | |
1048 | # add missing color to table, use colors 11-25 | |
1049 | my $colorIndex = 11 + ((scalar keys %colorMap) % 15); | |
1050 | $colorMap{$colorKey} = "$color{\"color$colorIndex\"}"; | |
1051 | } | |
1052 | ||
1053 | if ( $classline[0] eq $qossettings{'DEV'} ){ | |
1054 | push(@command, "DEF:$classline[1]=$mainsettings{'RRDLOG'}/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE"); | |
1055 | ||
1056 | # get color to be used for this graph | |
1057 | my $graphColor = $colorMap{$colorKey}; | |
1058 | ||
1059 | if ($count eq "1") { | |
1060 | push(@command, "AREA:$classline[1]$graphColor:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8])); | |
1061 | } else { | |
1062 | push(@command, "STACK:$classline[1]$graphColor:$Lang::tr{'Class'} $classline[1] -".sprintf("%15s",$classline[8])); | |
1063 | } | |
1064 | ||
1065 | push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps" | |
1066 | , "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps" | |
1067 | , "GPRINT:$classline[1]:MIN:%8.1lf %sBps" | |
1068 | , "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j"); | |
1069 | $count++; | |
1070 | } | |
1071 | } | |
1072 | RRDs::graph (@command); | |
1073 | $ERROR = RRDs::error; | |
1074 | return "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR; | |
1075 | } | |
1076 | ||
1077 | # Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors | |
1078 | ||
1079 | sub updatecpufreqgraph { | |
1080 | my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`; | |
1081 | my $period = $_[0]; | |
1082 | my @command = ( | |
1083 | @GRAPH_ARGS, | |
1084 | "-", | |
1085 | "--start", | |
1086 | "-1".$period, | |
1087 | "-r", | |
1088 | "-t ".$Lang::tr{'cpu frequency per'}." ".$Lang::tr{$period."-graph"}, | |
1089 | "-v MHz", | |
1090 | "--color=SHADEA".$color{"color19"}, | |
1091 | "--color=SHADEB".$color{"color19"}, | |
1092 | "--color=BACK".$color{"color21"}, | |
1093 | "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}), | |
1094 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
1095 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
1096 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
1097 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
1098 | ); | |
1099 | ||
1100 | for(my $i = 0; $i < $cpucount; $i++) { | |
1101 | my $j=$i+1; | |
1102 | push(@command,"DEF:cpu".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpufreq/cpufreq-".$i.".rrd:value:AVERAGE" | |
1103 | ,"CDEF:cpu".$i."=cpu".$i."_,1000000,/" | |
1104 | ,"LINE1:cpu".$i.$color{"color1$j"}."A0:cpu ".$i." " | |
1105 | ,"GPRINT:cpu".$i.":MAX:%3.0lf Mhz" | |
1106 | ,"GPRINT:cpu".$i.":AVERAGE:%3.0lf Mhz" | |
1107 | ,"GPRINT:cpu".$i.":MIN:%3.0lf Mhz" | |
1108 | ,"GPRINT:cpu".$i.":LAST:%3.0lf Mhz\\j"); | |
1109 | } | |
1110 | ||
1111 | RRDs::graph (@command); | |
1112 | $ERROR = RRDs::error; | |
1113 | return "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR; | |
1114 | } | |
1115 | ||
1116 | # Generate the Thermal Zone Temp CPU Graph | |
1117 | ||
1118 | sub updatethermaltempgraph { | |
1119 | my $thermalcount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone* 2>/dev/null | wc -l`; | |
1120 | my $period = $_[0]; | |
1121 | my @command = ( | |
1122 | @GRAPH_ARGS, | |
1123 | "-", | |
1124 | "--start", | |
1125 | "-1".$period, | |
1126 | "-r", | |
1127 | "-t ".$Lang::tr{'acpitemp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period."-graph"}, | |
1128 | "-v Celsius", | |
1129 | "--color=SHADEA".$color{"color19"}, | |
1130 | "--color=SHADEB".$color{"color19"}, | |
1131 | "--color=BACK".$color{"color21"}, | |
1132 | "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}), | |
1133 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
1134 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
1135 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
1136 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j" | |
1137 | ); | |
1138 | ||
1139 | for(my $i = 0; $i < $thermalcount; $i++) { | |
1140 | my $j=$i+1; | |
1141 | push(@command,"DEF:temp".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/thermal-thermal_zone".$i."/temperature-temperature.rrd:value:AVERAGE" | |
1142 | ,"CDEF:temp".$i."=temp".$i."_,1,/" | |
1143 | ,"LINE3:temp".$i.$color{"color1$j"}."A0:Temp ".$i." " | |
1144 | ,"GPRINT:temp".$i.":MAX:%3.0lf °C" | |
1145 | ,"GPRINT:temp".$i.":AVERAGE:%3.0lf °C" | |
1146 | ,"GPRINT:temp".$i.":MIN:%3.0lf °C" | |
1147 | ,"GPRINT:temp".$i.":LAST:%3.0lf °C\\j"); | |
1148 | } | |
1149 | ||
1150 | RRDs::graph (@command); | |
1151 | $ERROR = RRDs::error; | |
1152 | return "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR; | |
1153 | } | |
1154 | ||
1155 | ||
1156 | # Generate a random color, used by Qos Graph to be independent from the amount of values | |
1157 | ||
1158 | sub random_hex_color { | |
1159 | my $size = shift; | |
1160 | $size = 6 if $size !~ /^3|6$/; | |
1161 | my @hex = ( 0 .. 9, 'a' .. 'f' ); | |
1162 | my @color; | |
1163 | push @color, @hex[rand(@hex)] for 1 .. $size; | |
1164 | return join('', '#', @color); | |
1165 | } | |
1166 | ||
1167 | sub getprocesses { | |
1168 | my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/ 2>/dev/null`; | |
1169 | return @processesgraph; | |
1170 | } | |
1171 | ||
1172 | sub updateconntrackgraph { | |
1173 | my $period = $_[0]; | |
1174 | my @command = ( | |
1175 | @GRAPH_ARGS, | |
1176 | "-", | |
1177 | "--start", | |
1178 | "-1" . $period, | |
1179 | "-r", | |
1180 | "--lower-limit","0", | |
1181 | "-t $Lang::tr{'connection tracking'}", | |
1182 | "-v $Lang::tr{'open connections'}", | |
1183 | "DEF:conntrack=$mainsettings{'RRDLOG'}/collectd/localhost/conntrack/conntrack.rrd:entropy:AVERAGE", | |
1184 | "LINE3:conntrack#ff0000:" . sprintf("%-15s", $Lang::tr{'open connections'}), | |
1185 | "VDEF:ctmin=conntrack,MINIMUM", | |
1186 | "VDEF:ctmax=conntrack,MAXIMUM", | |
1187 | "VDEF:ctavg=conntrack,AVERAGE", | |
1188 | "GPRINT:ctmax:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'maximum'}), | |
1189 | "GPRINT:ctmin:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'minimum'}), | |
1190 | "GPRINT:ctavg:" . sprintf("%15s\\: %%5.0lf", $Lang::tr{'average'}) . "\\n", | |
1191 | "--color=BACK" . $color{"color21"}, | |
1192 | ); | |
1193 | ||
1194 | RRDs::graph(@command); | |
1195 | $ERROR = RRDs::error; | |
1196 | ||
1197 | return "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR; | |
1198 | } |