]>
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 | |
3 | # This is part of the IPFire Firewall | |
4 | ||
5 | ||
6 | package Graphs; | |
7 | ||
8 | use strict; | |
9 | use RRDs; | |
10 | ||
11 | require '/var/ipfire/general-functions.pl'; | |
12 | require "${General::swroot}/lang.pl"; | |
13 | require "${General::swroot}/header.pl"; | |
14 | ||
15 | my $ERROR; | |
16 | my $rrdlog = "/var/log/rrd"; | |
17 | my $graphs = "/srv/web/ipfire/html/graphs"; | |
18 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; | |
19 | ||
20 | # Read the global settings files to get the current theme and after this load | |
21 | # colors for this theme | |
22 | ||
23 | my %color = (); | |
24 | my %mainsettings = (); | |
25 | my %sensorsettings = (); | |
26 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
27 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
28 | ||
29 | ||
30 | # If the collection deamon is working and collecting lm_sensors data there will be | |
31 | # some data source named after a common scheme, with the sensorssettingsfile | |
32 | # the user is able to deactivate some of this parameters, in case not to show | |
33 | # false collected value´s may be disable. The user has the ability to ente | |
34 | # custom graph names in order to change temp0 to cpu or motherboad | |
35 | ||
36 | my $key; | |
37 | my $value; | |
38 | my @args = (); | |
39 | my $count = 0; | |
40 | my @sensorsgraphs = (); | |
41 | my @processesgraph = `ls -dA $rrdlog/collectd/localhost/processes-*/`; | |
42 | my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`; | |
43 | foreach (@sensorsdir) | |
44 | { | |
45 | chomp($_);chop($_); | |
46 | foreach (`ls $_/*`){ | |
47 | chomp($_); | |
48 | push(@sensorsgraphs,$_); | |
49 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
50 | my $label = $2.$3;$label=~ s/-//g; | |
51 | $sensorsettings{'LABEL-'.$label}="$label"; | |
52 | $sensorsettings{'LINE-'.$label}="checked"; | |
53 | } | |
54 | } | |
55 | ||
56 | &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings); | |
57 | use Encode 'from_to'; | |
58 | ||
59 | my %tr=(); | |
60 | if ((${Lang::language} eq 'el') || | |
61 | (${Lang::language} eq 'fa') || | |
62 | (${Lang::language} eq 'ru') || | |
63 | (${Lang::language} eq 'th') || | |
64 | (${Lang::language} eq 'vi') || | |
65 | (${Lang::language} eq 'zh') || | |
66 | (${Lang::language} eq 'zt')) { | |
67 | eval `/bin/cat "${General::swroot}/langs/en.pl"`; | |
68 | } else { | |
69 | %tr=%Lang::tr; # use translated version for other languages | |
70 | } | |
71 | ||
72 | # Generate the CPU Graph for the current period of time for values given by | |
73 | # collectd atm only cpu average is displayed and only 1 or 2 cpus is working | |
74 | ||
75 | sub updatecpugraph { | |
76 | my $period = $_[0]; | |
77 | my @command = ("$graphs/cpu-$period.png", | |
78 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}", | |
79 | "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r", | |
80 | "--color", "SHADEA".$color{"color19"}, | |
81 | "--color", "SHADEB".$color{"color19"}, | |
82 | "--color", "BACK".$color{"color21"}, | |
83 | "-t $Lang::tr{'cpu usage per'} $Lang::tr{$period}"); | |
84 | ||
85 | if ( -e "$rrdlog/collectd/localhost/cpu-1/" ){ | |
86 | push(@command,"DEF:iowait0=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE", | |
87 | "DEF:nice0=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE", | |
88 | "DEF:interrupt0=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE", | |
89 | "DEF:steal0=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE", | |
90 | "DEF:user0=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE", | |
91 | "DEF:system0=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE", | |
92 | "DEF:idle0=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE", | |
93 | "DEF:irq0=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE"); | |
94 | push(@command,"DEF:iowait1=$rrdlog/collectd/localhost/cpu-1/cpu-wait.rrd:value:AVERAGE", | |
95 | "DEF:nice1=$rrdlog/collectd/localhost/cpu-1/cpu-nice.rrd:value:AVERAGE", | |
96 | "DEF:interrupt1=$rrdlog/collectd/localhost/cpu-1/cpu-interrupt.rrd:value:AVERAGE", | |
97 | "DEF:steal1=$rrdlog/collectd/localhost/cpu-1/cpu-steal.rrd:value:AVERAGE", | |
98 | "DEF:user1=$rrdlog/collectd/localhost/cpu-1/cpu-user.rrd:value:AVERAGE", | |
99 | "DEF:system1=$rrdlog/collectd/localhost/cpu-1/cpu-system.rrd:value:AVERAGE", | |
100 | "DEF:idle1=$rrdlog/collectd/localhost/cpu-1/cpu-idle.rrd:value:AVERAGE", | |
101 | "DEF:irq1=$rrdlog/collectd/localhost/cpu-1/cpu-softirq.rrd:value:AVERAGE"); | |
102 | push(@command,"CDEF:user=user0,user1,+", | |
103 | "CDEF:nice=nice0,nice1,+", | |
104 | "CDEF:interrupt=interrupt0,interrupt1,+", | |
105 | "CDEF:steal=steal0,steal1,+", | |
106 | "CDEF:system=system0,system1,+", | |
107 | "CDEF:idle=idle0,idle1,+", | |
108 | "CDEF:iowait=iowait0,iowait1,+", | |
109 | "CDEF:irq=irq0,irq1,+"); | |
110 | } | |
111 | else { | |
112 | push(@command,"DEF:iowait=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE", | |
113 | "DEF:nice=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE", | |
114 | "DEF:interrupt=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE", | |
115 | "DEF:steal=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE", | |
116 | "DEF:user=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE", | |
117 | "DEF:system=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE", | |
118 | "DEF:idle=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE", | |
119 | "DEF:irq=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE"); | |
120 | } | |
121 | push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+", | |
122 | "CDEF:userpct=100,user,total,/,*", | |
123 | "CDEF:nicepct=100,nice,total,/,*", | |
124 | "CDEF:interruptpct=100,interrupt,total,/,*", | |
125 | "CDEF:stealpct=100,steal,total,/,*", | |
126 | "CDEF:systempct=100,system,total,/,*", | |
127 | "CDEF:idlepct=100,idle,total,/,*", | |
128 | "CDEF:iowaitpct=100,iowait,total,/,*", | |
129 | "CDEF:irqpct=100,irq,total,/,*", | |
130 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
131 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
132 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
133 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
134 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
135 | "AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'}), | |
136 | "GPRINT:iowaitpct:MAX:%3.2lf%%", | |
137 | "GPRINT:iowaitpct:AVERAGE:%3.2lf%%", | |
138 | "GPRINT:iowaitpct:MIN:%3.2lf%%", | |
139 | "GPRINT:iowaitpct:LAST:%3.2lf%%\\j", | |
140 | "STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'}), | |
141 | "GPRINT:irqpct:MAX:%3.2lf%%", | |
142 | "GPRINT:irqpct:AVERAGE:%3.2lf%%", | |
143 | "GPRINT:irqpct:MIN:%3.2lf%%", | |
144 | "GPRINT:irqpct:LAST:%3.2lf%%\\j", | |
145 | "STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'}), | |
146 | "GPRINT:nicepct:MAX:%3.2lf%%", | |
147 | "GPRINT:nicepct:AVERAGE:%3.2lf%%", | |
148 | "GPRINT:nicepct:MIN:%3.2lf%%", | |
149 | "GPRINT:nicepct:LAST:%3.2lf%%\\j", | |
150 | "STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'}), | |
151 | "GPRINT:interruptpct:MAX:%3.2lf%%", | |
152 | "GPRINT:interruptpct:AVERAGE:%3.2lf%%", | |
153 | "GPRINT:interruptpct:MIN:%3.2lf%%", | |
154 | "GPRINT:interruptpct:LAST:%3.2lf%%\\j", | |
155 | "STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'}), | |
156 | "GPRINT:stealpct:MAX:%3.2lf%%", | |
157 | "GPRINT:stealpct:AVERAGE:%3.2lf%%", | |
158 | "GPRINT:stealpct:MIN:%3.2lf%%", | |
159 | "GPRINT:stealpct:LAST:%3.2lf%%\\j", | |
160 | "STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'}), | |
161 | "GPRINT:userpct:MAX:%3.2lf%%", | |
162 | "GPRINT:userpct:AVERAGE:%3.2lf%%", | |
163 | "GPRINT:userpct:MIN:%3.2lf%%", | |
164 | "GPRINT:userpct:LAST:%3.2lf%%\\j", | |
165 | "STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'}), | |
166 | "GPRINT:systempct:MAX:%3.2lf%%", | |
167 | "GPRINT:systempct:AVERAGE:%3.2lf%%", | |
168 | "GPRINT:systempct:MIN:%3.2lf%%", | |
169 | "GPRINT:systempct:LAST:%3.2lf%%\\j", | |
170 | "STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'}), | |
171 | "GPRINT:idlepct:MAX:%3.2lf%%", | |
172 | "GPRINT:idlepct:AVERAGE:%3.2lf%%", | |
173 | "GPRINT:idlepct:MIN:%3.2lf%%", | |
174 | "GPRINT:idlepct:LAST:%3.2lf%%\\j"); | |
175 | ||
176 | RRDs::graph (@command); | |
177 | $ERROR = RRDs::error; | |
178 | print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR; | |
179 | } | |
180 | ||
0950b1ec AF |
181 | # Generate the CPU Frequency Graph for the current period of time for values given by |
182 | # only 1 or 2 cpus is working | |
183 | sub updatecpufreqgraph { | |
184 | if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd" ){ | |
185 | ||
186 | my $period = $_[0]; | |
187 | my @command = ("$graphs/cpufreq-$period.png", | |
188 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v Mhz", | |
189 | "-w 600", "-h 125", "-r", | |
190 | "--color", "SHADEA".$color{"color19"}, | |
191 | "--color", "SHADEB".$color{"color19"}, | |
192 | "--color", "BACK".$color{"color21"}, | |
193 | "-t $Lang::tr{'cpu frequency per'} $Lang::tr{$period}"); | |
194 | ||
195 | if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){ | |
196 | push(@command,"DEF:cpu1_=$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd:value:AVERAGE"); | |
197 | } | |
198 | push(@command,"DEF:cpu0_=$rrdlog/collectd/localhost/cpufreq/cpufreq-0.rrd:value:AVERAGE"); | |
199 | ||
200 | if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){ | |
201 | push(@command,"CDEF:cpu1=cpu1_,1000000,/"); | |
202 | } | |
142fb256 AF |
203 | push(@command,"CDEF:cpu0=cpu0_,1000000,/", |
204 | "COMMENT:CPU", | |
0950b1ec AF |
205 | "COMMENT:$Lang::tr{'maximal'}", |
206 | "COMMENT:$Lang::tr{'average'}", | |
207 | "COMMENT:$Lang::tr{'minimal'}", | |
142fb256 AF |
208 | "COMMENT:$Lang::tr{'current'}\\j",); |
209 | ||
210 | ||
211 | if ( -e "$rrdlog/collectd/localhost/cpufreq/cpufreq-1.rrd" ){ | |
a041a28d | 212 | push(@command,"LINE3:cpu1".$color{"color12"}."A0:1", |
0950b1ec AF |
213 | "GPRINT:cpu1:MAX:%3.0lf Mhz", |
214 | "GPRINT:cpu1:AVERAGE:%3.0lf Mhz", | |
215 | "GPRINT:cpu1:MIN:%3.0lf Mhz", | |
216 | "GPRINT:cpu1:LAST:%3.0lf Mhz\\j",); | |
217 | } | |
a041a28d | 218 | push(@command,"LINE2:cpu0".$color{"color11"}."A1:0", |
0950b1ec AF |
219 | "GPRINT:cpu0:MAX:%3.0lf Mhz", |
220 | "GPRINT:cpu0:AVERAGE:%3.0lf Mhz", | |
221 | "GPRINT:cpu0:MIN:%3.0lf Mhz", | |
222 | "GPRINT:cpu0:LAST:%3.0lf Mhz\\j",); | |
223 | ||
224 | RRDs::graph (@command); | |
225 | $ERROR = RRDs::error; | |
226 | print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR; | |
227 | } | |
228 | } | |
229 | ||
230 | ||
3961e831 AF |
231 | # Generate the Load Graph for the current period of time for values given by collecd |
232 | ||
233 | sub updateloadgraph { | |
234 | my $period = $_[0]; | |
235 | ||
236 | RRDs::graph ("$graphs/load-$period.png", | |
237 | "--start", "-1$period", "-aPNG", | |
238 | "-w 600", "-h 125", "-i", "-z", "-W www.ipfire.org", "-l 0", "-r", "--alt-y-grid", | |
239 | "-t Load Average $Lang::tr{'graph per'} $Lang::tr{$period}", "-v $Lang::tr{'processes'}", | |
240 | "--color", "SHADEA".$color{"color19"}, | |
241 | "--color", "SHADEB".$color{"color19"}, | |
242 | "--color", "BACK".$color{"color21"}, | |
243 | "DEF:load1=$rrdlog/collectd/localhost/load/load.rrd:shortterm:AVERAGE", | |
244 | "DEF:load5=$rrdlog/collectd/localhost/load/load.rrd:midterm:AVERAGE", | |
245 | "DEF:load15=$rrdlog/collectd/localhost/load/load.rrd:longterm:AVERAGE", | |
246 | "AREA:load1".$color{"color13"}."A0:1 Minute:", | |
247 | "GPRINT:load1:LAST:%5.2lf", | |
248 | "AREA:load5".$color{"color18"}."A0:5 Minuten:", | |
249 | "GPRINT:load5:LAST:%5.2lf", | |
250 | "AREA:load15".$color{"color14"}."A0:15 Minuten:", | |
251 | "GPRINT:load15:LAST:%5.2lf\\j", | |
252 | "LINE1:load5".$color{"color13"}, | |
253 | "LINE1:load1".$color{"color18"}); | |
254 | $ERROR = RRDs::error; | |
255 | print "Error in RRD::graph for load: $ERROR\n" if $ERROR; | |
256 | } | |
257 | ||
0950b1ec | 258 | |
3961e831 AF |
259 | # Generate the Memory and Swap Graph for the current period of time for values given by collecd |
260 | ||
261 | sub updatememgraph { | |
262 | my $period = $_[0]; | |
263 | ||
264 | RRDs::graph ("$graphs/memory-$period.png", | |
265 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}", | |
266 | "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r", | |
267 | "--color", "SHADEA".$color{"color19"}, | |
268 | "--color", "SHADEB".$color{"color19"}, | |
269 | "--color", "BACK".$color{"color21"}, | |
270 | "-t $Lang::tr{'memory usage per'} $Lang::tr{$period}", | |
271 | "DEF:used=$rrdlog/collectd/localhost/memory/memory-used.rrd:value:AVERAGE", | |
272 | "DEF:free=$rrdlog/collectd/localhost/memory/memory-free.rrd:value:AVERAGE", | |
273 | "DEF:buffer=$rrdlog/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE", | |
274 | "DEF:cache=$rrdlog/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE", | |
275 | "CDEF:total=used,free,cache,buffer,+,+,+", | |
276 | "CDEF:usedpct=used,total,/,100,*", | |
277 | "CDEF:bufferpct=buffer,total,/,100,*", | |
278 | "CDEF:cachepct=cache,total,/,100,*", | |
279 | "CDEF:freepct=free,total,/,100,*", | |
280 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
281 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
282 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
283 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
284 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
285 | "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used memory'}), | |
286 | "GPRINT:usedpct:MAX:%3.2lf%%", | |
287 | "GPRINT:usedpct:AVERAGE:%3.2lf%%", | |
288 | "GPRINT:usedpct:MIN:%3.2lf%%", | |
289 | "GPRINT:usedpct:LAST:%3.2lf%%\\j", | |
290 | "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'buffered memory'}), | |
291 | "GPRINT:bufferpct:MAX:%3.2lf%%", | |
292 | "GPRINT:bufferpct:AVERAGE:%3.2lf%%", | |
293 | "GPRINT:bufferpct:MIN:%3.2lf%%", | |
294 | "GPRINT:bufferpct:LAST:%3.2lf%%\\j", | |
295 | "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'cached memory'}), | |
296 | "GPRINT:cachepct:MAX:%3.2lf%%", | |
297 | "GPRINT:cachepct:AVERAGE:%3.2lf%%", | |
298 | "GPRINT:cachepct:MIN:%3.2lf%%", | |
299 | "GPRINT:cachepct:LAST:%3.2lf%%\\j", | |
300 | "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free memory'}), | |
301 | "GPRINT:freepct:MAX:%3.2lf%%", | |
302 | "GPRINT:freepct:AVERAGE:%3.2lf%%", | |
303 | "GPRINT:freepct:MIN:%3.2lf%%", | |
304 | "GPRINT:freepct:LAST:%3.2lf%%\\j"); | |
305 | $ERROR = RRDs::error; | |
306 | print "Error in RRD::graph for mem: $ERROR\n" if $ERROR; | |
307 | ||
308 | RRDs::graph ("$graphs/swap-$period.png", | |
309 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}", | |
310 | "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r", | |
311 | "--color", "SHADEA".$color{"color19"}, | |
312 | "--color", "SHADEB".$color{"color19"}, | |
313 | "--color", "BACK".$color{"color21"}, | |
314 | "-t $Lang::tr{'swap usage per'} $Lang::tr{$period}", | |
315 | "DEF:used=$rrdlog/collectd/localhost/swap/swap-used.rrd:value:AVERAGE", | |
316 | "DEF:free=$rrdlog/collectd/localhost/swap/swap-free.rrd:value:AVERAGE", | |
317 | "DEF:cached=$rrdlog/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE", | |
318 | "CDEF:total=used,free,cached,+,+", | |
319 | "CDEF:usedpct=100,used,total,/,*", | |
320 | "CDEF:freepct=100,free,total,/,*", | |
321 | "CDEF:cachedpct=100,cached,total,/,*", | |
322 | "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}), | |
323 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
324 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
325 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
326 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
327 | "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used swap'}), | |
328 | "GPRINT:usedpct:MAX:%3.2lf%%", | |
329 | "GPRINT:usedpct:AVERAGE:%3.2lf%%", | |
330 | "GPRINT:usedpct:MIN:%3.2lf%%", | |
331 | "GPRINT:usedpct:LAST:%3.2lf%%\\j", | |
332 | "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}), | |
333 | "GPRINT:freepct:MAX:%3.2lf%%", | |
334 | "GPRINT:freepct:AVERAGE:%3.2lf%%", | |
335 | "GPRINT:freepct:MIN:%3.2lf%%", | |
336 | "GPRINT:freepct:LAST:%3.2lf%%\\j", | |
337 | "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}), | |
338 | "GPRINT:cachedpct:MAX:%3.2lf%%", | |
339 | "GPRINT:cachedpct:AVERAGE:%3.2lf%%", | |
340 | "GPRINT:cachedpct:MIN:%3.2lf%%", | |
341 | "GPRINT:cachedpct:LAST:%3.2lf%%\\j"); | |
342 | $ERROR = RRDs::error; | |
343 | print "Error in RRD::graph for swap: $ERROR\n" if $ERROR; | |
344 | } | |
345 | ||
346 | # Generate the Disk Graph for the current period of time for values given by collecd | |
347 | ||
348 | sub updatediskgraph { | |
349 | my $period = $_[0]; | |
350 | my $disk = $_[1]; | |
351 | ||
352 | RRDs::graph ("$graphs/disk-$disk-$period.png", | |
353 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}", | |
354 | "--alt-y-grid", "-w 600", "-h 125", "-r", "-z", | |
355 | "--color", "SHADEA".$color{"color19"}, | |
356 | "--color", "SHADEB".$color{"color19"}, | |
357 | "--color", "BACK".$color{"color21"}, | |
358 | "-t $disk $Lang::tr{'disk access per'} $Lang::tr{$period}", | |
359 | "DEF:read=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE", | |
360 | "DEF:write=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE", | |
361 | "CDEF:writen=write,-1,*", | |
362 | "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE", | |
363 | "CDEF:st=standby,INF,*", | |
364 | "CDEF:st1=standby,-INF,*", | |
365 | "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}), | |
366 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
367 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
368 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
369 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
370 | "AREA:st".$color{"color20"}."A0:", | |
371 | "AREA:st1".$color{"color20"}."A0:standby\\j", | |
372 | "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}), | |
373 | "GPRINT:read:MAX:%8.1lf %sBps", | |
374 | "GPRINT:read:AVERAGE:%8.1lf %sBps", | |
375 | "GPRINT:read:MIN:%8.1lf %sBps", | |
376 | "GPRINT:read:LAST:%8.1lf %sBps\\j", | |
377 | "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}), | |
378 | "GPRINT:write:MAX:%8.1lf %sBps", | |
379 | "GPRINT:write:AVERAGE:%8.1lf %sBps", | |
380 | "GPRINT:write:MIN:%8.1lf %sBps", | |
381 | "GPRINT:write:LAST:%8.1lf %sBps\\j"); | |
382 | $ERROR = RRDs::error; | |
383 | print "Error in RRD::graph for disk: $ERROR\n" if $ERROR; | |
384 | } | |
385 | ||
386 | # Generate the Interface Graph for the current period of time for values given by collecd | |
387 | ||
388 | sub updateifgraph { | |
389 | my $interface = $_[0]; | |
390 | my $period = $_[1]; | |
391 | ||
392 | RRDs::graph ("$graphs/$interface-$period.png", | |
393 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}", | |
394 | "--alt-y-grid", "-w 600", "-h 125", "-z", "-r", | |
395 | "--color", "SHADEA".$color{"color19"}, | |
396 | "--color", "SHADEB".$color{"color19"}, | |
397 | "--color", "BACK".$color{"color21"}, | |
398 | "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}", | |
399 | "-v$Lang::tr{'bytes per second'}", | |
400 | "DEF:incoming=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:rx:AVERAGE", | |
401 | "DEF:outgoing=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:tx:AVERAGE", | |
402 | "CDEF:outgoingn=outgoing,-1,*", | |
403 | "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}), | |
404 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
405 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
406 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
407 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
408 | "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}), | |
409 | "GPRINT:incoming:MAX:%8.1lf %sBps", | |
410 | "GPRINT:incoming:AVERAGE:%8.1lf %sBps", | |
411 | "GPRINT:incoming:MIN:%8.1lf %sBps", | |
412 | "GPRINT:incoming:LAST:%8.1lf %sBps\\j", | |
413 | "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}), | |
414 | "GPRINT:outgoing:MAX:%8.1lf %sBps", | |
415 | "GPRINT:outgoing:AVERAGE:%8.1lf %sBps", | |
416 | "GPRINT:outgoing:MIN:%8.1lf %sBps", | |
417 | "GPRINT:outgoing:LAST:%8.1lf %sBps\\j"); | |
418 | $ERROR = RRDs::error; | |
419 | print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR; | |
420 | } | |
421 | ||
422 | # Generate the Firewall Graph for the current period of time for values given by collecd | |
423 | ||
424 | sub updatefwhitsgraph { | |
425 | my $period = $_[0]; | |
426 | RRDs::graph ("$graphs/fwhits-$period.png", | |
427 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", | |
428 | "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}", | |
429 | "--color", "SHADEA".$color{"color19"}, | |
430 | "--color", "SHADEB".$color{"color19"}, | |
431 | "--color", "BACK".$color{"color21"}, | |
432 | "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}", | |
433 | "DEF:output=$rrdlog/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE", | |
434 | "DEF:input=$rrdlog/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE", | |
435 | "DEF:newnotsyn=$rrdlog/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE", | |
436 | "DEF:portscan=$rrdlog/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE", | |
437 | "CDEF:amount=output,input,newnotsyn,+,+", | |
438 | "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}), | |
439 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
440 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
441 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
442 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
443 | "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr{'firewallhits'}), | |
444 | "GPRINT:amount:MAX:%8.1lf %sBps", | |
445 | "GPRINT:amount:AVERAGE:%8.1lf %sBps", | |
446 | "GPRINT:amount:MIN:%8.1lf %sBps", | |
447 | "GPRINT:amount:LAST:%8.1lf %sBps\\j", | |
448 | "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr{'portscans'}), | |
449 | "GPRINT:portscan:MAX:%8.1lf %sBps", | |
450 | "GPRINT:portscan:MIN:%8.1lf %sBps", | |
451 | "GPRINT:portscan:AVERAGE:%8.1lf %sBps", | |
452 | "GPRINT:portscan:LAST:%8.1lf %sBps\\j"); | |
453 | $ERROR = RRDs::error; | |
454 | print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR; | |
455 | } | |
456 | ||
457 | # Generate the Line Quality Graph for the current period of time for values given by collecd | |
458 | ||
cee25dda | 459 | sub updatepinggraph { |
3961e831 | 460 | my $period = $_[0]; |
cee25dda CS |
461 | my $host = $_[1]; |
462 | RRDs::graph ("$graphs/$host-$period.png", | |
3961e831 AF |
463 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", |
464 | "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-r", "-v ms", | |
cee25dda | 465 | "-t $Lang::tr{'linkq'} $host $Lang::tr{'graph per'} $Lang::tr{$period}", |
3961e831 AF |
466 | "--color", "SHADEA".$color{"color19"}, |
467 | "--color", "SHADEB".$color{"color19"}, | |
468 | "--color", "BACK".$color{"color21"}, | |
cee25dda | 469 | "DEF:roundtrip=$rrdlog/collectd/localhost/ping/ping-$host.rrd:ping:AVERAGE", |
3961e831 AF |
470 | "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'})."\\j", |
471 | "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/", | |
472 | "CDEF:r0=roundtrip,30,MIN", | |
473 | "CDEF:r1=roundtrip,70,MIN", | |
474 | "CDEF:r2=roundtrip,150,MIN", | |
475 | "CDEF:r3=roundtrip,300,MIN", | |
476 | "AREA:roundtrip".$color{"color25"}."A0:>300 ms", | |
477 | "AREA:r3".$color{"color18"}."A0:150-300 ms", | |
478 | "AREA:r2".$color{"color14"}."A0:70-150 ms", | |
479 | "AREA:r1".$color{"color17"}."A0:30-70 ms", | |
480 | "AREA:r0".$color{"color12"}."A0:<30 ms\\j", | |
cee25dda CS |
481 | "COMMENT:$Lang::tr{'maximal'}", |
482 | "COMMENT:$Lang::tr{'average'}", | |
483 | "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j", | |
3961e831 AF |
484 | "LINE1:roundtrip#707070:", |
485 | "GPRINT:roundtrip:MAX:%3.2lf ms", | |
486 | "GPRINT:roundtrip:AVERAGE:%3.2lf ms", | |
487 | "GPRINT:roundtrip:MIN:%3.2lf ms", | |
488 | "GPRINT:roundtrip:LAST:%3.2lf ms\\j"); | |
489 | $ERROR = RRDs::error; | |
490 | print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR; | |
491 | } | |
492 | ||
493 | # Generate the Hdd Graph for the current period of time for values given by collecd | |
494 | ||
495 | sub updatehddgraph { | |
496 | ||
497 | my $disk = $_[0]; | |
498 | my $period = $_[1]; | |
499 | ||
500 | RRDs::graph ("$graphs/hddtemp-$disk-$period.png", | |
501 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", | |
502 | "--alt-y-grid", "-w 600", "-h 125", | |
503 | "--color", "SHADEA".$color{"color19"}, | |
504 | "--color", "SHADEB".$color{"color19"}, | |
505 | "--color", "BACK".$color{"color21"}, | |
506 | "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}", | |
507 | "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE", | |
508 | "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE", | |
509 | "CDEF:st=standby,INF,*", | |
510 | "AREA:st".$color{"color20"}."A0:standby", | |
511 | "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j", | |
512 | "COMMENT:$Lang::tr{'maximal'}", | |
513 | "COMMENT:$Lang::tr{'average'}", | |
514 | "COMMENT:$Lang::tr{'minimal'}", | |
515 | "COMMENT:$Lang::tr{'current'}\\j", | |
516 | "GPRINT:temperature:MAX:%3.0lf Grad C", | |
517 | "GPRINT:temperature:AVERAGE:%3.0lf Grad C", | |
518 | "GPRINT:temperature:MIN:%3.0lf Grad C", | |
519 | "GPRINT:temperature:LAST:%3.0lf Grad C\\j", | |
520 | ); | |
521 | $ERROR = RRDs::error; | |
522 | print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR; | |
523 | } | |
524 | ||
525 | # Generate the QoS Graph for the current period of time | |
526 | ||
527 | sub overviewgraph { | |
528 | ||
529 | my $period = $_[0]; | |
530 | my $periodstring; | |
531 | my $description; | |
532 | my %qossettings = (); | |
533 | &General::readhash("${General::swroot}/qos/settings", \%qossettings); | |
534 | my $classentry = ""; | |
535 | my @classes = (); | |
536 | my @classline = (); | |
537 | my $classfile = "/var/ipfire/qos/classes"; | |
538 | ||
539 | $qossettings{'DEV'} = $_[1]; | |
540 | if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) { | |
541 | $qossettings{'CLASSPRFX'} = '1'; | |
542 | } else { | |
543 | $qossettings{'CLASSPRFX'} = '2'; | |
544 | } | |
545 | ||
546 | if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;} | |
547 | 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'})";} | |
548 | ||
549 | my $ERROR=""; | |
550 | my $count="1"; | |
551 | my $color="#000000"; | |
552 | my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png", | |
553 | "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org", | |
554 | "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}", | |
555 | "--color", "SHADEA".$color{"color19"}, | |
556 | "--color", "SHADEB".$color{"color19"}, | |
557 | "--color", "BACK".$color{"color21"}, | |
558 | "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}), | |
559 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
560 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
561 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
562 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
563 | $description | |
564 | ); | |
565 | open( FILE, "< $classfile" ) or die "Unable to read $classfile"; | |
566 | @classes = <FILE>; | |
567 | close FILE; | |
568 | foreach $classentry (sort @classes) | |
569 | { | |
570 | @classline = split( /\;/, $classentry ); | |
571 | if ( $classline[0] eq $qossettings{'DEV'} ) | |
572 | { | |
573 | $color=random_hex_color(6); | |
574 | push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE"); | |
575 | ||
576 | if ($count eq "1") { | |
577 | push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8])); | |
578 | } else { | |
579 | push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8])); | |
580 | ||
581 | } | |
582 | push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps"); | |
583 | push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps"); | |
584 | push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps"); | |
585 | push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j"); | |
586 | $count++; | |
587 | } | |
588 | } | |
589 | RRDs::graph (@command); | |
590 | $ERROR = RRDs::error; | |
591 | print "$ERROR"; | |
592 | } | |
593 | ||
594 | # Generate the Temperature Graph for the current period of time for values given by collecd and lm_sensors | |
595 | ||
596 | sub updatehwtempgraph { | |
597 | ||
598 | my $period = $_[0]; | |
599 | ||
600 | my @command = ("$graphs/sensors-hwtemp-$period.png", | |
601 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
602 | "--alt-y-grid", "-w 600", "-h 125", | |
603 | "--color", "SHADEA".$color{"color19"},"--color", | |
604 | "SHADEB".$color{"color19"},"--color", | |
605 | "BACK".$color{"color21"}, | |
606 | "-t $Lang::tr{'sensors temp'} $Lang::tr{'graph per'} $Lang::tr{$period}"); | |
607 | ||
608 | foreach(@sensorsgraphs){ | |
609 | chomp($_); | |
610 | if ( $_ =~ /temperature/ ) { | |
611 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
612 | my $label = $2.$3;$label=~ s/-//g; | |
613 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
614 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
615 | } | |
616 | } | |
617 | 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"); | |
618 | foreach(@sensorsgraphs){ | |
619 | chomp($_); | |
620 | if ( $_ =~ /temperature/ ){ | |
621 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
622 | my $label = $2.$3;$label=~ s/-//g; | |
623 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
624 | 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",); | |
625 | } | |
626 | } | |
627 | RRDs::graph (@command); | |
628 | $ERROR = RRDs::error; | |
629 | print "$ERROR"; | |
630 | } | |
631 | ||
632 | # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors | |
633 | ||
634 | sub updatehwvoltgraph { | |
635 | ||
636 | my $period = $_[0]; | |
637 | ||
638 | my @command = ("$graphs/sensors-hwvolt-$period.png", | |
639 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
640 | "--alt-y-grid", "-w 600", "-h 125", | |
641 | "--color", "SHADEA".$color{"color19"},"--color", | |
642 | "SHADEB".$color{"color19"},"--color", | |
643 | "BACK".$color{"color21"}, | |
644 | "-t $Lang::tr{'mbmon volt'} $Lang::tr{'graph per'} $Lang::tr{$period}"); | |
645 | ||
646 | foreach(@sensorsgraphs){ | |
647 | chomp($_); | |
648 | if ( $_ =~ /voltage/ ) { | |
649 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
650 | my $label = $2.$3;$label=~ s/-//g; | |
651 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
652 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
653 | } | |
654 | } | |
655 | 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"); | |
656 | foreach(@sensorsgraphs){ | |
657 | chomp($_); | |
658 | if ( $_ =~ /voltage/ ){ | |
659 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
660 | my $label = $2.$3;$label=~ s/-//g; | |
661 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
662 | 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",); | |
663 | } | |
664 | } | |
665 | RRDs::graph (@command); | |
666 | $ERROR = RRDs::error; | |
667 | print "$ERROR"; | |
668 | } | |
669 | ||
670 | # Generate the Load Graph for the current period of time for values given by collecd and lm_sensors | |
671 | ||
672 | sub updatehwfangraph { | |
673 | ||
674 | my $period = $_[0]; | |
675 | ||
676 | my @command = ("$graphs/sensors-hwfan-$period.png", | |
677 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
678 | "--alt-y-grid", "-w 600", "-h 125", | |
679 | "--color", "SHADEA".$color{"color19"},"--color", | |
680 | "SHADEB".$color{"color19"},"--color", | |
681 | "BACK".$color{"color21"}, | |
682 | "-t $Lang::tr{'mbmon fan'} $Lang::tr{'graph per'} $Lang::tr{$period}"); | |
683 | ||
684 | foreach(@sensorsgraphs){ | |
685 | chomp($_); | |
686 | if ( $_ =~ /fanspeed/ ) { | |
687 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
688 | my $label = $2.$3;$label=~ s/-//g; | |
689 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
690 | push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE"); | |
691 | } | |
692 | } | |
693 | 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"); | |
694 | foreach(@sensorsgraphs){ | |
695 | chomp($_); | |
696 | if ( $_ =~ /fanspeed/ ){ | |
697 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
698 | my $label = $2.$3;$label=~ s/-//g; | |
699 | if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;} | |
700 | 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",); | |
701 | } | |
702 | } | |
703 | RRDs::graph (@command); | |
704 | $ERROR = RRDs::error; | |
705 | print "$ERROR"; | |
706 | } | |
707 | ||
708 | sub updateprocessesgraph { | |
709 | ||
710 | my $period = $_[0]; | |
711 | my $count="0"; | |
712 | ||
713 | my @command = ("$graphs/processes-$period.png", | |
714 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
715 | "--alt-y-grid", "-w 600", "-h 125", | |
716 | "--color", "SHADEA".$color{"color19"},"--color", | |
717 | "SHADEB".$color{"color19"},"--color", | |
718 | "BACK".$color{"color21"}, | |
719 | "-t $Lang::tr{'processes'} $Lang::tr{'graph per'} $Lang::tr{$period}"); | |
720 | ||
721 | foreach(@processesgraph){ | |
722 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
723 | push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE"); | |
724 | push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE"); | |
725 | push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");} | |
726 | ||
727 | push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j"); | |
728 | ||
729 | foreach(@processesgraph){ | |
730 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
731 | if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);} | |
732 | else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);} | |
733 | $count++;} | |
734 | ||
735 | RRDs::graph (@command); | |
736 | $ERROR = RRDs::error; | |
737 | print "$ERROR"; | |
738 | ||
739 | my $count="0"; | |
740 | ||
741 | my @command = ("$graphs/processesmem-$period.png", | |
742 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
743 | "--alt-y-grid", "-w 600", "-h 125", | |
744 | "--color", "SHADEA".$color{"color19"},"--color", | |
745 | "SHADEB".$color{"color19"},"--color", | |
746 | "BACK".$color{"color21"}, | |
747 | "-t $Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph per'} $Lang::tr{$period}"); | |
748 | ||
749 | foreach(@processesgraph){ | |
750 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
751 | push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");} | |
752 | push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j"); | |
753 | ||
754 | foreach(@processesgraph){ | |
755 | chomp($_);my @name=split(/\-/,$_);chop($name[1]); | |
756 | if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);} | |
757 | else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);} | |
758 | $count++;} | |
759 | ||
760 | RRDs::graph (@command); | |
761 | $ERROR = RRDs::error; | |
762 | print "$ERROR"; | |
763 | } | |
764 | ||
dd8bfcf5 CS |
765 | sub wireless { |
766 | my $period = $_[0]; | |
767 | my $interface = $_[1]; | |
768 | RRDs::graph ("$graphs/wireless-$interface-$period.png", | |
769 | "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", | |
a962a923 | 770 | "--alt-y-grid", "-w 600", "-h 125", "-v dBm", "-z", |
dd8bfcf5 CS |
771 | "-t Wireless $interface $Lang::tr{'graph per'} $Lang::tr{$period}", |
772 | "--color", "SHADEA".$color{"color19"}, | |
773 | "--color", "SHADEB".$color{"color19"}, | |
774 | "--color", "BACK".$color{"color21"}, | |
775 | "DEF:noise=$rrdlog/collectd/localhost/wireless-$interface/signal_noise.rrd:value:AVERAGE", | |
776 | "DEF:power=$rrdlog/collectd/localhost/wireless-$interface/signal_power.rrd:value:AVERAGE", | |
777 | "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}), | |
778 | "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}), | |
779 | "COMMENT:".sprintf("%15s",$Lang::tr{'average'}), | |
780 | "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}), | |
781 | "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j", | |
782 | "LINE1:noise".$color{"color11"}."A0:".sprintf("%-20s","Signal Noise Ratio"), | |
783 | "GPRINT:noise:MAX:%5.1lf %sdBm", | |
784 | "GPRINT:noise:AVERAGE:%5.1lf %sdBm", | |
785 | "GPRINT:noise:MIN:%5.1lf %sdBm", | |
786 | "GPRINT:noise:LAST:%5.1lf %sdBm\\j", | |
787 | "LINE1:power".$color{"color12"}."A0:".sprintf("%-20s","Signal Power Ratio"), | |
788 | "GPRINT:power:MAX:%5.1lf %sdBm", | |
789 | "GPRINT:power:AVERAGE:%5.1lf %sdBm", | |
790 | "GPRINT:power:MIN:%5.1lf %sdBm", | |
791 | "GPRINT:power:LAST:%5.1lf %sdBm\\j", | |
792 | ); | |
793 | $ERROR = RRDs::error; | |
794 | print "Error in RRD::graph for Wireless: $ERROR\n" if $ERROR; | |
795 | } | |
796 | ||
3961e831 AF |
797 | # Generate a random color, used by Qos Graph to be independent from the amount of values |
798 | ||
799 | sub random_hex_color { | |
800 | my $size = shift; | |
801 | $size = 6 if $size !~ /^3|6$/; | |
802 | my @hex = ( 0 .. 9, 'a' .. 'f' ); | |
803 | my @color; | |
804 | push @color, @hex[rand(@hex)] for 1 .. $size; | |
805 | return join('', '#', @color); | |
806 | } |