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