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