]>
Commit | Line | Data |
---|---|---|
0b1641db | 1 | #!/usr/bin/perl |
350b52c5 | 2 | # Generate Graphs exported from Makegraphs to minimize system load an only generate the Graphs when displayed |
0edf2f61 | 3 | # This is part of the IPFire Firewall |
350b52c5 | 4 | |
0b1641db | 5 | |
350b52c5 CS |
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 | ||
350b52c5 CS |
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 | my %color = (); | |
21 | my %mainsettings = (); | |
22 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
23 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
24 | ||
25 | my %mbmon_settings = (); | |
26 | &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings); | |
27 | ||
28 | my %mbmon_values = (); | |
7d01d525 | 29 | if ( -e "/var/log/mbmon-values" ){ |
cce90b0b | 30 | &General::readhash("/var/log/mbmon-values", \%mbmon_values); |
7d01d525 | 31 | } |
cce90b0b | 32 | |
350b52c5 CS |
33 | my $key; |
34 | my $value; | |
35 | my @args = (); | |
36 | my $count = 0; | |
37 | ||
38 | use Encode 'from_to'; | |
39 | ||
40 | my %tr=(); | |
41 | if ((${Lang::language} eq 'el') || | |
42 | (${Lang::language} eq 'fa') || | |
43 | (${Lang::language} eq 'ru') || | |
44 | (${Lang::language} eq 'th') || | |
45 | (${Lang::language} eq 'vi') || | |
46 | (${Lang::language} eq 'zh') || | |
47 | (${Lang::language} eq 'zt')) { | |
48 | eval `/bin/cat "${General::swroot}/langs/en.pl"`; | |
49 | } else { | |
50 | %tr=%Lang::tr; # use translated version for other languages | |
51 | } | |
52 | ||
53 | ||
54 | sub updatecpugraph { | |
60412147 CS |
55 | my $period = $_[0]; |
56 | ||
57 | RRDs::graph ("$graphs/cpu-$period.png", | |
fbfdb241 | 58 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
60412147 CS |
59 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", |
60 | "--color", "SHADEA".$color{"color19"}, | |
61 | "--color", "SHADEB".$color{"color19"}, | |
62 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 63 | "-t $Lang::tr{'cpu usage per'} $Lang::tr{$period}", |
60412147 CS |
64 | "DEF:iowait=$rrdlog/cpu.rrd:iowait:AVERAGE", |
65 | "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE", | |
66 | "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE", | |
67 | "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE", | |
68 | "DEF:irq=$rrdlog/cpu.rrd:irq:AVERAGE", | |
69 | "CDEF:total=user,system,idle,iowait,irq,+,+,+,+", | |
70 | "CDEF:userpct=100,user,total,/,*", | |
71 | "CDEF:systempct=100,system,total,/,*", | |
72 | "CDEF:idlepct=100,idle,total,/,*", | |
73 | "CDEF:iowaitpct=100,iowait,total,/,*", | |
74 | "CDEF:irqpct=100,irq,total,/,*", | |
0edf2f61 CS |
75 | "COMMENT:$Lang::tr{'caption'}\\t\\t\\t ", |
76 | "COMMENT:$Lang::tr{'maximal'}", | |
77 | "COMMENT:$Lang::tr{'average'}", | |
78 | "COMMENT:$Lang::tr{'minimal'}", | |
79 | "COMMENT:$Lang::tr{'current'}\\j", | |
80 | "AREA:iowaitpct".$color{"color14"}.":$Lang::tr{'iowait'}", | |
249dda69 CS |
81 | "GPRINT:iowaitpct:MAX:%3.2lf%%", |
82 | "GPRINT:iowaitpct:AVERAGE:%3.2lf%%", | |
83 | "GPRINT:iowaitpct:MIN:%3.2lf%%", | |
84 | "GPRINT:iowaitpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 85 | "STACK:irqpct".$color{"color23"}.":$Lang::tr{'cpu irq usage'}", |
249dda69 CS |
86 | "GPRINT:irqpct:MAX:%3.2lf%%", |
87 | "GPRINT:irqpct:AVERAGE:%3.2lf%%", | |
88 | "GPRINT:irqpct:MIN:%3.2lf%%", | |
89 | "GPRINT:irqpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 90 | "STACK:userpct".$color{"color11"}.":$Lang::tr{'user cpu usage'}", |
249dda69 CS |
91 | "GPRINT:userpct:MAX:%3.2lf%%", |
92 | "GPRINT:userpct:AVERAGE:%3.2lf%%", | |
93 | "GPRINT:userpct:MIN:%3.2lf%%", | |
94 | "GPRINT:userpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 95 | "STACK:systempct".$color{"color13"}.":$Lang::tr{'system cpu usage'}", |
249dda69 CS |
96 | "GPRINT:systempct:MAX:%3.2lf%%", |
97 | "GPRINT:systempct:AVERAGE:%3.2lf%%", | |
98 | "GPRINT:systempct:MIN:%3.2lf%%", | |
99 | "GPRINT:systempct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 100 | "STACK:idlepct".$color{"color12"}.":$Lang::tr{'idle cpu usage'}", |
249dda69 CS |
101 | "GPRINT:idlepct:MAX:%3.2lf%%", |
102 | "GPRINT:idlepct:AVERAGE:%3.2lf%%", | |
103 | "GPRINT:idlepct:MIN:%3.2lf%%", | |
104 | "GPRINT:idlepct:LAST:%3.2lf%%\\j"); | |
60412147 CS |
105 | $ERROR = RRDs::error; |
106 | print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR; | |
350b52c5 CS |
107 | } |
108 | ||
109 | sub updateloadgraph { | |
60412147 CS |
110 | my $period = $_[0]; |
111 | ||
112 | RRDs::graph ("$graphs/load-$period.png", | |
113 | "--start", "-1$period", "-aPNG", | |
fbfdb241 | 114 | "-w 600", "-h 100", "-i", "-z", "-W www.ipfire.org", "-l 0", "-r", "--alt-y-grid", |
60412147 CS |
115 | "-t Load Average", |
116 | "--color", "SHADEA".$color{"color19"}, | |
117 | "--color", "SHADEB".$color{"color19"}, | |
118 | "--color", "BACK".$color{"color21"}, | |
119 | "DEF:load1=$rrdlog/load.rrd:load1:AVERAGE", | |
120 | "DEF:load5=$rrdlog/load.rrd:load5:AVERAGE", | |
121 | "DEF:load15=$rrdlog/load.rrd:load15:AVERAGE", | |
122 | "AREA:load1".$color{"color13"}.":1 Minute, letzter:", | |
123 | "GPRINT:load1:LAST:%5.2lf", | |
124 | "AREA:load5".$color{"color18"}.":5 Minuten, letzter:", | |
125 | "GPRINT:load5:LAST:%5.2lf", | |
126 | "AREA:load15".$color{"color14"}.":15 Minuten, letzter:", | |
127 | "GPRINT:load15:LAST:%5.2lf\\j", | |
128 | "LINE1:load5".$color{"color13"}, | |
129 | "LINE1:load1".$color{"color18"}); | |
130 | $ERROR = RRDs::error; | |
131 | print "Error in RRD::graph for load: $ERROR\n" if $ERROR; | |
350b52c5 CS |
132 | } |
133 | ||
134 | sub updatememgraph { | |
60412147 CS |
135 | my $period = $_[0]; |
136 | ||
137 | RRDs::graph ("$graphs/memory-$period.png", | |
fbfdb241 | 138 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
60412147 CS |
139 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", |
140 | "--color", "SHADEA".$color{"color19"}, | |
141 | "--color", "SHADEB".$color{"color19"}, | |
142 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 143 | "-t $Lang::tr{'memory usage per'} $Lang::tr{$period}", |
60412147 CS |
144 | "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE", |
145 | "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE", | |
146 | "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE", | |
147 | "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE", | |
148 | "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE", | |
149 | "CDEF:total=used,free,+", | |
150 | "CDEF:used2=used,buffer,cache,shared,+,+,-", | |
151 | "CDEF:usedpct=100,used2,total,/,*", | |
152 | "CDEF:sharedpct=100,shared,total,/,*", | |
153 | "CDEF:bufferpct=100,buffer,total,/,*", | |
154 | "CDEF:cachepct=100,cache,total,/,*", | |
155 | "CDEF:freepct=100,free,total,/,*", | |
0edf2f61 CS |
156 | "COMMENT:$Lang::tr{'caption'}\\t\\t\\t", |
157 | "COMMENT:$Lang::tr{'maximal'}", | |
158 | "COMMENT:$Lang::tr{'average'}", | |
159 | "COMMENT:$Lang::tr{'minimal'}", | |
160 | "COMMENT:$Lang::tr{'current'}\\j", | |
161 | "AREA:usedpct".$color{"color11"}.":$Lang::tr{'used memory'}", | |
249dda69 CS |
162 | "GPRINT:usedpct:MAX:%3.2lf%%", |
163 | "GPRINT:usedpct:AVERAGE:%3.2lf%%", | |
164 | "GPRINT:usedpct:MIN:%3.2lf%%", | |
165 | "GPRINT:usedpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 166 | "STACK:sharedpct".$color{"color13"}.":$Lang::tr{'shared memory'}", |
249dda69 CS |
167 | "GPRINT:sharedpct:MAX:%3.2lf%%", |
168 | "GPRINT:sharedpct:AVERAGE:%3.2lf%%", | |
169 | "GPRINT:sharedpct:MIN:%3.2lf%%", | |
170 | "GPRINT:sharedpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 171 | "STACK:bufferpct".$color{"color23"}.":$Lang::tr{'buffered memory'}", |
249dda69 CS |
172 | "GPRINT:bufferpct:MAX:%3.2lf%%", |
173 | "GPRINT:bufferpct:AVERAGE:%3.2lf%%", | |
174 | "GPRINT:bufferpct:MIN:%3.2lf%%", | |
175 | "GPRINT:bufferpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 176 | "STACK:cachepct".$color{"color14"}.":$Lang::tr{'cached memory'}", |
249dda69 CS |
177 | "GPRINT:cachepct:MAX:%3.2lf%%", |
178 | "GPRINT:cachepct:AVERAGE:%3.2lf%%", | |
179 | "GPRINT:cachepct:MIN:%3.2lf%%", | |
180 | "GPRINT:cachepct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 181 | "STACK:freepct".$color{"color12"}.":$Lang::tr{'free memory'}", |
249dda69 CS |
182 | "GPRINT:freepct:MAX:%3.2lf%%", |
183 | "GPRINT:freepct:AVERAGE:%3.2lf%%", | |
184 | "GPRINT:freepct:MIN:%3.2lf%%", | |
185 | "GPRINT:freepct:LAST:%3.2lf%%\\j"); | |
60412147 CS |
186 | $ERROR = RRDs::error; |
187 | print "Error in RRD::graph for mem: $ERROR\n" if $ERROR; | |
188 | ||
189 | RRDs::graph ("$graphs/swap-$period.png", | |
fbfdb241 | 190 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
60412147 CS |
191 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r", |
192 | "--color", "SHADEA".$color{"color19"}, | |
193 | "--color", "SHADEB".$color{"color19"}, | |
194 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 195 | "-t $Lang::tr{'swap usage per'} $Lang::tr{$period}", |
60412147 CS |
196 | "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE", |
197 | "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE", | |
198 | "CDEF:total=used,free,+", | |
199 | "CDEF:usedpct=100,used,total,/,*", | |
200 | "CDEF:freepct=100,free,total,/,*", | |
0edf2f61 CS |
201 | "COMMENT:$Lang::tr{'caption'}\\t\\t", |
202 | "COMMENT:$Lang::tr{'maximal'}", | |
203 | "COMMENT:$Lang::tr{'average'}", | |
204 | "COMMENT:$Lang::tr{'minimal'}", | |
205 | "COMMENT:$Lang::tr{'current'}\\j", | |
206 | "AREA:usedpct".$color{"color11"}.":$Lang::tr{'used swap'}", | |
249dda69 CS |
207 | "GPRINT:usedpct:MAX:%3.2lf%%", |
208 | "GPRINT:usedpct:AVERAGE:%3.2lf%%", | |
209 | "GPRINT:usedpct:MIN:%3.2lf%%", | |
210 | "GPRINT:usedpct:LAST:%3.2lf%%\\j", | |
0edf2f61 | 211 | "STACK:freepct".$color{"color12"}.":$Lang::tr{'free swap'}", |
249dda69 CS |
212 | "GPRINT:freepct:MAX:%3.2lf%%", |
213 | "GPRINT:freepct:AVERAGE:%3.2lf%%", | |
214 | "GPRINT:freepct:MIN:%3.2lf%%", | |
215 | "GPRINT:freepct:LAST:%3.2lf%%\\j"); | |
60412147 CS |
216 | $ERROR = RRDs::error; |
217 | print "Error in RRD::graph for swap: $ERROR\n" if $ERROR; | |
350b52c5 CS |
218 | } |
219 | ||
220 | sub updatediskgraph { | |
60412147 CS |
221 | my $period = $_[0]; |
222 | my $disk = $_[1]; | |
223 | ||
224 | RRDs::graph ("$graphs/disk-$disk-$period.png", | |
fbfdb241 | 225 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
60412147 CS |
226 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r", |
227 | "--color", "SHADEA".$color{"color19"}, | |
228 | "--color", "SHADEB".$color{"color19"}, | |
229 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 230 | "-t $Lang::tr{'disk access per'} $Lang::tr{$period} $disk", |
60412147 CS |
231 | "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE", |
232 | "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE", | |
0edf2f61 CS |
233 | "AREA:read".$color{"color11"}.":$Lang::tr{'sectors read from disk per second'}", |
234 | "STACK:write".$color{"color12"}.":$Lang::tr{'sectors written to disk per second'}\\j", | |
60412147 | 235 | "COMMENT: \\j", |
0edf2f61 CS |
236 | "COMMENT:$Lang::tr{'maximal'}", |
237 | "COMMENT:$Lang::tr{'average'}", | |
238 | "COMMENT:$Lang::tr{'current'}\\j", | |
239 | "GPRINT:read:MAX:$Lang::tr{'read sectors'}\\:%8.0lf", | |
d39a5cb6 | 240 | "GPRINT:read:AVERAGE:$Lang::tr{'read sectors'}\\:%8.0lf", |
0edf2f61 CS |
241 | "GPRINT:read:LAST:$Lang::tr{'read sectors'}\\:%8.0lf\\j", |
242 | "GPRINT:write:MAX:$Lang::tr{'written sectors'}\\:%8.0lf", | |
243 | "GPRINT:write:AVERAGE:$Lang::tr{'written sectors'}\\:%8.0lf", | |
244 | "GPRINT:write:LAST:$Lang::tr{'written sectors'}\\:%8.0lf\\j"); | |
60412147 CS |
245 | $ERROR = RRDs::error; |
246 | print "Error in RRD::graph for disk: $ERROR\n" if $ERROR; | |
350b52c5 CS |
247 | } |
248 | ||
249 | sub updateifgraph { | |
250 | my $interface = $_[0]; | |
251 | my $period = $_[1]; | |
252 | ||
253 | RRDs::graph ("$graphs/$interface-$period.png", | |
fbfdb241 | 254 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 CS |
255 | "--alt-y-grid", "-w 600", "-h 100", |
256 | "--color", "SHADEA".$color{"color19"}, | |
257 | "--color", "SHADEB".$color{"color19"}, | |
258 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 CS |
259 | "-t $Lang::tr{'traffic on'} $interface ($Lang::tr{'graph per'} $Lang::tr{$period})", |
260 | "-v$Lang::tr{'bytes per second'}", | |
350b52c5 CS |
261 | "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE", |
262 | "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE", | |
0edf2f61 CS |
263 | "AREA:incoming".$color{"color11"}.":$Lang::tr{'incoming traffic in bytes per second'}", |
264 | "AREA:outgoing".$color{"color12"}.":$Lang::tr{'outgoing traffic in bytes per second'}\\j", | |
350b52c5 | 265 | "COMMENT: \\j", |
0edf2f61 CS |
266 | "COMMENT:$Lang::tr{'maximal'}", |
267 | "COMMENT:$Lang::tr{'average'}", | |
268 | "COMMENT:$Lang::tr{'minimal'}", | |
269 | "COMMENT:$Lang::tr{'current'}\\j", | |
270 | "GPRINT:incoming:MAX:$Lang::tr{'in'}\\:%8.3lf %sBps", | |
271 | "GPRINT:incoming:AVERAGE:$Lang::tr{'in'}\\:%8.3lf %sBps", | |
272 | "GPRINT:incoming:MIN:$Lang::tr{'in'}\\:%8.3lf %sBps", | |
273 | "GPRINT:incoming:LAST:$Lang::tr{'in'}\\:%8.3lf %sBps\\j", | |
274 | "GPRINT:outgoing:MAX:$Lang::tr{'out'}\\:%8.3lf %sBps", | |
7c4cc0d8 | 275 | "GPRINT:outgoing:AVERAGE:$Lang::tr{'out'}\\:%8.3lf %sBps", |
0edf2f61 CS |
276 | "GPRINT:outgoing:MIN:$Lang::tr{'out'}\\:%8.3lf %sBps", |
277 | "GPRINT:outgoing:LAST:$Lang::tr{'out'}\\:%8.3lf %sBps\\j"); | |
350b52c5 CS |
278 | $ERROR = RRDs::error; |
279 | print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR; | |
280 | } | |
281 | ||
282 | sub updatefwhitsgraph { | |
3c5695fe | 283 | my $period = $_[0]; |
350b52c5 | 284 | |
3c5695fe | 285 | RRDs::graph ("$graphs/firewallhits-$period-area.png", |
fbfdb241 | 286 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
3c5695fe | 287 | "--alt-y-grid", "-w 600", "-h 100", |
350b52c5 CS |
288 | "--color", "SHADEA".$color{"color19"}, |
289 | "--color", "SHADEB".$color{"color19"}, | |
290 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 291 | "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}", |
350b52c5 | 292 | "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE", |
350b52c5 | 293 | "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE", |
0edf2f61 CS |
294 | "COMMENT:$Lang::tr{'caption'}\\t\\t\\t", |
295 | "COMMENT:$Lang::tr{'maximal'}", | |
296 | "COMMENT:$Lang::tr{'average'}", | |
297 | "COMMENT:$Lang::tr{'minimal'}", | |
298 | "COMMENT:$Lang::tr{'current'}\\j", | |
299 | "AREA:amount".$color{"color24"}.":$Lang::tr{'firewallhits'}/5 min", | |
249dda69 CS |
300 | "GPRINT:amount:MAX:%2.2lf %S", |
301 | "GPRINT:amount:AVERAGE:%2.2lf %S", | |
302 | "GPRINT:amount:MIN:%2.2lf %S", | |
303 | "GPRINT:amount:LAST:%2.2lf %S\\j", | |
0edf2f61 | 304 | "STACK:portamount".$color{"color25"}.":$Lang::tr{'portscans'}/5 min", |
249dda69 CS |
305 | "GPRINT:portamount:MAX:%2.2lf %S", |
306 | "GPRINT:portamount:MIN:%2.2lf %S", | |
307 | "GPRINT:portamount:AVERAGE:%2.2lf %S", | |
308 | "GPRINT:portamount:LAST:%2.2lf %S\\j"); | |
350b52c5 CS |
309 | $ERROR = RRDs::error; |
310 | print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR; | |
311 | } | |
312 | ||
313 | sub updatelqgraph { | |
314 | my $period = $_[0]; | |
315 | RRDs::graph ("$graphs/lq-$period.png", | |
fbfdb241 | 316 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 | 317 | "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r", |
0edf2f61 | 318 | "-t $Lang::tr{'linkq'} ($Lang::tr{'graph per'} $Lang::tr{$period})", |
350b52c5 CS |
319 | "--lazy", |
320 | "--color", "SHADEA".$color{"color19"}, | |
321 | "--color", "SHADEB".$color{"color19"}, | |
322 | "--color", "BACK".$color{"color21"}, | |
323 | "-v ms / pkts (% x10)", | |
324 | "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE", | |
325 | "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE", | |
326 | "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/", | |
327 | "CDEF:loss10=loss,10,*", | |
328 | "CDEF:r0=roundtrip,30,MIN", | |
329 | "CDEF:r1=roundtrip,70,MIN", | |
330 | "CDEF:r2=roundtrip,150,MIN", | |
331 | "CDEF:r3=roundtrip,300,MIN", | |
332 | "AREA:roundtrip".$color{"color25"}.":>300 ms", | |
333 | "AREA:r3".$color{"color18"}.":150-300 ms", | |
334 | "AREA:r2".$color{"color14"}.":70-150 ms", | |
335 | "AREA:r1".$color{"color17"}.":30-70 ms", | |
336 | "AREA:r0".$color{"color12"}.":<30 ms", | |
337 | "AREA:loss10".$color{"color13"}.":Packet loss (x10)\\j", | |
338 | "COMMENT: \\j", | |
0edf2f61 CS |
339 | "COMMENT:$Lang::tr{'maximal'}", |
340 | "COMMENT:$Lang::tr{'average'}", | |
341 | "COMMENT:$Lang::tr{'minimal'}", | |
342 | "COMMENT:$Lang::tr{'current'}\\j", | |
350b52c5 CS |
343 | "LINE1:roundtrip#707070:", |
344 | "GPRINT:roundtrip:MAX:Time\\:%3.2lf ms", | |
345 | "GPRINT:roundtrip:AVERAGE:Time\\:%3.2lf ms", | |
249dda69 | 346 | "GPRINT:roundtrip:MIN:Time\\:%3.2lf ms", |
350b52c5 CS |
347 | "GPRINT:roundtrip:LAST:Time\\:%3.2lf ms\\j", |
348 | "GPRINT:loss:MAX:Loss\\:%3.2lf%%", | |
349 | "GPRINT:loss:AVERAGE:Loss\\:%3.2lf%%", | |
249dda69 | 350 | "GPRINT:loss:MIN:Loss\\:%3.2lf%%", |
350b52c5 CS |
351 | "GPRINT:loss:LAST:Loss\\:%3.2lf%%\\j" |
352 | ); | |
353 | $ERROR = RRDs::error; | |
354 | print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR; | |
355 | } | |
356 | ||
357 | sub updatehddgraph { | |
cce90b0b | 358 | |
350b52c5 CS |
359 | my $disk = $_[0]; |
360 | my $period = $_[1]; | |
361 | ||
362 | RRDs::graph ("$graphs/hddtemp-$disk-$period.png", | |
fbfdb241 | 363 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 CS |
364 | "--alt-y-grid", "-w 600", "-h 100", |
365 | "--color", "SHADEA".$color{"color19"}, | |
366 | "--color", "SHADEB".$color{"color19"}, | |
367 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 | 368 | "-t $Lang::tr{'harddisk temperature'} ($Lang::tr{'graph per'} $Lang::tr{$period})", |
350b52c5 | 369 | "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE", |
0edf2f61 CS |
370 | "LINE2:temperature".$color{"color11"}.":$Lang::tr{'hdd temperature in'} C\\j", |
371 | "COMMENT:$Lang::tr{'maximal'}", | |
372 | "COMMENT:$Lang::tr{'average'}", | |
373 | "COMMENT:$Lang::tr{'minimal'}", | |
374 | "COMMENT:$Lang::tr{'current'}\\j", | |
a28fdc01 CS |
375 | "GPRINT:temperature:MAX:%3.0lf Grad C", |
376 | "GPRINT:temperature:AVERAGE:%3.0lf Grad C", | |
377 | "GPRINT:temperature:MIN:%3.0lf Grad C", | |
378 | "GPRINT:temperature:LAST:%3.0lf Grad C\\j", | |
350b52c5 | 379 | ); |
249dda69 | 380 | $ERROR = RRDs::error; |
350b52c5 CS |
381 | print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR; |
382 | } | |
383 | ||
384 | sub updatetempgraph | |
385 | { | |
386 | my $type = "temp"; | |
387 | my $period = $_[0]; | |
dced81b2 | 388 | my $count = "11"; |
cce90b0b CS |
389 | |
390 | @args = ("$graphs/mbmon-$type-$period.png", | |
fbfdb241 | 391 | "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 CS |
392 | "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale", |
393 | "--color", "SHADEA".$color{"color19"}, | |
394 | "--color", "SHADEB".$color{"color19"}, | |
395 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 CS |
396 | "-t $Lang::tr{'mbmon temp'} ($Lang::tr{'graph per'} $Lang::tr{$period})", |
397 | "COMMENT:$Lang::tr{'caption'}\\t\\t", | |
398 | "COMMENT:$Lang::tr{'maximal'}", | |
399 | "COMMENT:$Lang::tr{'average'}", | |
400 | "COMMENT:$Lang::tr{'minimal'}", | |
401 | "COMMENT:$Lang::tr{'current'}\\j",); | |
cce90b0b | 402 | |
350b52c5 CS |
403 | foreach $key ( sort(keys %mbmon_values) ) |
404 | { | |
405 | if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') ) | |
406 | { | |
407 | if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') ) | |
408 | { | |
409 | $mbmon_settings{'LABEL-'.$key} = $key; | |
410 | } | |
cce90b0b | 411 | push (@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE"); |
249dda69 CS |
412 | push (@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Grad C"); |
413 | push (@args, "GPRINT:$key:MAX:%3.1lf"); | |
414 | push (@args, "GPRINT:$key:AVERAGE:%3.1lf"); | |
415 | push (@args, "GPRINT:$key:MIN:%3.1lf"); | |
416 | push (@args, "GPRINT:$key:LAST:%3.1lf\\j"); | |
dced81b2 | 417 | $count++; |
cce90b0b | 418 | } |
350b52c5 | 419 | } |
249dda69 | 420 | |
cce90b0b | 421 | RRDs::graph ( @args ); |
350b52c5 CS |
422 | $ERROR = RRDs::error; |
423 | print("Error in RRD::graph for temp: $ERROR\n")if $ERROR; | |
350b52c5 CS |
424 | } |
425 | ||
426 | sub updatefangraph | |
427 | { | |
428 | my $type = "fan"; | |
429 | my $period = $_[0]; | |
dced81b2 | 430 | my $count = "11"; |
350b52c5 | 431 | |
fbfdb241 | 432 | @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 CS |
433 | "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale", |
434 | "--color", "SHADEA".$color{"color19"}, | |
435 | "--color", "SHADEB".$color{"color19"}, | |
436 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 CS |
437 | "-t $Lang::tr{'mbmon fan'} ($Lang::tr{'graph per'} $Lang::tr{$period})", |
438 | "COMMENT:$Lang::tr{'caption'}\\t\\t", | |
439 | "COMMENT:$Lang::tr{'maximal'}", | |
440 | "COMMENT:$Lang::tr{'average'}", | |
441 | "COMMENT:$Lang::tr{'minimal'}", | |
442 | "COMMENT:$Lang::tr{'current'}\\j",); | |
350b52c5 | 443 | |
350b52c5 CS |
444 | foreach $key ( sort(keys %mbmon_values) ) |
445 | { | |
446 | if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') ) | |
447 | { | |
448 | if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') ) | |
449 | { | |
450 | $mbmon_settings{'LABEL-'.$key} = $key; | |
451 | } | |
452 | ||
453 | push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE"); | |
249dda69 CS |
454 | push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} rpm"); |
455 | push(@args, "GPRINT:$key:MAX:%5.0lf"); | |
456 | push(@args, "GPRINT:$key:AVERAGE:%5.0lf"); | |
457 | push(@args, "GPRINT:$key:MIN:%5.0lf"); | |
458 | push(@args, "GPRINT:$key:LAST:%5.0lf\\j"); | |
dced81b2 | 459 | $count++; |
350b52c5 CS |
460 | } |
461 | } | |
350b52c5 CS |
462 | RRDs::graph ( @args ); |
463 | $ERROR = RRDs::error; | |
464 | print("Error in RRD::graph for temp: $ERROR\n")if $ERROR; | |
350b52c5 CS |
465 | } |
466 | ||
467 | sub updatevoltgraph | |
468 | { | |
469 | my $type = "volt"; | |
470 | my $period = $_[0]; | |
dced81b2 | 471 | my $count = "11"; |
350b52c5 | 472 | |
fbfdb241 | 473 | @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", |
350b52c5 CS |
474 | "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale", |
475 | "--color", "SHADEA".$color{"color19"}, | |
476 | "--color", "SHADEB".$color{"color19"}, | |
477 | "--color", "BACK".$color{"color21"}, | |
0edf2f61 CS |
478 | "-t $Lang::tr{'mbmon volt'} ($Lang::tr{'graph per'} $Lang::tr{$period})", |
479 | "COMMENT:$Lang::tr{'caption'}\\t", | |
480 | "COMMENT:$Lang::tr{'maximal'}", | |
481 | "COMMENT:$Lang::tr{'average'}", | |
482 | "COMMENT:$Lang::tr{'minimal'}", | |
483 | "COMMENT:$Lang::tr{'current'}\\j",); | |
350b52c5 | 484 | |
350b52c5 CS |
485 | foreach $key ( sort(keys %mbmon_values) ) |
486 | { | |
487 | my $v = substr($key,0,1); | |
488 | if ( ($v eq 'v') && ($mbmon_settings{'LINE-'.$key} eq 'on') ) | |
489 | { | |
490 | if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') ) | |
491 | { | |
492 | $mbmon_settings{'LABEL-'.$key} = $key; | |
493 | } | |
494 | ||
495 | push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE"); | |
249dda69 CS |
496 | push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Volt"); |
497 | push(@args, "GPRINT:$key:MAX:%3.2lf"); | |
498 | push(@args, "GPRINT:$key:AVERAGE:%3.2lf"); | |
499 | push(@args, "GPRINT:$key:MIN:%3.2lf"); | |
500 | push(@args, "GPRINT:$key:LAST:%3.2lf\\j"); | |
dced81b2 | 501 | $count++; |
350b52c5 CS |
502 | } |
503 | } | |
504 | ||
350b52c5 CS |
505 | RRDs::graph ( @args ); |
506 | $ERROR = RRDs::error; | |
507 | print("Error in RRD::graph for temp: $ERROR\n")if $ERROR; | |
350b52c5 | 508 | } |
0b1641db CS |
509 | |
510 | sub overviewgraph { | |
511 | ||
512 | my $period = $_[0]; | |
513 | my $periodstring; | |
514 | my $description; | |
515 | my %qossettings = (); | |
516 | &General::readhash("${General::swroot}/qos/settings", \%qossettings); | |
517 | my $classentry = ""; | |
518 | my @classes = (); | |
519 | my @classline = (); | |
520 | my $classfile = "/var/ipfire/qos/classes"; | |
521 | ||
522 | $qossettings{'DEV'} = $_[1]; | |
523 | if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) { | |
524 | $qossettings{'CLASSPRFX'} = '1'; | |
525 | } else { | |
526 | $qossettings{'CLASSPRFX'} = '2'; | |
527 | } | |
528 | ||
529 | if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;} | |
530 | 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'})";} | |
531 | ||
532 | my $ERROR=""; | |
533 | my $count="1"; | |
534 | my $color="#000000"; | |
535 | my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png", | |
fbfdb241 | 536 | "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org", |
0b1641db CS |
537 | "--alt-y-grid", "-w 600", "-h 150", "-r", |
538 | "--color", "SHADEA".$color{"color19"}, | |
539 | "--color", "SHADEB".$color{"color19"}, | |
540 | "--color", "BACK".$color{"color21"}, | |
359179f3 CS |
541 | "COMMENT:$Lang::tr{'caption'}\\t\\t\\t\\t ", |
542 | "COMMENT:$Lang::tr{'maximal'}", | |
543 | "COMMENT:$Lang::tr{'average'}", | |
544 | "COMMENT:$Lang::tr{'minimal'}", | |
545 | "COMMENT:$Lang::tr{'current'}\\j", | |
0b1641db CS |
546 | $description |
547 | ); | |
548 | open( FILE, "< $classfile" ) or die "Unable to read $classfile"; | |
549 | @classes = <FILE>; | |
550 | close FILE; | |
551 | foreach $classentry (sort @classes) | |
552 | { | |
553 | @classline = split( /\;/, $classentry ); | |
554 | if ( $classline[0] eq $qossettings{'DEV'} ) | |
555 | { | |
556 | $color=random_hex_color(6); | |
fbfdb241 | 557 | push(@command, "DEF:$classline[1]=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE"); |
0b1641db CS |
558 | |
559 | if ($count eq "1") { | |
359179f3 | 560 | push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8])); |
0b1641db | 561 | } else { |
359179f3 CS |
562 | push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8])); |
563 | ||
0b1641db | 564 | } |
359179f3 CS |
565 | push(@command, "GPRINT:$classline[1]:MAX:%5.2lf"); |
566 | push(@command, "GPRINT:$classline[1]:AVERAGE:%5.2lf"); | |
567 | push(@command, "GPRINT:$classline[1]:MIN:%5.2lf"); | |
568 | push(@command, "GPRINT:$classline[1]:LAST:%5.2lf\\j"); | |
0b1641db CS |
569 | $count++; |
570 | } | |
571 | } | |
572 | RRDs::graph (@command); | |
573 | $ERROR = RRDs::error; | |
574 | print "$ERROR"; | |
575 | } | |
576 | ||
577 | sub random_hex_color { | |
578 | my $size = shift; | |
579 | $size = 6 if $size !~ /^3|6$/; | |
580 | my @hex = ( 0 .. 9, 'a' .. 'f' ); | |
581 | my @color; | |
582 | push @color, @hex[rand(@hex)] for 1 .. $size; | |
583 | return join('', '#', @color); | |
584 | } |