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