]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/graphs.pl
83de8439306fc1d90cfb5eba20c13d0754558e15
[people/pmueller/ipfire-2.x.git] / config / cfgroot / graphs.pl
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
181 # Generate the Load Graph for the current period of time for values given by collecd
182
183 sub updateloadgraph {
184 my $period = $_[0];
185
186 RRDs::graph ("$graphs/load-$period.png",
187 "--start", "-1$period", "-aPNG",
188 "-w 600", "-h 125", "-i", "-z", "-W www.ipfire.org", "-l 0", "-r", "--alt-y-grid",
189 "-t Load Average $Lang::tr{'graph per'} $Lang::tr{$period}", "-v $Lang::tr{'processes'}",
190 "--color", "SHADEA".$color{"color19"},
191 "--color", "SHADEB".$color{"color19"},
192 "--color", "BACK".$color{"color21"},
193 "DEF:load1=$rrdlog/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
194 "DEF:load5=$rrdlog/collectd/localhost/load/load.rrd:midterm:AVERAGE",
195 "DEF:load15=$rrdlog/collectd/localhost/load/load.rrd:longterm:AVERAGE",
196 "AREA:load1".$color{"color13"}."A0:1 Minute:",
197 "GPRINT:load1:LAST:%5.2lf",
198 "AREA:load5".$color{"color18"}."A0:5 Minuten:",
199 "GPRINT:load5:LAST:%5.2lf",
200 "AREA:load15".$color{"color14"}."A0:15 Minuten:",
201 "GPRINT:load15:LAST:%5.2lf\\j",
202 "LINE1:load5".$color{"color13"},
203 "LINE1:load1".$color{"color18"});
204 $ERROR = RRDs::error;
205 print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
206 }
207
208 # Generate the Memory and Swap Graph for the current period of time for values given by collecd
209
210 sub updatememgraph {
211 my $period = $_[0];
212
213 RRDs::graph ("$graphs/memory-$period.png",
214 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
215 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
216 "--color", "SHADEA".$color{"color19"},
217 "--color", "SHADEB".$color{"color19"},
218 "--color", "BACK".$color{"color21"},
219 "-t $Lang::tr{'memory usage per'} $Lang::tr{$period}",
220 "DEF:used=$rrdlog/collectd/localhost/memory/memory-used.rrd:value:AVERAGE",
221 "DEF:free=$rrdlog/collectd/localhost/memory/memory-free.rrd:value:AVERAGE",
222 "DEF:buffer=$rrdlog/collectd/localhost/memory/memory-buffered.rrd:value:AVERAGE",
223 "DEF:cache=$rrdlog/collectd/localhost/memory/memory-cached.rrd:value:AVERAGE",
224 "CDEF:total=used,free,cache,buffer,+,+,+",
225 "CDEF:usedpct=used,total,/,100,*",
226 "CDEF:bufferpct=buffer,total,/,100,*",
227 "CDEF:cachepct=cache,total,/,100,*",
228 "CDEF:freepct=free,total,/,100,*",
229 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
230 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
231 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
232 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
233 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
234 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used memory'}),
235 "GPRINT:usedpct:MAX:%3.2lf%%",
236 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
237 "GPRINT:usedpct:MIN:%3.2lf%%",
238 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
239 "STACK:bufferpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'buffered memory'}),
240 "GPRINT:bufferpct:MAX:%3.2lf%%",
241 "GPRINT:bufferpct:AVERAGE:%3.2lf%%",
242 "GPRINT:bufferpct:MIN:%3.2lf%%",
243 "GPRINT:bufferpct:LAST:%3.2lf%%\\j",
244 "STACK:cachepct".$color{"color14"}."A0:".sprintf("%-25s",$Lang::tr{'cached memory'}),
245 "GPRINT:cachepct:MAX:%3.2lf%%",
246 "GPRINT:cachepct:AVERAGE:%3.2lf%%",
247 "GPRINT:cachepct:MIN:%3.2lf%%",
248 "GPRINT:cachepct:LAST:%3.2lf%%\\j",
249 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free memory'}),
250 "GPRINT:freepct:MAX:%3.2lf%%",
251 "GPRINT:freepct:AVERAGE:%3.2lf%%",
252 "GPRINT:freepct:MIN:%3.2lf%%",
253 "GPRINT:freepct:LAST:%3.2lf%%\\j");
254 $ERROR = RRDs::error;
255 print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
256
257 RRDs::graph ("$graphs/swap-$period.png",
258 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
259 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
260 "--color", "SHADEA".$color{"color19"},
261 "--color", "SHADEB".$color{"color19"},
262 "--color", "BACK".$color{"color21"},
263 "-t $Lang::tr{'swap usage per'} $Lang::tr{$period}",
264 "DEF:used=$rrdlog/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
265 "DEF:free=$rrdlog/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
266 "DEF:cached=$rrdlog/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
267 "CDEF:total=used,free,cached,+,+",
268 "CDEF:usedpct=100,used,total,/,*",
269 "CDEF:freepct=100,free,total,/,*",
270 "CDEF:cachedpct=100,cached,total,/,*",
271 "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
272 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
273 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
274 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
275 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
276 "AREA:usedpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'used swap'}),
277 "GPRINT:usedpct:MAX:%3.2lf%%",
278 "GPRINT:usedpct:AVERAGE:%3.2lf%%",
279 "GPRINT:usedpct:MIN:%3.2lf%%",
280 "GPRINT:usedpct:LAST:%3.2lf%%\\j",
281 "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
282 "GPRINT:freepct:MAX:%3.2lf%%",
283 "GPRINT:freepct:AVERAGE:%3.2lf%%",
284 "GPRINT:freepct:MIN:%3.2lf%%",
285 "GPRINT:freepct:LAST:%3.2lf%%\\j",
286 "STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}),
287 "GPRINT:cachedpct:MAX:%3.2lf%%",
288 "GPRINT:cachedpct:AVERAGE:%3.2lf%%",
289 "GPRINT:cachedpct:MIN:%3.2lf%%",
290 "GPRINT:cachedpct:LAST:%3.2lf%%\\j");
291 $ERROR = RRDs::error;
292 print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
293 }
294
295 # Generate the Disk Graph for the current period of time for values given by collecd
296
297 sub updatediskgraph {
298 my $period = $_[0];
299 my $disk = $_[1];
300
301 RRDs::graph ("$graphs/disk-$disk-$period.png",
302 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
303 "--alt-y-grid", "-w 600", "-h 125", "-r", "-z",
304 "--color", "SHADEA".$color{"color19"},
305 "--color", "SHADEB".$color{"color19"},
306 "--color", "BACK".$color{"color21"},
307 "-t $disk $Lang::tr{'disk access per'} $Lang::tr{$period}",
308 "DEF:read=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:read:AVERAGE",
309 "DEF:write=$rrdlog/collectd/localhost/disk-$disk/disk_octets.rrd:write:AVERAGE",
310 "CDEF:writen=write,-1,*",
311 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
312 "CDEF:st=standby,INF,*",
313 "CDEF:st1=standby,-INF,*",
314 "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}),
315 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
316 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
317 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
318 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
319 "AREA:st".$color{"color20"}."A0:",
320 "AREA:st1".$color{"color20"}."A0:standby\\j",
321 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
322 "GPRINT:read:MAX:%8.1lf %sBps",
323 "GPRINT:read:AVERAGE:%8.1lf %sBps",
324 "GPRINT:read:MIN:%8.1lf %sBps",
325 "GPRINT:read:LAST:%8.1lf %sBps\\j",
326 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
327 "GPRINT:write:MAX:%8.1lf %sBps",
328 "GPRINT:write:AVERAGE:%8.1lf %sBps",
329 "GPRINT:write:MIN:%8.1lf %sBps",
330 "GPRINT:write:LAST:%8.1lf %sBps\\j");
331 $ERROR = RRDs::error;
332 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
333 }
334
335 # Generate the Interface Graph for the current period of time for values given by collecd
336
337 sub updateifgraph {
338 my $interface = $_[0];
339 my $period = $_[1];
340
341 RRDs::graph ("$graphs/$interface-$period.png",
342 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
343 "--alt-y-grid", "-w 600", "-h 125", "-z", "-r",
344 "--color", "SHADEA".$color{"color19"},
345 "--color", "SHADEB".$color{"color19"},
346 "--color", "BACK".$color{"color21"},
347 "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
348 "-v$Lang::tr{'bytes per second'}",
349 "DEF:incoming=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:rx:AVERAGE",
350 "DEF:outgoing=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:tx:AVERAGE",
351 "CDEF:outgoingn=outgoing,-1,*",
352 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
353 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
354 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
355 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
356 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
357 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
358 "GPRINT:incoming:MAX:%8.1lf %sBps",
359 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
360 "GPRINT:incoming:MIN:%8.1lf %sBps",
361 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
362 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
363 "GPRINT:outgoing:MAX:%8.1lf %sBps",
364 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
365 "GPRINT:outgoing:MIN:%8.1lf %sBps",
366 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j");
367 $ERROR = RRDs::error;
368 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
369 }
370
371 # Generate the Firewall Graph for the current period of time for values given by collecd
372
373 sub updatefwhitsgraph {
374 my $period = $_[0];
375 RRDs::graph ("$graphs/fwhits-$period.png",
376 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
377 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
378 "--color", "SHADEA".$color{"color19"},
379 "--color", "SHADEB".$color{"color19"},
380 "--color", "BACK".$color{"color21"},
381 "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}",
382 "DEF:output=$rrdlog/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
383 "DEF:input=$rrdlog/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
384 "DEF:newnotsyn=$rrdlog/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
385 "DEF:portscan=$rrdlog/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
386 "CDEF:amount=output,input,newnotsyn,+,+",
387 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
388 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
389 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
390 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
391 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
392 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr{'firewallhits'}),
393 "GPRINT:amount:MAX:%8.1lf %sBps",
394 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
395 "GPRINT:amount:MIN:%8.1lf %sBps",
396 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
397 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr{'portscans'}),
398 "GPRINT:portscan:MAX:%8.1lf %sBps",
399 "GPRINT:portscan:MIN:%8.1lf %sBps",
400 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
401 "GPRINT:portscan:LAST:%8.1lf %sBps\\j");
402 $ERROR = RRDs::error;
403 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
404 }
405
406 # Generate the Line Quality Graph for the current period of time for values given by collecd
407
408 sub updatepinggraph {
409 my $period = $_[0];
410 my $host = $_[1];
411 RRDs::graph ("$graphs/$host-$period.png",
412 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
413 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-r", "-v ms",
414 "-t $Lang::tr{'linkq'} $host $Lang::tr{'graph per'} $Lang::tr{$period}",
415 "--color", "SHADEA".$color{"color19"},
416 "--color", "SHADEB".$color{"color19"},
417 "--color", "BACK".$color{"color21"},
418 "DEF:roundtrip=$rrdlog/collectd/localhost/ping/ping-$host.rrd:ping:AVERAGE",
419 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
420 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
421 "CDEF:r0=roundtrip,30,MIN",
422 "CDEF:r1=roundtrip,70,MIN",
423 "CDEF:r2=roundtrip,150,MIN",
424 "CDEF:r3=roundtrip,300,MIN",
425 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
426 "AREA:r3".$color{"color18"}."A0:150-300 ms",
427 "AREA:r2".$color{"color14"}."A0:70-150 ms",
428 "AREA:r1".$color{"color17"}."A0:30-70 ms",
429 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
430 "COMMENT:$Lang::tr{'maximal'}",
431 "COMMENT:$Lang::tr{'average'}",
432 "COMMENT:$Lang::tr{'minimal'}","COMMENT:$Lang::tr{'current'}\\j",
433 "LINE1:roundtrip#707070:",
434 "GPRINT:roundtrip:MAX:%3.2lf ms",
435 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
436 "GPRINT:roundtrip:MIN:%3.2lf ms",
437 "GPRINT:roundtrip:LAST:%3.2lf ms\\j");
438 $ERROR = RRDs::error;
439 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
440 }
441
442 # Generate the Hdd Graph for the current period of time for values given by collecd
443
444 sub updatehddgraph {
445
446 my $disk = $_[0];
447 my $period = $_[1];
448
449 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
450 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
451 "--alt-y-grid", "-w 600", "-h 125",
452 "--color", "SHADEA".$color{"color19"},
453 "--color", "SHADEB".$color{"color19"},
454 "--color", "BACK".$color{"color21"},
455 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
456 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
457 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
458 "CDEF:st=standby,INF,*",
459 "AREA:st".$color{"color20"}."A0:standby",
460 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
461 "COMMENT:$Lang::tr{'maximal'}",
462 "COMMENT:$Lang::tr{'average'}",
463 "COMMENT:$Lang::tr{'minimal'}",
464 "COMMENT:$Lang::tr{'current'}\\j",
465 "GPRINT:temperature:MAX:%3.0lf Grad C",
466 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
467 "GPRINT:temperature:MIN:%3.0lf Grad C",
468 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
469 );
470 $ERROR = RRDs::error;
471 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
472 }
473
474 # Generate the QoS Graph for the current period of time
475
476 sub overviewgraph {
477
478 my $period = $_[0];
479 my $periodstring;
480 my $description;
481 my %qossettings = ();
482 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
483 my $classentry = "";
484 my @classes = ();
485 my @classline = ();
486 my $classfile = "/var/ipfire/qos/classes";
487
488 $qossettings{'DEV'} = $_[1];
489 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
490 $qossettings{'CLASSPRFX'} = '1';
491 } else {
492 $qossettings{'CLASSPRFX'} = '2';
493 }
494
495 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
496 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'})";}
497
498 my $ERROR="";
499 my $count="1";
500 my $color="#000000";
501 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
502 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
503 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
504 "--color", "SHADEA".$color{"color19"},
505 "--color", "SHADEB".$color{"color19"},
506 "--color", "BACK".$color{"color21"},
507 "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}),
508 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
509 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
510 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
511 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
512 $description
513 );
514 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
515 @classes = <FILE>;
516 close FILE;
517 foreach $classentry (sort @classes)
518 {
519 @classline = split( /\;/, $classentry );
520 if ( $classline[0] eq $qossettings{'DEV'} )
521 {
522 $color=random_hex_color(6);
523 push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
524
525 if ($count eq "1") {
526 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
527 } else {
528 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
529
530 }
531 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps");
532 push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps");
533 push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps");
534 push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
535 $count++;
536 }
537 }
538 RRDs::graph (@command);
539 $ERROR = RRDs::error;
540 print "$ERROR";
541 }
542
543 # Generate the Temperature Graph for the current period of time for values given by collecd and lm_sensors
544
545 sub updatehwtempgraph {
546
547 my $period = $_[0];
548
549 my @command = ("$graphs/sensors-hwtemp-$period.png",
550 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
551 "--alt-y-grid", "-w 600", "-h 125",
552 "--color", "SHADEA".$color{"color19"},"--color",
553 "SHADEB".$color{"color19"},"--color",
554 "BACK".$color{"color21"},
555 "-t $Lang::tr{'sensors temp'} $Lang::tr{'graph per'} $Lang::tr{$period}");
556
557 foreach(@sensorsgraphs){
558 chomp($_);
559 if ( $_ =~ /temperature/ ) {
560 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
561 my $label = $2.$3;$label=~ s/-//g;
562 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
563 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
564 }
565 }
566 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");
567 foreach(@sensorsgraphs){
568 chomp($_);
569 if ( $_ =~ /temperature/ ){
570 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
571 my $label = $2.$3;$label=~ s/-//g;
572 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
573 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",);
574 }
575 }
576 RRDs::graph (@command);
577 $ERROR = RRDs::error;
578 print "$ERROR";
579 }
580
581 # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
582
583 sub updatehwvoltgraph {
584
585 my $period = $_[0];
586
587 my @command = ("$graphs/sensors-hwvolt-$period.png",
588 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
589 "--alt-y-grid", "-w 600", "-h 125",
590 "--color", "SHADEA".$color{"color19"},"--color",
591 "SHADEB".$color{"color19"},"--color",
592 "BACK".$color{"color21"},
593 "-t $Lang::tr{'mbmon volt'} $Lang::tr{'graph per'} $Lang::tr{$period}");
594
595 foreach(@sensorsgraphs){
596 chomp($_);
597 if ( $_ =~ /voltage/ ) {
598 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
599 my $label = $2.$3;$label=~ s/-//g;
600 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
601 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
602 }
603 }
604 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");
605 foreach(@sensorsgraphs){
606 chomp($_);
607 if ( $_ =~ /voltage/ ){
608 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
609 my $label = $2.$3;$label=~ s/-//g;
610 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
611 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",);
612 }
613 }
614 RRDs::graph (@command);
615 $ERROR = RRDs::error;
616 print "$ERROR";
617 }
618
619 # Generate the Load Graph for the current period of time for values given by collecd and lm_sensors
620
621 sub updatehwfangraph {
622
623 my $period = $_[0];
624
625 my @command = ("$graphs/sensors-hwfan-$period.png",
626 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
627 "--alt-y-grid", "-w 600", "-h 125",
628 "--color", "SHADEA".$color{"color19"},"--color",
629 "SHADEB".$color{"color19"},"--color",
630 "BACK".$color{"color21"},
631 "-t $Lang::tr{'mbmon fan'} $Lang::tr{'graph per'} $Lang::tr{$period}");
632
633 foreach(@sensorsgraphs){
634 chomp($_);
635 if ( $_ =~ /fanspeed/ ) {
636 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
637 my $label = $2.$3;$label=~ s/-//g;
638 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
639 push(@command,"DEF:".$sensorsettings{'LABEL-'.$label}."=".$_.":value:AVERAGE");
640 }
641 }
642 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");
643 foreach(@sensorsgraphs){
644 chomp($_);
645 if ( $_ =~ /fanspeed/ ){
646 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
647 my $label = $2.$3;$label=~ s/-//g;
648 if ( $sensorsettings{'LINE-'.$label} eq "off" ){next;}
649 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",);
650 }
651 }
652 RRDs::graph (@command);
653 $ERROR = RRDs::error;
654 print "$ERROR";
655 }
656
657 sub updateprocessesgraph {
658
659 my $period = $_[0];
660 my $count="0";
661
662 my @command = ("$graphs/processes-$period.png",
663 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
664 "--alt-y-grid", "-w 600", "-h 125",
665 "--color", "SHADEA".$color{"color19"},"--color",
666 "SHADEB".$color{"color19"},"--color",
667 "BACK".$color{"color21"},
668 "-t $Lang::tr{'processes'} $Lang::tr{'graph per'} $Lang::tr{$period}");
669
670 foreach(@processesgraph){
671 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
672 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
673 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
674 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");}
675
676 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
677
678 foreach(@processesgraph){
679 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
680 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
681 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
682 $count++;}
683
684 RRDs::graph (@command);
685 $ERROR = RRDs::error;
686 print "$ERROR";
687
688 my $count="0";
689
690 my @command = ("$graphs/processesmem-$period.png",
691 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
692 "--alt-y-grid", "-w 600", "-h 125",
693 "--color", "SHADEA".$color{"color19"},"--color",
694 "SHADEB".$color{"color19"},"--color",
695 "BACK".$color{"color21"},
696 "-t $Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph per'} $Lang::tr{$period}");
697
698 foreach(@processesgraph){
699 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
700 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");}
701 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
702
703 foreach(@processesgraph){
704 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
705 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
706 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
707 $count++;}
708
709 RRDs::graph (@command);
710 $ERROR = RRDs::error;
711 print "$ERROR";
712 }
713
714 # Generate a random color, used by Qos Graph to be independent from the amount of values
715
716 sub random_hex_color {
717 my $size = shift;
718 $size = 6 if $size !~ /^3|6$/;
719 my @hex = ( 0 .. 9, 'a' .. 'f' );
720 my @color;
721 push @color, @hex[rand(@hex)] for 1 .. $size;
722 return join('', '#', @color);
723 }