Ended core 5 and started core 6
[people/pmueller/ipfire-2.x.git] / config / cfgroot / graphs.pl
CommitLineData
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
6package Graphs;
7
8use strict;
9use RRDs;
10
11require '/var/ipfire/general-functions.pl';
12require "${General::swroot}/lang.pl";
13require "${General::swroot}/header.pl";
14
350b52c5
CS
15my $ERROR;
16my $rrdlog = "/var/log/rrd";
17my $graphs = "/srv/web/ipfire/html/graphs";
18$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
19
20my %color = ();
21my %mainsettings = ();
22&General::readhash("${General::swroot}/main/settings", \%mainsettings);
23&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
24
25my %mbmon_settings = ();
26&General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
27
28my %mbmon_values = ();
7d01d525 29if ( -e "/var/log/mbmon-values" ){
cce90b0b 30&General::readhash("/var/log/mbmon-values", \%mbmon_values);
7d01d525 31}
cce90b0b 32
350b52c5
CS
33my $key;
34my $value;
35my @args = ();
36my $count = 0;
37
38use Encode 'from_to';
39
40my %tr=();
b4af7142 41if ((${Lang::language} eq 'el') ||
350b52c5
CS
42 (${Lang::language} eq 'fa') ||
43 (${Lang::language} eq 'ru') ||
b4af7142 44 (${Lang::language} eq 'th') ||
350b52c5
CS
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
54sub 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
109sub 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",
af95dec5 115 "-t Load Average $Lang::tr{'graph per'} $Lang::tr{$period}",
60412147
CS
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
134sub 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
220sub 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"},
af95dec5 230 "-t $disk $Lang::tr{'disk access per'} $Lang::tr{$period}",
60412147
CS
231 "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
232 "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
471a46f7
CS
233 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
234 "CDEF:st=standby,INF,*",
b4af7142 235 "AREA:st".$color{"color20"}.":standby\\j",
0edf2f61
CS
236 "AREA:read".$color{"color11"}.":$Lang::tr{'sectors read from disk per second'}",
237 "STACK:write".$color{"color12"}.":$Lang::tr{'sectors written to disk per second'}\\j",
60412147 238 "COMMENT: \\j",
0edf2f61
CS
239 "COMMENT:$Lang::tr{'maximal'}",
240 "COMMENT:$Lang::tr{'average'}",
241 "COMMENT:$Lang::tr{'current'}\\j",
242 "GPRINT:read:MAX:$Lang::tr{'read sectors'}\\:%8.0lf",
d39a5cb6 243 "GPRINT:read:AVERAGE:$Lang::tr{'read sectors'}\\:%8.0lf",
0edf2f61
CS
244 "GPRINT:read:LAST:$Lang::tr{'read sectors'}\\:%8.0lf\\j",
245 "GPRINT:write:MAX:$Lang::tr{'written sectors'}\\:%8.0lf",
246 "GPRINT:write:AVERAGE:$Lang::tr{'written sectors'}\\:%8.0lf",
247 "GPRINT:write:LAST:$Lang::tr{'written sectors'}\\:%8.0lf\\j");
60412147
CS
248 $ERROR = RRDs::error;
249 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
350b52c5
CS
250}
251
252sub updateifgraph {
253 my $interface = $_[0];
254 my $period = $_[1];
255
256 RRDs::graph ("$graphs/$interface-$period.png",
fbfdb241 257 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5
CS
258 "--alt-y-grid", "-w 600", "-h 100",
259 "--color", "SHADEA".$color{"color19"},
260 "--color", "SHADEB".$color{"color19"},
261 "--color", "BACK".$color{"color21"},
af95dec5 262 "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
0edf2f61 263 "-v$Lang::tr{'bytes per second'}",
350b52c5
CS
264 "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
265 "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
0edf2f61
CS
266 "AREA:incoming".$color{"color11"}.":$Lang::tr{'incoming traffic in bytes per second'}",
267 "AREA:outgoing".$color{"color12"}.":$Lang::tr{'outgoing traffic in bytes per second'}\\j",
350b52c5 268 "COMMENT: \\j",
0edf2f61
CS
269 "COMMENT:$Lang::tr{'maximal'}",
270 "COMMENT:$Lang::tr{'average'}",
271 "COMMENT:$Lang::tr{'minimal'}",
272 "COMMENT:$Lang::tr{'current'}\\j",
273 "GPRINT:incoming:MAX:$Lang::tr{'in'}\\:%8.3lf %sBps",
274 "GPRINT:incoming:AVERAGE:$Lang::tr{'in'}\\:%8.3lf %sBps",
275 "GPRINT:incoming:MIN:$Lang::tr{'in'}\\:%8.3lf %sBps",
276 "GPRINT:incoming:LAST:$Lang::tr{'in'}\\:%8.3lf %sBps\\j",
277 "GPRINT:outgoing:MAX:$Lang::tr{'out'}\\:%8.3lf %sBps",
7c4cc0d8 278 "GPRINT:outgoing:AVERAGE:$Lang::tr{'out'}\\:%8.3lf %sBps",
0edf2f61
CS
279 "GPRINT:outgoing:MIN:$Lang::tr{'out'}\\:%8.3lf %sBps",
280 "GPRINT:outgoing:LAST:$Lang::tr{'out'}\\:%8.3lf %sBps\\j");
350b52c5
CS
281 $ERROR = RRDs::error;
282 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
283}
284
285sub updatefwhitsgraph {
3c5695fe 286 my $period = $_[0];
350b52c5 287
3c5695fe 288 RRDs::graph ("$graphs/firewallhits-$period-area.png",
fbfdb241 289 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
3c5695fe 290 "--alt-y-grid", "-w 600", "-h 100",
350b52c5
CS
291 "--color", "SHADEA".$color{"color19"},
292 "--color", "SHADEB".$color{"color19"},
293 "--color", "BACK".$color{"color21"},
0edf2f61 294 "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}",
350b52c5 295 "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
350b52c5 296 "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
0edf2f61
CS
297 "COMMENT:$Lang::tr{'caption'}\\t\\t\\t",
298 "COMMENT:$Lang::tr{'maximal'}",
299 "COMMENT:$Lang::tr{'average'}",
300 "COMMENT:$Lang::tr{'minimal'}",
301 "COMMENT:$Lang::tr{'current'}\\j",
302 "AREA:amount".$color{"color24"}.":$Lang::tr{'firewallhits'}/5 min",
249dda69
CS
303 "GPRINT:amount:MAX:%2.2lf %S",
304 "GPRINT:amount:AVERAGE:%2.2lf %S",
305 "GPRINT:amount:MIN:%2.2lf %S",
306 "GPRINT:amount:LAST:%2.2lf %S\\j",
0edf2f61 307 "STACK:portamount".$color{"color25"}.":$Lang::tr{'portscans'}/5 min",
249dda69
CS
308 "GPRINT:portamount:MAX:%2.2lf %S",
309 "GPRINT:portamount:MIN:%2.2lf %S",
310 "GPRINT:portamount:AVERAGE:%2.2lf %S",
311 "GPRINT:portamount:LAST:%2.2lf %S\\j");
350b52c5
CS
312 $ERROR = RRDs::error;
313 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
314}
315
316sub updatelqgraph {
317 my $period = $_[0];
318 RRDs::graph ("$graphs/lq-$period.png",
fbfdb241 319 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5 320 "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
af95dec5 321 "-t $Lang::tr{'linkq'} $Lang::tr{'graph per'} $Lang::tr{$period}",
b4af7142 322 "--lazy",
350b52c5
CS
323 "--color", "SHADEA".$color{"color19"},
324 "--color", "SHADEB".$color{"color19"},
325 "--color", "BACK".$color{"color21"},
326 "-v ms / pkts (% x10)",
327 "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
328 "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
329 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
330 "CDEF:loss10=loss,10,*",
331 "CDEF:r0=roundtrip,30,MIN",
332 "CDEF:r1=roundtrip,70,MIN",
333 "CDEF:r2=roundtrip,150,MIN",
334 "CDEF:r3=roundtrip,300,MIN",
335 "AREA:roundtrip".$color{"color25"}.":>300 ms",
336 "AREA:r3".$color{"color18"}.":150-300 ms",
337 "AREA:r2".$color{"color14"}.":70-150 ms",
338 "AREA:r1".$color{"color17"}.":30-70 ms",
339 "AREA:r0".$color{"color12"}.":<30 ms",
340 "AREA:loss10".$color{"color13"}.":Packet loss (x10)\\j",
341 "COMMENT: \\j",
0edf2f61
CS
342 "COMMENT:$Lang::tr{'maximal'}",
343 "COMMENT:$Lang::tr{'average'}",
344 "COMMENT:$Lang::tr{'minimal'}",
345 "COMMENT:$Lang::tr{'current'}\\j",
350b52c5
CS
346 "LINE1:roundtrip#707070:",
347 "GPRINT:roundtrip:MAX:Time\\:%3.2lf ms",
348 "GPRINT:roundtrip:AVERAGE:Time\\:%3.2lf ms",
249dda69 349 "GPRINT:roundtrip:MIN:Time\\:%3.2lf ms",
350b52c5
CS
350 "GPRINT:roundtrip:LAST:Time\\:%3.2lf ms\\j",
351 "GPRINT:loss:MAX:Loss\\:%3.2lf%%",
352 "GPRINT:loss:AVERAGE:Loss\\:%3.2lf%%",
249dda69 353 "GPRINT:loss:MIN:Loss\\:%3.2lf%%",
350b52c5
CS
354 "GPRINT:loss:LAST:Loss\\:%3.2lf%%\\j"
355 );
356 $ERROR = RRDs::error;
357 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
358}
359
360sub updatehddgraph {
cce90b0b 361
350b52c5
CS
362 my $disk = $_[0];
363 my $period = $_[1];
364
365 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
fbfdb241 366 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5
CS
367 "--alt-y-grid", "-w 600", "-h 100",
368 "--color", "SHADEA".$color{"color19"},
369 "--color", "SHADEB".$color{"color19"},
370 "--color", "BACK".$color{"color21"},
af95dec5 371 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
350b52c5 372 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
471a46f7
CS
373 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
374 "CDEF:st=standby,INF,*",
b4af7142 375 "AREA:st".$color{"color20"}.":standby",
0edf2f61
CS
376 "LINE2:temperature".$color{"color11"}.":$Lang::tr{'hdd temperature in'} C\\j",
377 "COMMENT:$Lang::tr{'maximal'}",
378 "COMMENT:$Lang::tr{'average'}",
379 "COMMENT:$Lang::tr{'minimal'}",
380 "COMMENT:$Lang::tr{'current'}\\j",
a28fdc01
CS
381 "GPRINT:temperature:MAX:%3.0lf Grad C",
382 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
383 "GPRINT:temperature:MIN:%3.0lf Grad C",
384 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
350b52c5 385 );
b4af7142 386 $ERROR = RRDs::error;
350b52c5
CS
387 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
388}
389
390sub updatetempgraph
391{
392 my $type = "temp";
393 my $period = $_[0];
dced81b2 394 my $count = "11";
b4af7142 395
cce90b0b 396 @args = ("$graphs/mbmon-$type-$period.png",
fbfdb241 397 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5
CS
398 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
399 "--color", "SHADEA".$color{"color19"},
400 "--color", "SHADEB".$color{"color19"},
401 "--color", "BACK".$color{"color21"},
0edf2f61
CS
402 "-t $Lang::tr{'mbmon temp'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
403 "COMMENT:$Lang::tr{'caption'}\\t\\t",
404 "COMMENT:$Lang::tr{'maximal'}",
405 "COMMENT:$Lang::tr{'average'}",
406 "COMMENT:$Lang::tr{'minimal'}",
407 "COMMENT:$Lang::tr{'current'}\\j",);
b4af7142
CS
408
409 foreach $key ( sort(keys %mbmon_values) )
350b52c5
CS
410 {
411 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
412 {
413 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
414 {
415 $mbmon_settings{'LABEL-'.$key} = $key;
416 }
cce90b0b 417 push (@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
249dda69
CS
418 push (@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Grad C");
419 push (@args, "GPRINT:$key:MAX:%3.1lf");
420 push (@args, "GPRINT:$key:AVERAGE:%3.1lf");
421 push (@args, "GPRINT:$key:MIN:%3.1lf");
422 push (@args, "GPRINT:$key:LAST:%3.1lf\\j");
dced81b2 423 $count++;
cce90b0b 424 }
350b52c5 425 }
b4af7142
CS
426
427 RRDs::graph ( @args );
350b52c5
CS
428 $ERROR = RRDs::error;
429 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
350b52c5
CS
430}
431
432sub updatefangraph
433{
434 my $type = "fan";
435 my $period = $_[0];
dced81b2 436 my $count = "11";
350b52c5 437
fbfdb241 438 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5
CS
439 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
440 "--color", "SHADEA".$color{"color19"},
441 "--color", "SHADEB".$color{"color19"},
442 "--color", "BACK".$color{"color21"},
0edf2f61
CS
443 "-t $Lang::tr{'mbmon fan'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
444 "COMMENT:$Lang::tr{'caption'}\\t\\t",
445 "COMMENT:$Lang::tr{'maximal'}",
446 "COMMENT:$Lang::tr{'average'}",
447 "COMMENT:$Lang::tr{'minimal'}",
448 "COMMENT:$Lang::tr{'current'}\\j",);
350b52c5 449
b4af7142 450 foreach $key ( sort(keys %mbmon_values) )
350b52c5
CS
451 {
452 if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
453 {
454 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
455 {
456 $mbmon_settings{'LABEL-'.$key} = $key;
457 }
458
459 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
249dda69
CS
460 push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} rpm");
461 push(@args, "GPRINT:$key:MAX:%5.0lf");
462 push(@args, "GPRINT:$key:AVERAGE:%5.0lf");
463 push(@args, "GPRINT:$key:MIN:%5.0lf");
464 push(@args, "GPRINT:$key:LAST:%5.0lf\\j");
dced81b2 465 $count++;
350b52c5
CS
466 }
467 }
350b52c5
CS
468 RRDs::graph ( @args );
469 $ERROR = RRDs::error;
470 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
350b52c5
CS
471}
472
473sub updatevoltgraph
474{
475 my $type = "volt";
476 my $period = $_[0];
dced81b2 477 my $count = "11";
350b52c5 478
fbfdb241 479 @args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
350b52c5
CS
480 "--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
481 "--color", "SHADEA".$color{"color19"},
482 "--color", "SHADEB".$color{"color19"},
483 "--color", "BACK".$color{"color21"},
0edf2f61
CS
484 "-t $Lang::tr{'mbmon volt'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
485 "COMMENT:$Lang::tr{'caption'}\\t",
486 "COMMENT:$Lang::tr{'maximal'}",
487 "COMMENT:$Lang::tr{'average'}",
488 "COMMENT:$Lang::tr{'minimal'}",
489 "COMMENT:$Lang::tr{'current'}\\j",);
350b52c5 490
b4af7142 491 foreach $key ( sort(keys %mbmon_values) )
350b52c5
CS
492 {
493 my $v = substr($key,0,1);
494 if ( ($v eq 'v') && ($mbmon_settings{'LINE-'.$key} eq 'on') )
495 {
496 if ( !defined($mbmon_settings{'LABEL-'.$key}) || ($mbmon_settings{'LABEL-'.$key} eq '') )
497 {
498 $mbmon_settings{'LABEL-'.$key} = $key;
499 }
500
501 push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
249dda69
CS
502 push(@args, "LINE2:".$key.$color{"color$count"}.":$mbmon_settings{'LABEL-'.$key} Volt");
503 push(@args, "GPRINT:$key:MAX:%3.2lf");
504 push(@args, "GPRINT:$key:AVERAGE:%3.2lf");
505 push(@args, "GPRINT:$key:MIN:%3.2lf");
506 push(@args, "GPRINT:$key:LAST:%3.2lf\\j");
dced81b2 507 $count++;
350b52c5
CS
508 }
509 }
510
350b52c5
CS
511 RRDs::graph ( @args );
512 $ERROR = RRDs::error;
513 print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
350b52c5 514}
0b1641db
CS
515
516sub overviewgraph {
517
518 my $period = $_[0];
519 my $periodstring;
520 my $description;
521 my %qossettings = ();
522 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
523 my $classentry = "";
524 my @classes = ();
525 my @classline = ();
526 my $classfile = "/var/ipfire/qos/classes";
b4af7142 527
0b1641db 528 $qossettings{'DEV'} = $_[1];
b4af7142 529 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
0b1641db 530 $qossettings{'CLASSPRFX'} = '1';
b4af7142 531 } else {
0b1641db
CS
532 $qossettings{'CLASSPRFX'} = '2';
533 }
b4af7142 534
0b1641db
CS
535 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
536 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'})";}
b4af7142 537
0b1641db
CS
538 my $ERROR="";
539 my $count="1";
540 my $color="#000000";
541 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
fbfdb241 542 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
0b1641db
CS
543 "--alt-y-grid", "-w 600", "-h 150", "-r",
544 "--color", "SHADEA".$color{"color19"},
545 "--color", "SHADEB".$color{"color19"},
546 "--color", "BACK".$color{"color21"},
359179f3
CS
547 "COMMENT:$Lang::tr{'caption'}\\t\\t\\t\\t ",
548 "COMMENT:$Lang::tr{'maximal'}",
549 "COMMENT:$Lang::tr{'average'}",
550 "COMMENT:$Lang::tr{'minimal'}",
551 "COMMENT:$Lang::tr{'current'}\\j",
0b1641db
CS
552 $description
553 );
554 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
555 @classes = <FILE>;
556 close FILE;
557 foreach $classentry (sort @classes)
558 {
559 @classline = split( /\;/, $classentry );
560 if ( $classline[0] eq $qossettings{'DEV'} )
561 {
562 $color=random_hex_color(6);
fbfdb241 563 push(@command, "DEF:$classline[1]=/var/log/rrd/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
0b1641db
CS
564
565 if ($count eq "1") {
359179f3 566 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
0b1641db 567 } else {
359179f3
CS
568 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
569
0b1641db 570 }
359179f3
CS
571 push(@command, "GPRINT:$classline[1]:MAX:%5.2lf");
572 push(@command, "GPRINT:$classline[1]:AVERAGE:%5.2lf");
573 push(@command, "GPRINT:$classline[1]:MIN:%5.2lf");
574 push(@command, "GPRINT:$classline[1]:LAST:%5.2lf\\j");
0b1641db
CS
575 $count++;
576 }
577 }
578 RRDs::graph (@command);
579 $ERROR = RRDs::error;
580 print "$ERROR";
581}
582
583sub random_hex_color {
584 my $size = shift;
585 $size = 6 if $size !~ /^3|6$/;
586 my @hex = ( 0 .. 9, 'a' .. 'f' );
587 my @color;
588 push @color, @hex[rand(@hex)] for 1 .. $size;
589 return join('', '#', @color);
590}