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