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