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