]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/graphs.pl
Added memory and cpu util graphs for services
[people/teissler/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 "COMMENT:".sprintf("%-25s",$Lang::tr{'caption'}),
310 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
311 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
312 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
313 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
314 "AREA:st".$color{"color20"}."A0:standby\\j",
315 "AREA:read".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'read bytes'}),
316 "GPRINT:read:MAX:%8.1lf %sBps",
317 "GPRINT:read:AVERAGE:%8.1lf %sBps",
318 "GPRINT:read:MIN:%8.1lf %sBps",
319 "GPRINT:read:LAST:%8.1lf %sBps\\j",
320 "AREA:writen".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'written bytes'}),
321 "GPRINT:write:MAX:%8.1lf %sBps",
322 "GPRINT:write:AVERAGE:%8.1lf %sBps",
323 "GPRINT:write:MIN:%8.1lf %sBps",
324 "GPRINT:write:LAST:%8.1lf %sBps\\j");
325 $ERROR = RRDs::error;
326 print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
327 }
328
329 # Generate the Interface Graph for the current period of time for values given by collecd
330
331 sub updateifgraph {
332 my $interface = $_[0];
333 my $period = $_[1];
334
335 RRDs::graph ("$graphs/$interface-$period.png",
336 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org", "-v $Lang::tr{'bytes per second'}",
337 "--alt-y-grid", "-w 600", "-h 125", "-z", "-r",
338 "--color", "SHADEA".$color{"color19"},
339 "--color", "SHADEB".$color{"color19"},
340 "--color", "BACK".$color{"color21"},
341 "-t $Lang::tr{'traffic on'} $interface $Lang::tr{'graph per'} $Lang::tr{$period}",
342 "-v$Lang::tr{'bytes per second'}",
343 "DEF:incoming=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:rx:AVERAGE",
344 "DEF:outgoing=$rrdlog/collectd/localhost/interface/if_octets-$interface.rrd:tx:AVERAGE",
345 "CDEF:outgoingn=outgoing,-1,*",
346 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
347 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
348 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
349 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
350 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
351 "AREA:incoming".$color{"color12"}."A0:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}),
352 "GPRINT:incoming:MAX:%8.1lf %sBps",
353 "GPRINT:incoming:AVERAGE:%8.1lf %sBps",
354 "GPRINT:incoming:MIN:%8.1lf %sBps",
355 "GPRINT:incoming:LAST:%8.1lf %sBps\\j",
356 "AREA:outgoingn".$color{"color13"}."A0:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}),
357 "GPRINT:outgoing:MAX:%8.1lf %sBps",
358 "GPRINT:outgoing:AVERAGE:%8.1lf %sBps",
359 "GPRINT:outgoing:MIN:%8.1lf %sBps",
360 "GPRINT:outgoing:LAST:%8.1lf %sBps\\j");
361 $ERROR = RRDs::error;
362 print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
363 }
364
365 # Generate the Firewall Graph for the current period of time for values given by collecd
366
367 sub updatefwhitsgraph {
368 my $period = $_[0];
369 RRDs::graph ("$graphs/fwhits-$period.png",
370 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
371 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
372 "--color", "SHADEA".$color{"color19"},
373 "--color", "SHADEB".$color{"color19"},
374 "--color", "BACK".$color{"color21"},
375 "-t $Lang::tr{'firewall hits per'} $Lang::tr{$period}",
376 "DEF:output=$rrdlog/collectd/localhost/iptables-filter-FORWARD/ipt_bytes-DROP_OUTPUT.rrd:value:AVERAGE",
377 "DEF:input=$rrdlog/collectd/localhost/iptables-filter-INPUT/ipt_bytes-DROP_INPUT.rrd:value:AVERAGE",
378 "DEF:newnotsyn=$rrdlog/collectd/localhost/iptables-filter-NEWNOTSYN/ipt_bytes-DROP_NEWNOTSYN.rrd:value:AVERAGE",
379 "DEF:portscan=$rrdlog/collectd/localhost/iptables-filter-PSCAN/ipt_bytes-DROP_PScan.rrd:value:AVERAGE",
380 "CDEF:amount=output,input,newnotsyn,+,+",
381 "COMMENT:".sprintf("%-20s",$Lang::tr{'caption'}),
382 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
383 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
384 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
385 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
386 "AREA:amount".$color{"color24"}."A0:".sprintf("%-20s",$Lang::tr{'firewallhits'}),
387 "GPRINT:amount:MAX:%8.1lf %sBps",
388 "GPRINT:amount:AVERAGE:%8.1lf %sBps",
389 "GPRINT:amount:MIN:%8.1lf %sBps",
390 "GPRINT:amount:LAST:%8.1lf %sBps\\j",
391 "STACK:portscan".$color{"color25"}."A0:".sprintf("%-20s",$Lang::tr{'portscans'}),
392 "GPRINT:portscan:MAX:%8.1lf %sBps",
393 "GPRINT:portscan:MIN:%8.1lf %sBps",
394 "GPRINT:portscan:AVERAGE:%8.1lf %sBps",
395 "GPRINT:portscan:LAST:%8.1lf %sBps\\j");
396 $ERROR = RRDs::error;
397 print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
398 }
399
400 # Generate the Line Quality Graph for the current period of time for values given by collecd
401
402 sub updatelqgraph {
403 my $period = $_[0];
404 RRDs::graph ("$graphs/lq-$period.png",
405 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
406 "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-r", "-v ms",
407 "-t $Lang::tr{'linkq'} $Lang::tr{'graph per'} $Lang::tr{$period}",
408 "--color", "SHADEA".$color{"color19"},
409 "--color", "SHADEB".$color{"color19"},
410 "--color", "BACK".$color{"color21"},
411 "DEF:roundtrip=$rrdlog/collectd/localhost/ping/ping-gateway.rrd:ping:AVERAGE",
412 "COMMENT:$Lang::".sprintf("%-20s",$Lang::tr{'caption'})."\\j",
413 "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
414 "CDEF:r0=roundtrip,30,MIN",
415 "CDEF:r1=roundtrip,70,MIN",
416 "CDEF:r2=roundtrip,150,MIN",
417 "CDEF:r3=roundtrip,300,MIN",
418 "AREA:roundtrip".$color{"color25"}."A0:>300 ms",
419 "AREA:r3".$color{"color18"}."A0:150-300 ms",
420 "AREA:r2".$color{"color14"}."A0:70-150 ms",
421 "AREA:r1".$color{"color17"}."A0:30-70 ms",
422 "AREA:r0".$color{"color12"}."A0:<30 ms\\j",
423 "COMMENT:".sprintf("%-15s",$Lang::tr{'maximal'}),
424 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
425 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
426 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
427 "LINE1:roundtrip#707070:",
428 "GPRINT:roundtrip:MAX:%3.2lf ms",
429 "GPRINT:roundtrip:AVERAGE:%3.2lf ms",
430 "GPRINT:roundtrip:MIN:%3.2lf ms",
431 "GPRINT:roundtrip:LAST:%3.2lf ms\\j");
432 $ERROR = RRDs::error;
433 print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
434 }
435
436 # Generate the Hdd Graph for the current period of time for values given by collecd
437
438 sub updatehddgraph {
439
440 my $disk = $_[0];
441 my $period = $_[1];
442
443 RRDs::graph ("$graphs/hddtemp-$disk-$period.png",
444 "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org",
445 "--alt-y-grid", "-w 600", "-h 125",
446 "--color", "SHADEA".$color{"color19"},
447 "--color", "SHADEB".$color{"color19"},
448 "--color", "BACK".$color{"color21"},
449 "-t $disk $Lang::tr{'harddisk temperature'} $Lang::tr{'graph per'} $Lang::tr{$period}",
450 "DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
451 "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
452 "CDEF:st=standby,INF,*",
453 "AREA:st".$color{"color20"}."A0:standby",
454 "LINE3:temperature".$color{"color11"}."A0:$Lang::tr{'hdd temperature in'} C\\j",
455 "COMMENT:$Lang::tr{'maximal'}",
456 "COMMENT:$Lang::tr{'average'}",
457 "COMMENT:$Lang::tr{'minimal'}",
458 "COMMENT:$Lang::tr{'current'}\\j",
459 "GPRINT:temperature:MAX:%3.0lf Grad C",
460 "GPRINT:temperature:AVERAGE:%3.0lf Grad C",
461 "GPRINT:temperature:MIN:%3.0lf Grad C",
462 "GPRINT:temperature:LAST:%3.0lf Grad C\\j",
463 );
464 $ERROR = RRDs::error;
465 print "Error in RRD::graph for hdd-$disk: $ERROR\n" if $ERROR;
466 }
467
468 # Generate the QoS Graph for the current period of time
469
470 sub overviewgraph {
471
472 my $period = $_[0];
473 my $periodstring;
474 my $description;
475 my %qossettings = ();
476 &General::readhash("${General::swroot}/qos/settings", \%qossettings);
477 my $classentry = "";
478 my @classes = ();
479 my @classline = ();
480 my $classfile = "/var/ipfire/qos/classes";
481
482 $qossettings{'DEV'} = $_[1];
483 if ( $qossettings{'DEV'} eq $qossettings{'RED_DEV'} ) {
484 $qossettings{'CLASSPRFX'} = '1';
485 } else {
486 $qossettings{'CLASSPRFX'} = '2';
487 }
488
489 if ( $period ne '3240' ){ $periodstring = "-1$period";}else{ $periodstring = "-".$period;}
490 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'})";}
491
492 my $ERROR="";
493 my $count="1";
494 my $color="#000000";
495 my @command=("/srv/web/ipfire/html/graphs/qos-graph-$qossettings{'DEV'}-$period.png",
496 "--start", $periodstring, "-aPNG", "-i", "-z", "-W www.ipfire.org",
497 "--alt-y-grid", "-w 600", "-h 125", "-r", "-v $Lang::tr{'bytes per second'}",
498 "--color", "SHADEA".$color{"color19"},
499 "--color", "SHADEB".$color{"color19"},
500 "--color", "BACK".$color{"color21"},
501 "COMMENT:".sprintf("%-28s",$Lang::tr{'caption'}),
502 "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
503 "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
504 "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
505 "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
506 $description
507 );
508 open( FILE, "< $classfile" ) or die "Unable to read $classfile";
509 @classes = <FILE>;
510 close FILE;
511 foreach $classentry (sort @classes)
512 {
513 @classline = split( /\;/, $classentry );
514 if ( $classline[0] eq $qossettings{'DEV'} )
515 {
516 $color=random_hex_color(6);
517 push(@command, "DEF:$classline[1]=$rrdlog/class_$qossettings{'CLASSPRFX'}-$classline[1]_$qossettings{'DEV'}.rrd:bytes:AVERAGE");
518
519 if ($count eq "1") {
520 push(@command, "AREA:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
521 } else {
522 push(@command, "STACK:$classline[1]$color:Klasse $classline[1] -".sprintf("%15s",$classline[8]));
523
524 }
525 push(@command, "GPRINT:$classline[1]:MAX:%8.1lf %sBps");
526 push(@command, "GPRINT:$classline[1]:AVERAGE:%8.1lf %sBps");
527 push(@command, "GPRINT:$classline[1]:MIN:%8.1lf %sBps");
528 push(@command, "GPRINT:$classline[1]:LAST:%8.1lf %sBps\\j");
529 $count++;
530 }
531 }
532 RRDs::graph (@command);
533 $ERROR = RRDs::error;
534 print "$ERROR";
535 }
536
537 # Generate the Temperature Graph for the current period of time for values given by collecd and mbmon
538
539 sub updatehwtempgraph {
540
541 my $period = $_[0];
542
543 my @command = ("$graphs/mbmon-hwtemp-$period.png",
544 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
545 "--alt-y-grid", "-w 600", "-h 125",
546 "--color", "SHADEA".$color{"color19"},"--color",
547 "SHADEB".$color{"color19"},"--color",
548 "BACK".$color{"color21"},
549 "-t $Lang::tr{'mbmon temp'} $Lang::tr{'graph per'} $Lang::tr{$period}");
550
551 foreach(@mbmongraphs){
552 chomp($_);
553 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");
554 }
555 }
556 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");
557 foreach(@mbmongraphs){
558 chomp($_);
559 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]}),
560 "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",);}
561 }
562 RRDs::graph (@command);
563 $ERROR = RRDs::error;
564 print "$ERROR";
565 }
566
567 # Generate the Voltage Graph for the current period of time for values given by collecd and mbmon
568
569 sub updatehwvoltgraph {
570
571 my $period = $_[0];
572
573 my @command = ("$graphs/mbmon-hwvolt-$period.png",
574 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
575 "--alt-y-grid", "-w 600", "-h 125",
576 "--color", "SHADEA".$color{"color19"},"--color",
577 "SHADEB".$color{"color19"},"--color",
578 "BACK".$color{"color21"},
579 "-t $Lang::tr{'mbmon volt'} $Lang::tr{'graph per'} $Lang::tr{$period}");
580
581 foreach(@mbmongraphs){
582 chomp($_);
583 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");}
584 }
585 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");
586 foreach(@mbmongraphs){
587 chomp($_);
588 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]}),
589 "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",);}
590 }
591 RRDs::graph (@command);
592 $ERROR = RRDs::error;
593 print "$ERROR";
594 }
595
596 # Generate the Load Graph for the current period of time for values given by collecd and mbmon
597
598 sub updatehwfangraph {
599
600 my $period = $_[0];
601
602 my @command = ("$graphs/mbmon-hwfan-$period.png",
603 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
604 "--alt-y-grid", "-w 600", "-h 125",
605 "--color", "SHADEA".$color{"color19"},"--color",
606 "SHADEB".$color{"color19"},"--color",
607 "BACK".$color{"color21"},
608 "-t $Lang::tr{'mbmon fan'} $Lang::tr{'graph per'} $Lang::tr{$period}");
609
610 foreach(@mbmongraphs){
611 chomp($_);
612 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");}
613 }
614 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");
615 foreach(@mbmongraphs){
616 chomp($_);
617 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]}),
618 "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",);}
619 }
620 RRDs::graph (@command);
621 $ERROR = RRDs::error;
622 print "$ERROR";
623 }
624
625 sub updateprocessesgraph {
626
627 my $period = $_[0];
628 my $count="0";
629
630 my @command = ("$graphs/processes-$period.png",
631 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
632 "--alt-y-grid", "-w 600", "-h 125",
633 "--color", "SHADEA".$color{"color19"},"--color",
634 "SHADEB".$color{"color19"},"--color",
635 "BACK".$color{"color21"},
636 "-t $Lang::tr{'processes'} $Lang::tr{'graph per'} $Lang::tr{$period}");
637
638 foreach(@processesgraph){
639 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
640 push(@command,"DEF:".$name[1]."user=".$_."ps_cputime.rrd:user:AVERAGE");
641 push(@command,"DEF:".$name[1]."system=".$_."ps_cputime.rrd:syst:AVERAGE");
642 push(@command,"CDEF:".$name[1]."=".$name[1]."user,".$name[1]."system,+");}
643
644 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
645
646 foreach(@processesgraph){
647 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
648 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
649 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
650 $count++;}
651
652 RRDs::graph (@command);
653 $ERROR = RRDs::error;
654 print "$ERROR";
655
656 my $count="0";
657
658 my @command = ("$graphs/processesmem-$period.png",
659 "--start", "-1$period", "-aPNG", "-i", "-W www.ipfire.org",
660 "--alt-y-grid", "-w 600", "-h 125",
661 "--color", "SHADEA".$color{"color19"},"--color",
662 "SHADEB".$color{"color19"},"--color",
663 "BACK".$color{"color21"},
664 "-t $Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph per'} $Lang::tr{$period}");
665
666 foreach(@processesgraph){
667 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
668 push(@command,"DEF:".$name[1]."=".$_."ps_rss.rrd:value:AVERAGE");}
669 push(@command,"COMMENT:".$Lang::tr{'caption'}."\\j");
670
671 foreach(@processesgraph){
672 chomp($_);my @name=split(/\-/,$_);chop($name[1]);
673 if ($count eq "0") {push(@command,"AREA:".$name[1].random_hex_color(6)."A0:".$name[1]);}
674 else {push(@command,"STACK:".$name[1].random_hex_color(6)."A0:".$name[1]);}
675 $count++;}
676
677 RRDs::graph (@command);
678 $ERROR = RRDs::error;
679 print "$ERROR";
680 }
681
682 # Generate a random color, used by Qos Graph to be independent from the amount of values
683
684 sub random_hex_color {
685 my $size = shift;
686 $size = 6 if $size !~ /^3|6$/;
687 my @hex = ( 0 .. 9, 'a' .. 'f' );
688 my @color;
689 push @color, @hex[rand(@hex)] for 1 .. $size;
690 return join('', '#', @color);
691 }