1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 no warnings ('qw');
8 use CGI;
9 use RRDs;
10 use Fcntl (qw(:flock));
11 use Carp (qw(carp cluck confess croak));
13 our $Config = read_config ();
15 our $AbsDir;
16 our $RelDir;
17 our $Type;
18 our $Inst;
19 our $TimeSpan;
21 for (qw(Red Green Blue Yellow Cyan Magenta))
22 {
23 $Config->{'Colors'}{"Half$_"} = color_calculate_transparent ($Config->{'Colors'}{'Alpha'},
24 $Config->{'Colors'}{'Canvas'}, $Config->{'Colors'}{"Full$_"});
25 }
27 $Config->{'Colors'}{'HalfBlueGreen'} = color_calculate_transparent ($Config->{'Colors'}{'Alpha'},
28 $Config->{'Colors'}{'Canvas'}, $Config->{'Colors'}{'FullGreen'}, $Config->{'Colors'}{'FullBlue'});
29 $Config->{'Colors'}{'HalfRedBlue'} = color_calculate_transparent ($Config->{'Colors'}{'Alpha'},
30 $Config->{'Colors'}{'Canvas'}, $Config->{'Colors'}{'FullBlue'}, $Config->{'Colors'}{'FullRed'});
32 our $GraphDefs;
33 {
34 my $Alpha = $Config->{'Colors'}{'Alpha'};
35 my $Canvas = $Config->{'Colors'}{'Canvas'};
37 my $FullRed = $Config->{'Colors'}{'FullRed'};
38 my $FullGreen = $Config->{'Colors'}{'FullGreen'};
39 my $FullBlue = $Config->{'Colors'}{'FullBlue'};
40 my $FullYellow = $Config->{'Colors'}{'FullYellow'};
41 my $FullCyan = $Config->{'Colors'}{'FullCyan'};
42 my $FullMagenta= $Config->{'Colors'}{'FullMagenta'};
44 my $HalfRed = $Config->{'Colors'}{'HalfRed'};
45 my $HalfGreen = $Config->{'Colors'}{'HalfGreen'};
46 my $HalfBlue = $Config->{'Colors'}{'HalfBlue'};
47 my $HalfYellow = $Config->{'Colors'}{'HalfYellow'};
48 my $HalfCyan = $Config->{'Colors'}{'HalfCyan'};
49 my $HalfMagenta= $Config->{'Colors'}{'HalfMagenta'};
51 my $HalfBlueGreen = $Config->{'Colors'}{'HalfBlueGreen'};
52 my $HalfRedBlue = $Config->{'Colors'}{'HalfRedBlue'};
54 $GraphDefs =
55 {
56 apache_bytes => ['DEF:min_raw={file}:count:MIN',
57 'DEF:avg_raw={file}:count:AVERAGE',
58 'DEF:max_raw={file}:count:MAX',
59 'CDEF:min=min_raw,8,*',
60 'CDEF:avg=avg_raw,8,*',
61 'CDEF:max=max_raw,8,*',
62 'CDEF:mytime=avg_raw,TIME,TIME,IF',
63 'CDEF:sample_len_raw=mytime,PREV(mytime),-',
64 'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
65 'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
66 'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
67 "AREA:avg#$HalfBlue",
68 "LINE1:avg#$FullBlue:Bit/s",
69 'GPRINT:min:MIN:%5.1lf%s Min,',
70 'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
71 'GPRINT:max:MAX:%5.1lf%s Max,',
72 'GPRINT:avg:LAST:%5.1lf%s Last',
73 'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
74 ],
75 apache_requests => ['DEF:min={file}:count:MIN',
76 'DEF:avg={file}:count:AVERAGE',
77 'DEF:max={file}:count:MAX',
78 "AREA:max#$HalfBlue",
79 "AREA:min#$Canvas",
80 "LINE1:avg#$FullBlue:Requests/s",
81 'GPRINT:min:MIN:%6.2lf Min,',
82 'GPRINT:avg:AVERAGE:%6.2lf Avg,',
83 'GPRINT:max:MAX:%6.2lf Max,',
84 'GPRINT:avg:LAST:%6.2lf Last'
85 ],
86 apache_scoreboard => ['DEF:min={file}:count:MIN',
87 'DEF:avg={file}:count:AVERAGE',
88 'DEF:max={file}:count:MAX',
89 "AREA:max#$HalfBlue",
90 "AREA:min#$Canvas",
91 "LINE1:avg#$FullBlue:Processes",
92 'GPRINT:min:MIN:%6.2lf Min,',
93 'GPRINT:avg:AVERAGE:%6.2lf Avg,',
94 'GPRINT:max:MAX:%6.2lf Max,',
95 'GPRINT:avg:LAST:%6.2lf Last'
96 ],
97 charge => [
98 'DEF:avg={file}:charge:AVERAGE',
99 'DEF:min={file}:charge:MIN',
100 'DEF:max={file}:charge:MAX',
101 "AREA:max#$HalfBlue",
102 "AREA:min#$Canvas",
103 "LINE1:avg#$FullBlue:Charge",
104 'GPRINT:min:MIN:%5.1lf%sAh Min,',
105 'GPRINT:avg:AVERAGE:%5.1lf%sAh Avg,',
106 'GPRINT:max:MAX:%5.1lf%sAh Max,',
107 'GPRINT:avg:LAST:%5.1lf%sAh Last\l'
108 ],
109 cpu => ['DEF:user_avg={file}:user:AVERAGE',
110 'DEF:user_min={file}:user:MIN',
111 'DEF:user_max={file}:user:MAX',
112 'DEF:nice_avg={file}:nice:AVERAGE',
113 'DEF:nice_min={file}:nice:MIN',
114 'DEF:nice_max={file}:nice:MAX',
115 'DEF:syst_avg={file}:syst:AVERAGE',
116 'DEF:syst_min={file}:syst:MIN',
117 'DEF:syst_max={file}:syst:MAX',
118 'DEF:idle_avg={file}:idle:AVERAGE',
119 'DEF:idle_min={file}:idle:MIN',
120 'DEF:idle_max={file}:idle:MAX',
121 'DEF:wait_avg={file}:wait:AVERAGE',
122 'DEF:wait_min={file}:wait:MIN',
123 'DEF:wait_max={file}:wait:MAX',
124 'CDEF:user_avg_notnull=user_avg,UN,0,user_avg,IF',
125 'CDEF:nice_avg_notnull=nice_avg,UN,0,nice_avg,IF',
126 'CDEF:syst_avg_notnull=syst_avg,UN,0,syst_avg,IF',
127 'CDEF:idle_avg_notnull=idle_avg,UN,0,idle_avg,IF',
128 'CDEF:wait_avg_notnull=wait_avg,UN,0,wait_avg,IF',
129 'CDEF:totl_avg_notnull=user_avg_notnull,nice_avg_notnull,+,syst_avg_notnull,+,idle_avg_notnull,+,wait_avg_notnull,+',
130 'CDEF:user_avg_pct=user_avg_notnull,100,*,totl_avg_notnull,/',
131 'CDEF:nice_avg_pct=nice_avg_notnull,100,*,totl_avg_notnull,/',
132 'CDEF:syst_avg_pct=syst_avg_notnull,100,*,totl_avg_notnull,/',
133 'CDEF:wait_avg_pct=wait_avg_notnull,100,*,totl_avg_notnull,/',
134 'CDEF:nice_acc=syst_avg_pct,wait_avg_pct,user_avg_pct,nice_avg_pct,+,+,+',
135 'CDEF:user_acc=syst_avg_pct,wait_avg_pct,user_avg_pct,+,+',
136 'CDEF:wait_acc=syst_avg_pct,wait_avg_pct,+',
137 'CDEF:syst_acc=syst_avg_pct',
138 # 'CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+',
139 # 'CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+',
140 # 'CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+',
141 # 'CDEF:syst_acc=syst_avg_notnull',
142 "AREA:nice_acc#$HalfGreen",
143 "AREA:user_acc#$HalfBlue",
144 "AREA:wait_acc#$HalfYellow",
145 "AREA:syst_acc#$HalfRed",
146 "LINE1:nice_acc#$FullGreen:Nice ",
147 'GPRINT:nice_min:MIN:%5.1lf%% Min,',
148 'GPRINT:nice_avg:AVERAGE:%5.1lf%% Avg,',
149 'GPRINT:nice_max:MAX:%5.1lf%% Max,',
150 'GPRINT:nice_avg:LAST:%5.1lf%% Last\l',
151 "LINE1:user_acc#$FullBlue:User ",
152 'GPRINT:user_min:MIN:%5.1lf%% Min,',
153 'GPRINT:user_avg:AVERAGE:%5.1lf%% Avg,',
154 'GPRINT:user_max:MAX:%5.1lf%% Max,',
155 'GPRINT:user_avg:LAST:%5.1lf%% Last\l',
156 "LINE1:wait_acc#$FullYellow:Wait-IO",
157 'GPRINT:wait_min:MIN:%5.1lf%% Min,',
158 'GPRINT:wait_avg:AVERAGE:%5.1lf%% Avg,',
159 'GPRINT:wait_max:MAX:%5.1lf%% Max,',
160 'GPRINT:wait_avg:LAST:%5.1lf%% Last\l',
161 "LINE1:syst_acc#$FullRed:System ",
162 'GPRINT:syst_min:MIN:%5.1lf%% Min,',
163 'GPRINT:syst_avg:AVERAGE:%5.1lf%% Avg,',
164 'GPRINT:syst_max:MAX:%5.1lf%% Max,',
165 'GPRINT:syst_avg:LAST:%5.1lf%% Last\l'
166 ],
167 current => [
168 'DEF:avg={file}:current:AVERAGE',
169 'DEF:min={file}:current:MIN',
170 'DEF:max={file}:current:MAX',
171 "AREA:max#$HalfBlue",
172 "AREA:min#$Canvas",
173 "LINE1:avg#$FullBlue:Current",
174 'GPRINT:min:MIN:%5.1lf%sA Min,',
175 'GPRINT:avg:AVERAGE:%5.1lf%sA Avg,',
176 'GPRINT:max:MAX:%5.1lf%sA Max,',
177 'GPRINT:avg:LAST:%5.1lf%sA Last\l'
178 ],
179 df => [
180 'DEF:free_avg={file}:free:AVERAGE',
181 'DEF:free_min={file}:free:MIN',
182 'DEF:free_max={file}:free:MAX',
183 'DEF:used_avg={file}:used:AVERAGE',
184 'DEF:used_min={file}:used:MIN',
185 'DEF:used_max={file}:used:MAX',
186 'CDEF:total=free_avg,used_avg,+',
187 'CDEF:free_pct=100,free_avg,*,total,/',
188 'CDEF:used_pct=100,used_avg,*,total,/',
189 'CDEF:free_acc=free_pct,used_pct,+',
190 'CDEF:used_acc=used_pct',
191 "AREA:free_acc#$HalfGreen",
192 "AREA:used_acc#$HalfRed",
193 "LINE1:free_acc#$FullGreen:Free",
194 'GPRINT:free_min:MIN:%5.1lf%sB Min,',
195 'GPRINT:free_avg:AVERAGE:%5.1lf%sB Avg,',
196 'GPRINT:free_max:MAX:%5.1lf%sB Max,',
197 'GPRINT:free_avg:LAST:%5.1lf%sB Last\l',
198 "LINE1:used_acc#$FullRed:Used",
199 'GPRINT:used_min:MIN:%5.1lf%sB Min,',
200 'GPRINT:used_avg:AVERAGE:%5.1lf%sB Avg,',
201 'GPRINT:used_max:MAX:%5.1lf%sB Max,',
202 'GPRINT:used_avg:LAST:%5.1lf%sB Last\l'
203 ],
204 disk => [
205 'DEF:rtime_avg={file}:rtime:AVERAGE',
206 'DEF:rtime_min={file}:rtime:MIN',
207 'DEF:rtime_max={file}:rtime:MAX',
208 'DEF:wtime_avg={file}:wtime:AVERAGE',
209 'DEF:wtime_min={file}:wtime:MIN',
210 'DEF:wtime_max={file}:wtime:MAX',
211 'CDEF:rtime_avg_ms=rtime_avg,1000,/',
212 'CDEF:rtime_min_ms=rtime_min,1000,/',
213 'CDEF:rtime_max_ms=rtime_max,1000,/',
214 'CDEF:wtime_avg_ms=wtime_avg,1000,/',
215 'CDEF:wtime_min_ms=wtime_min,1000,/',
216 'CDEF:wtime_max_ms=wtime_max,1000,/',
217 'CDEF:total_avg_ms=rtime_avg_ms,wtime_avg_ms,+',
218 'CDEF:total_min_ms=rtime_min_ms,wtime_min_ms,+',
219 'CDEF:total_max_ms=rtime_max_ms,wtime_max_ms,+',
220 "AREA:total_max_ms#$HalfRed",
221 "AREA:total_min_ms#$Canvas",
222 "LINE1:wtime_avg_ms#$FullGreen:Write",
223 'GPRINT:wtime_min_ms:MIN:%5.1lf%s Min,',
224 'GPRINT:wtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
225 'GPRINT:wtime_max_ms:MAX:%5.1lf%s Max,',
226 'GPRINT:wtime_avg_ms:LAST:%5.1lf%s Last\n',
227 "LINE1:rtime_avg_ms#$FullBlue:Read ",
228 'GPRINT:rtime_min_ms:MIN:%5.1lf%s Min,',
229 'GPRINT:rtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
230 'GPRINT:rtime_max_ms:MAX:%5.1lf%s Max,',
231 'GPRINT:rtime_avg_ms:LAST:%5.1lf%s Last\n',
232 "LINE1:total_avg_ms#$FullRed:Total",
233 'GPRINT:total_min_ms:MIN:%5.1lf%s Min,',
234 'GPRINT:total_avg_ms:AVERAGE:%5.1lf%s Avg,',
235 'GPRINT:total_max_ms:MAX:%5.1lf%s Max,',
236 'GPRINT:total_avg_ms:LAST:%5.1lf%s Last'
237 ],
238 hddtemp => [
239 'DEF:temp_avg={file}:value:AVERAGE',
240 'DEF:temp_min={file}:value:MIN',
241 'DEF:temp_max={file}:value:MAX',
242 "AREA:temp_max#$HalfBlue",
243 "AREA:temp_min#$Canvas",
244 "LINE1:temp_avg#$FullBlue:Temperature",
245 'GPRINT:temp_min:MIN:%4.1lf Min,',
246 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
247 'GPRINT:temp_max:MAX:%4.1lf Max,',
248 'GPRINT:temp_avg:LAST:%4.1lf Last\l'
249 ],
250 load => ['DEF:s_avg={file}:shortterm:AVERAGE',
251 'DEF:s_min={file}:shortterm:MIN',
252 'DEF:s_max={file}:shortterm:MAX',
253 'DEF:m_avg={file}:midterm:AVERAGE',
254 'DEF:m_min={file}:midterm:MIN',
255 'DEF:m_max={file}:midterm:MAX',
256 'DEF:l_avg={file}:longterm:AVERAGE',
257 'DEF:l_min={file}:longterm:MIN',
258 'DEF:l_max={file}:longterm:MAX',
259 "AREA:s_max#$HalfGreen",
260 "AREA:s_min#$Canvas",
261 "LINE1:s_avg#$FullGreen: 1m average",
262 'GPRINT:s_min:MIN:%4.2lf Min,',
263 'GPRINT:s_avg:AVERAGE:%4.2lf Avg,',
264 'GPRINT:s_max:MAX:%4.2lf Max,',
265 'GPRINT:s_avg:LAST:%4.2lf Last\n',
266 "LINE1:m_avg#$FullBlue: 5m average",
267 'GPRINT:m_min:MIN:%4.2lf Min,',
268 'GPRINT:m_avg:AVERAGE:%4.2lf Avg,',
269 'GPRINT:m_max:MAX:%4.2lf Max,',
270 'GPRINT:m_avg:LAST:%4.2lf Last\n',
271 "LINE1:l_avg#$FullRed:15m average",
272 'GPRINT:l_min:MIN:%4.2lf Min,',
273 'GPRINT:l_avg:AVERAGE:%4.2lf Avg,',
274 'GPRINT:l_max:MAX:%4.2lf Max,',
275 'GPRINT:l_avg:LAST:%4.2lf Last'
276 ],
277 mails => ['DEF:rawgood={file}:good:AVERAGE',
278 'DEF:rawspam={file}:spam:AVERAGE',
279 'CDEF:good=rawgood,UN,0,rawgood,IF',
280 'CDEF:spam=rawspam,UN,0,rawspam,IF',
281 'CDEF:negspam=spam,-1,*',
282 "AREA:good#$HalfGreen",
283 "LINE1:good#$FullGreen:Good mails",
284 'GPRINT:good:AVERAGE:%4.1lf Avg,',
285 'GPRINT:good:MAX:%4.1lf Max,',
286 'GPRINT:good:LAST:%4.1lf Last\n',
287 "AREA:negspam#$HalfRed",
288 "LINE1:negspam#$FullRed:Spam mails",
289 'GPRINT:spam:AVERAGE:%4.1lf Avg,',
290 'GPRINT:spam:MAX:%4.1lf Max,',
291 'GPRINT:spam:LAST:%4.1lf Last',
292 'HRULE:0#000000'],
293 memory => [
294 'DEF:used_avg={file}:used:AVERAGE',
295 'DEF:free_avg={file}:free:AVERAGE',
296 'DEF:buffers_avg={file}:buffers:AVERAGE',
297 'DEF:cached_avg={file}:cached:AVERAGE',
298 'DEF:used_min={file}:used:MIN',
299 'DEF:free_min={file}:free:MIN',
300 'DEF:buffers_min={file}:buffers:MIN',
301 'DEF:cached_min={file}:cached:MIN',
302 'DEF:used_max={file}:used:MAX',
303 'DEF:free_max={file}:free:MAX',
304 'DEF:buffers_max={file}:buffers:MAX',
305 'DEF:cached_max={file}:cached:MAX',
306 'CDEF:cached_avg_nn=cached_avg,UN,0,cached_avg,IF',
307 'CDEF:buffers_avg_nn=buffers_avg,UN,0,buffers_avg,IF',
308 'CDEF:free_cached_buffers_used=free_avg,cached_avg_nn,+,buffers_avg_nn,+,used_avg,+',
309 'CDEF:cached_buffers_used=cached_avg,buffers_avg_nn,+,used_avg,+',
310 'CDEF:buffers_used=buffers_avg,used_avg,+',
311 "AREA:free_cached_buffers_used#$HalfGreen",
312 "AREA:cached_buffers_used#$HalfBlue",
313 "AREA:buffers_used#$HalfYellow",
314 "AREA:used_avg#$HalfRed",
315 "LINE1:free_cached_buffers_used#$FullGreen:Free ",
316 'GPRINT:free_min:MIN:%5.1lf%s Min,',
317 'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
318 'GPRINT:free_max:MAX:%5.1lf%s Max,',
319 'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
320 "LINE1:cached_buffers_used#$FullBlue:Page cache ",
321 'GPRINT:cached_min:MIN:%5.1lf%s Min,',
322 'GPRINT:cached_avg:AVERAGE:%5.1lf%s Avg,',
323 'GPRINT:cached_max:MAX:%5.1lf%s Max,',
324 'GPRINT:cached_avg:LAST:%5.1lf%s Last\n',
325 "LINE1:buffers_used#$FullYellow:Buffer cache",
326 'GPRINT:buffers_min:MIN:%5.1lf%s Min,',
327 'GPRINT:buffers_avg:AVERAGE:%5.1lf%s Avg,',
328 'GPRINT:buffers_max:MAX:%5.1lf%s Max,',
329 'GPRINT:buffers_avg:LAST:%5.1lf%s Last\n',
330 "LINE1:used_avg#$FullRed:Used ",
331 'GPRINT:used_min:MIN:%5.1lf%s Min,',
332 'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
333 'GPRINT:used_max:MAX:%5.1lf%s Max,',
334 'GPRINT:used_avg:LAST:%5.1lf%s Last'
335 ],
336 mysql_commands => [
337 "DEF:val_avg={file}:value:AVERAGE",
338 "DEF:val_min={file}:value:MIN",
339 "DEF:val_max={file}:value:MAX",
340 "AREA:val_max#$HalfBlue",
341 "AREA:val_min#$Canvas",
342 "LINE1:val_avg#$FullBlue:{inst}",
343 'GPRINT:val_min:MIN:%5.2lf Min,',
344 'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
345 'GPRINT:val_max:MAX:%5.2lf Max,',
346 'GPRINT:val_avg:LAST:%5.2lf Last'
347 ],
348 mysql_handler => [
349 "DEF:val_avg={file}:value:AVERAGE",
350 "DEF:val_min={file}:value:MIN",
351 "DEF:val_max={file}:value:MAX",
352 "AREA:val_max#$HalfBlue",
353 "AREA:val_min#$Canvas",
354 "LINE1:val_avg#$FullBlue:{inst}",
355 'GPRINT:val_min:MIN:%5.2lf Min,',
356 'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
357 'GPRINT:val_max:MAX:%5.2lf Max,',
358 'GPRINT:val_avg:LAST:%5.2lf Last'
359 ],
360 mysql_qcache => [
361 "DEF:hits_min={file}:hits:MIN",
362 "DEF:hits_avg={file}:hits:AVERAGE",
363 "DEF:hits_max={file}:hits:MAX",
364 "DEF:inserts_min={file}:inserts:MIN",
365 "DEF:inserts_avg={file}:inserts:AVERAGE",
366 "DEF:inserts_max={file}:inserts:MAX",
367 "DEF:not_cached_min={file}:not_cached:MIN",
368 "DEF:not_cached_avg={file}:not_cached:AVERAGE",
369 "DEF:not_cached_max={file}:not_cached:MAX",
370 "DEF:lowmem_prunes_min={file}:lowmem_prunes:MIN",
371 "DEF:lowmem_prunes_avg={file}:lowmem_prunes:AVERAGE",
372 "DEF:lowmem_prunes_max={file}:lowmem_prunes:MAX",
373 "DEF:queries_min={file}:queries_in_cache:MIN",
374 "DEF:queries_avg={file}:queries_in_cache:AVERAGE",
375 "DEF:queries_max={file}:queries_in_cache:MAX",
376 "CDEF:unknown=queries_avg,UNKN,+",
377 "CDEF:not_cached_agg=hits_avg,inserts_avg,+,not_cached_avg,+",
378 "CDEF:inserts_agg=hits_avg,inserts_avg,+",
379 "CDEF:hits_agg=hits_avg",
380 "AREA:not_cached_agg#$HalfYellow",
381 "AREA:inserts_agg#$HalfBlue",
382 "AREA:hits_agg#$HalfGreen",
383 "LINE1:not_cached_agg#$FullYellow:Not Cached ",
384 'GPRINT:not_cached_min:MIN:%5.2lf Min,',
385 'GPRINT:not_cached_avg:AVERAGE:%5.2lf Avg,',
386 'GPRINT:not_cached_max:MAX:%5.2lf Max,',
387 'GPRINT:not_cached_avg:LAST:%5.2lf Last\l',
388 "LINE1:inserts_agg#$FullBlue:Inserts ",
389 'GPRINT:inserts_min:MIN:%5.2lf Min,',
390 'GPRINT:inserts_avg:AVERAGE:%5.2lf Avg,',
391 'GPRINT:inserts_max:MAX:%5.2lf Max,',
392 'GPRINT:inserts_avg:LAST:%5.2lf Last\l',
393 "LINE1:hits_agg#$FullGreen:Hits ",
394 'GPRINT:hits_min:MIN:%5.2lf Min,',
395 'GPRINT:hits_avg:AVERAGE:%5.2lf Avg,',
396 'GPRINT:hits_max:MAX:%5.2lf Max,',
397 'GPRINT:hits_avg:LAST:%5.2lf Last\l',
398 "LINE1:lowmem_prunes_avg#$FullRed:Lowmem Prunes ",
399 'GPRINT:lowmem_prunes_min:MIN:%5.2lf Min,',
400 'GPRINT:lowmem_prunes_avg:AVERAGE:%5.2lf Avg,',
401 'GPRINT:lowmem_prunes_max:MAX:%5.2lf Max,',
402 'GPRINT:lowmem_prunes_avg:LAST:%5.2lf Last\l',
403 "LINE1:unknown#$Canvas:Queries in cache",
404 'GPRINT:queries_min:MIN:%5.0lf Min,',
405 'GPRINT:queries_avg:AVERAGE:%5.0lf Avg,',
406 'GPRINT:queries_max:MAX:%5.0lf Max,',
407 'GPRINT:queries_avg:LAST:%5.0lf Last\l'
408 ],
409 mysql_threads => [
410 "DEF:running_min={file}:running:MIN",
411 "DEF:running_avg={file}:running:AVERAGE",
412 "DEF:running_max={file}:running:MAX",
413 "DEF:connected_min={file}:connected:MIN",
414 "DEF:connected_avg={file}:connected:AVERAGE",
415 "DEF:connected_max={file}:connected:MAX",
416 "DEF:cached_min={file}:cached:MIN",
417 "DEF:cached_avg={file}:cached:AVERAGE",
418 "DEF:cached_max={file}:cached:MAX",
419 "DEF:created_min={file}:created:MIN",
420 "DEF:created_avg={file}:created:AVERAGE",
421 "DEF:created_max={file}:created:MAX",
422 "CDEF:unknown=created_avg,UNKN,+",
423 "CDEF:cached_agg=connected_avg,cached_avg,+",
424 "AREA:cached_agg#$HalfGreen",
425 "AREA:connected_avg#$HalfBlue",
426 "AREA:running_avg#$HalfRed",
427 "LINE1:cached_agg#$FullGreen:Cached ",
428 'GPRINT:cached_min:MIN:%5.1lf Min,',
429 'GPRINT:cached_avg:AVERAGE:%5.1lf Avg,',
430 'GPRINT:cached_max:MAX:%5.1lf Max,',
431 'GPRINT:cached_avg:LAST:%5.1lf Last\l',
432 "LINE1:connected_avg#$FullBlue:Connected",
433 'GPRINT:connected_min:MIN:%5.1lf Min,',
434 'GPRINT:connected_avg:AVERAGE:%5.1lf Avg,',
435 'GPRINT:connected_max:MAX:%5.1lf Max,',
436 'GPRINT:connected_avg:LAST:%5.1lf Last\l',
437 "LINE1:running_avg#$FullRed:Running ",
438 'GPRINT:running_min:MIN:%5.1lf Min,',
439 'GPRINT:running_avg:AVERAGE:%5.1lf Avg,',
440 'GPRINT:running_max:MAX:%5.1lf Max,',
441 'GPRINT:running_avg:LAST:%5.1lf Last\l',
442 "LINE1:unknown#$Canvas:Created ",
443 'GPRINT:created_min:MIN:%5.0lf Min,',
444 'GPRINT:created_avg:AVERAGE:%5.0lf Avg,',
445 'GPRINT:created_max:MAX:%5.0lf Max,',
446 'GPRINT:created_avg:LAST:%5.0lf Last\l'
447 ],
448 nfs3_procedures => [
449 "DEF:null_avg={file}:null:AVERAGE",
450 "DEF:getattr_avg={file}:getattr:AVERAGE",
451 "DEF:setattr_avg={file}:setattr:AVERAGE",
452 "DEF:lookup_avg={file}:lookup:AVERAGE",
453 "DEF:access_avg={file}:access:AVERAGE",
454 "DEF:readlink_avg={file}:readlink:AVERAGE",
455 "DEF:read_avg={file}:read:AVERAGE",
456 "DEF:write_avg={file}:write:AVERAGE",
457 "DEF:create_avg={file}:create:AVERAGE",
458 "DEF:mkdir_avg={file}:mkdir:AVERAGE",
459 "DEF:symlink_avg={file}:symlink:AVERAGE",
460 "DEF:mknod_avg={file}:mknod:AVERAGE",
461 "DEF:remove_avg={file}:remove:AVERAGE",
462 "DEF:rmdir_avg={file}:rmdir:AVERAGE",
463 "DEF:rename_avg={file}:rename:AVERAGE",
464 "DEF:link_avg={file}:link:AVERAGE",
465 "DEF:readdir_avg={file}:readdir:AVERAGE",
466 "DEF:readdirplus_avg={file}:readdirplus:AVERAGE",
467 "DEF:fsstat_avg={file}:fsstat:AVERAGE",
468 "DEF:fsinfo_avg={file}:fsinfo:AVERAGE",
469 "DEF:pathconf_avg={file}:pathconf:AVERAGE",
470 "DEF:commit_avg={file}:commit:AVERAGE",
471 "DEF:null_max={file}:null:MAX",
472 "DEF:getattr_max={file}:getattr:MAX",
473 "DEF:setattr_max={file}:setattr:MAX",
474 "DEF:lookup_max={file}:lookup:MAX",
475 "DEF:access_max={file}:access:MAX",
476 "DEF:readlink_max={file}:readlink:MAX",
477 "DEF:read_max={file}:read:MAX",
478 "DEF:write_max={file}:write:MAX",
479 "DEF:create_max={file}:create:MAX",
480 "DEF:mkdir_max={file}:mkdir:MAX",
481 "DEF:symlink_max={file}:symlink:MAX",
482 "DEF:mknod_max={file}:mknod:MAX",
483 "DEF:remove_max={file}:remove:MAX",
484 "DEF:rmdir_max={file}:rmdir:MAX",
485 "DEF:rename_max={file}:rename:MAX",
486 "DEF:link_max={file}:link:MAX",
487 "DEF:readdir_max={file}:readdir:MAX",
488 "DEF:readdirplus_max={file}:readdirplus:MAX",
489 "DEF:fsstat_max={file}:fsstat:MAX",
490 "DEF:fsinfo_max={file}:fsinfo:MAX",
491 "DEF:pathconf_max={file}:pathconf:MAX",
492 "DEF:commit_max={file}:commit:MAX",
493 "CDEF:other_avg=null_avg,readlink_avg,create_avg,mkdir_avg,symlink_avg,mknod_avg,remove_avg,rmdir_avg,rename_avg,link_avg,readdir_avg,readdirplus_avg,fsstat_avg,fsinfo_avg,pathconf_avg,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
494 "CDEF:other_max=null_max,readlink_max,create_max,mkdir_max,symlink_max,mknod_max,remove_max,rmdir_max,rename_max,link_max,readdir_max,readdirplus_max,fsstat_max,fsinfo_max,pathconf_max,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
495 "CDEF:stack_read=read_avg",
496 "CDEF:stack_getattr=stack_read,getattr_avg,+",
497 "CDEF:stack_access=stack_getattr,access_avg,+",
498 "CDEF:stack_lookup=stack_access,lookup_avg,+",
499 "CDEF:stack_write=stack_lookup,write_avg,+",
500 "CDEF:stack_commit=stack_write,commit_avg,+",
501 "CDEF:stack_setattr=stack_commit,setattr_avg,+",
502 "CDEF:stack_other=stack_setattr,other_avg,+",
503 "AREA:stack_other#$HalfRed",
504 "AREA:stack_setattr#$HalfGreen",
505 "AREA:stack_commit#$HalfYellow",
506 "AREA:stack_write#$HalfGreen",
507 "AREA:stack_lookup#$HalfBlue",
508 "AREA:stack_access#$HalfMagenta",
509 "AREA:stack_getattr#$HalfCyan",
510 "AREA:stack_read#$HalfBlue",
511 "LINE1:stack_other#$FullRed:Other ",
512 'GPRINT:other_max:MAX:%5.1lf Max,',
513 'GPRINT:other_avg:AVERAGE:%5.1lf Avg,',
514 'GPRINT:other_avg:LAST:%5.1lf Last\l',
515 "LINE1:stack_setattr#$FullGreen:setattr",
516 'GPRINT:setattr_max:MAX:%5.1lf Max,',
517 'GPRINT:setattr_avg:AVERAGE:%5.1lf Avg,',
518 'GPRINT:setattr_avg:LAST:%5.1lf Last\l',
519 "LINE1:stack_commit#$FullYellow:commit ",
520 'GPRINT:commit_max:MAX:%5.1lf Max,',
521 'GPRINT:commit_avg:AVERAGE:%5.1lf Avg,',
522 'GPRINT:commit_avg:LAST:%5.1lf Last\l',
523 "LINE1:stack_write#$FullGreen:write ",
524 'GPRINT:write_max:MAX:%5.1lf Max,',
525 'GPRINT:write_avg:AVERAGE:%5.1lf Avg,',
526 'GPRINT:write_avg:LAST:%5.1lf Last\l',
527 "LINE1:stack_lookup#$FullBlue:lookup ",
528 'GPRINT:lookup_max:MAX:%5.1lf Max,',
529 'GPRINT:lookup_avg:AVERAGE:%5.1lf Avg,',
530 'GPRINT:lookup_avg:LAST:%5.1lf Last\l',
531 "LINE1:stack_access#$FullMagenta:access ",
532 'GPRINT:access_max:MAX:%5.1lf Max,',
533 'GPRINT:access_avg:AVERAGE:%5.1lf Avg,',
534 'GPRINT:access_avg:LAST:%5.1lf Last\l',
535 "LINE1:stack_getattr#$FullCyan:getattr",
536 'GPRINT:getattr_max:MAX:%5.1lf Max,',
537 'GPRINT:getattr_avg:AVERAGE:%5.1lf Avg,',
538 'GPRINT:getattr_avg:LAST:%5.1lf Last\l',
539 "LINE1:stack_read#$FullBlue:read ",
540 'GPRINT:read_max:MAX:%5.1lf Max,',
541 'GPRINT:read_avg:AVERAGE:%5.1lf Avg,',
542 'GPRINT:read_avg:LAST:%5.1lf Last\l'
543 ],
544 partition => [
545 "DEF:rbyte_avg={file}:rbytes:AVERAGE",
546 "DEF:rbyte_min={file}:rbytes:MIN",
547 "DEF:rbyte_max={file}:rbytes:MAX",
548 "DEF:wbyte_avg={file}:wbytes:AVERAGE",
549 "DEF:wbyte_min={file}:wbytes:MIN",
550 "DEF:wbyte_max={file}:wbytes:MAX",
551 'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
552 "AREA:wbyte_avg#$HalfGreen",
553 "AREA:rbyte_avg#$HalfBlue",
554 "AREA:overlap#$HalfBlueGreen",
555 "LINE1:wbyte_avg#$FullGreen:Write",
556 'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
557 'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
558 'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
559 'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
560 "LINE1:rbyte_avg#$FullBlue:Read ",
561 'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
562 'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
563 'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
564 'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l'
565 ],
566 ping => ['DEF:ping_avg={file}:ping:AVERAGE',
567 'DEF:ping_min={file}:ping:MIN',
568 'DEF:ping_max={file}:ping:MAX',
569 "AREA:ping_max#$HalfBlue",
570 "AREA:ping_min#$Canvas",
571 "LINE1:ping_avg#$FullBlue:Ping",
572 'GPRINT:ping_min:MIN:%4.1lf ms Min,',
573 'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
574 'GPRINT:ping_max:MAX:%4.1lf ms Max,',
575 'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
576 processes => [
577 "DEF:running_avg={file}:running:AVERAGE",
578 "DEF:running_min={file}:running:MIN",
579 "DEF:running_max={file}:running:MAX",
580 "DEF:sleeping_avg={file}:sleeping:AVERAGE",
581 "DEF:sleeping_min={file}:sleeping:MIN",
582 "DEF:sleeping_max={file}:sleeping:MAX",
583 "DEF:zombies_avg={file}:zombies:AVERAGE",
584 "DEF:zombies_min={file}:zombies:MIN",
585 "DEF:zombies_max={file}:zombies:MAX",
586 "DEF:stopped_avg={file}:stopped:AVERAGE",
587 "DEF:stopped_min={file}:stopped:MIN",
588 "DEF:stopped_max={file}:stopped:MAX",
589 "DEF:paging_avg={file}:paging:AVERAGE",
590 "DEF:paging_min={file}:paging:MIN",
591 "DEF:paging_max={file}:paging:MAX",
592 "DEF:blocked_avg={file}:blocked:AVERAGE",
593 "DEF:blocked_min={file}:blocked:MIN",
594 "DEF:blocked_max={file}:blocked:MAX",
595 'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
596 'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
597 'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
598 'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
599 'CDEF:running_acc=sleeping_avg,running_avg,+',
600 'CDEF:sleeping_acc=sleeping_avg',
601 "AREA:paging_acc#$HalfYellow",
602 "AREA:blocked_acc#$HalfCyan",
603 "AREA:zombies_acc#$HalfRed",
604 "AREA:stopped_acc#$HalfMagenta",
605 "AREA:running_acc#$HalfGreen",
606 "AREA:sleeping_acc#$HalfBlue",
607 "LINE1:paging_acc#$FullYellow:Paging ",
608 'GPRINT:paging_min:MIN:%5.1lf Min,',
609 'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
610 'GPRINT:paging_max:MAX:%5.1lf Max,',
611 'GPRINT:paging_avg:LAST:%5.1lf Last\l',
612 "LINE1:blocked_acc#$FullCyan:Blocked ",
613 'GPRINT:blocked_min:MIN:%5.1lf Min,',
614 'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
615 'GPRINT:blocked_max:MAX:%5.1lf Max,',
616 'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
617 "LINE1:zombies_acc#$FullRed:Zombies ",
618 'GPRINT:zombies_min:MIN:%5.1lf Min,',
619 'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
620 'GPRINT:zombies_max:MAX:%5.1lf Max,',
621 'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
622 "LINE1:stopped_acc#$FullMagenta:Stopped ",
623 'GPRINT:stopped_min:MIN:%5.1lf Min,',
624 'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
625 'GPRINT:stopped_max:MAX:%5.1lf Max,',
626 'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
627 "LINE1:running_acc#$FullGreen:Running ",
628 'GPRINT:running_min:MIN:%5.1lf Min,',
629 'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
630 'GPRINT:running_max:MAX:%5.1lf Max,',
631 'GPRINT:running_avg:LAST:%5.1lf Last\l',
632 "LINE1:sleeping_acc#$FullBlue:Sleeping",
633 'GPRINT:sleeping_min:MIN:%5.1lf Min,',
634 'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
635 'GPRINT:sleeping_max:MAX:%5.1lf Max,',
636 'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
637 ],
638 sensors => [
639 'DEF:temp_avg={file}:value:AVERAGE',
640 'DEF:temp_min={file}:value:MIN',
641 'DEF:temp_max={file}:value:MAX',
642 "AREA:temp_max#$HalfBlue",
643 "AREA:temp_min#$Canvas",
644 "LINE1:temp_avg#$FullBlue:Value",
645 'GPRINT:temp_min:MIN:%4.1lf Min,',
646 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
647 'GPRINT:temp_max:MAX:%4.1lf Max,',
648 'GPRINT:temp_avg:LAST:%4.1lf Last\l'
649 ],
650 swap => [
651 'DEF:used_avg={file}:used:AVERAGE',
652 'DEF:used_min={file}:used:MIN',
653 'DEF:used_max={file}:used:MAX',
654 'DEF:free_avg={file}:free:AVERAGE',
655 'DEF:free_min={file}:free:MIN',
656 'DEF:free_max={file}:free:MAX',
657 'DEF:cach_avg={file}:cached:AVERAGE',
658 'DEF:cach_min={file}:cached:MIN',
659 'DEF:cach_max={file}:cached:MAX',
660 'DEF:resv_avg={file}:resv:AVERAGE',
661 'DEF:resv_min={file}:resv:MIN',
662 'DEF:resv_max={file}:resv:MAX',
663 'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
664 'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
665 'CDEF:used_acc=used_avg',
666 'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
667 'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
668 'CDEF:free_acc=cach_acc,free_avg,+',
669 "AREA:free_acc#$HalfGreen",
670 "AREA:cach_acc#$HalfBlue",
671 "AREA:resv_acc#$HalfYellow",
672 "AREA:used_acc#$HalfRed",
673 "LINE1:free_acc#$FullGreen:Free ",
674 'GPRINT:free_min:MIN:%5.1lf%s Min,',
675 'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
676 'GPRINT:free_max:MAX:%5.1lf%s Max,',
677 'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
678 "LINE1:cach_acc#$FullBlue:Cached ",
679 'GPRINT:cach_min:MIN:%5.1lf%s Min,',
680 'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
681 'GPRINT:cach_max:MAX:%5.1lf%s Max,',
682 'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
683 "LINE1:resv_acc#$FullYellow:Reserved",
684 'GPRINT:resv_min:MIN:%5.1lf%s Min,',
685 'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
686 'GPRINT:resv_max:MAX:%5.1lf%s Max,',
687 'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
688 "LINE1:used_acc#$FullRed:Used ",
689 'GPRINT:used_min:MIN:%5.1lf%s Min,',
690 'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
691 'GPRINT:used_max:MAX:%5.1lf%s Max,',
692 'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
693 ],
694 traffic => ['DEF:out_min_raw={file}:outgoing:MIN',
695 'DEF:out_avg_raw={file}:outgoing:AVERAGE',
696 'DEF:out_max_raw={file}:outgoing:MAX',
697 'DEF:inc_min_raw={file}:incoming:MIN',
698 'DEF:inc_avg_raw={file}:incoming:AVERAGE',
699 'DEF:inc_max_raw={file}:incoming:MAX',
700 'CDEF:out_min=out_min_raw,8,*',
701 'CDEF:out_avg=out_avg_raw,8,*',
702 'CDEF:out_max=out_max_raw,8,*',
703 'CDEF:inc_min=inc_min_raw,8,*',
704 'CDEF:inc_avg=inc_avg_raw,8,*',
705 'CDEF:inc_max=inc_max_raw,8,*',
706 'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
707 'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
708 'CDEF:sample_len_raw=mytime,PREV(mytime),-',
709 'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
710 'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
711 'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
712 'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
713 'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
714 "AREA:out_avg#$HalfGreen",
715 "AREA:inc_avg#$HalfBlue",
716 "AREA:overlap#$HalfBlueGreen",
717 "LINE1:out_avg#$FullGreen:Outgoing",
718 'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
719 'GPRINT:out_max:MAX:%5.1lf%s Max,',
720 'GPRINT:out_avg:LAST:%5.1lf%s Last',
721 'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
722 "LINE1:inc_avg#$FullBlue:Incoming",
723 #'GPRINT:inc_min:MIN:%5.1lf %s Min,',
724 'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
725 'GPRINT:inc_max:MAX:%5.1lf%s Max,',
726 'GPRINT:inc_avg:LAST:%5.1lf%s Last',
727 'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
728 ],
729 cpufreq => [
730 'DEF:cpufreq_avg={file}:value:AVERAGE',
731 'DEF:cpufreq_min={file}:value:MIN',
732 'DEF:cpufreq_max={file}:value:MAX',
733 "AREA:cpufreq_max#$HalfBlue",
734 "AREA:cpufreq_min#$Canvas",
735 "LINE1:cpufreq_avg#$FullBlue:Frequency",
736 'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
737 'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
738 'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
739 'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l'
740 ],
741 users => [
742 'DEF:users_avg={file}:users:AVERAGE',
743 'DEF:users_min={file}:users:MIN',
744 'DEF:users_max={file}:users:MAX',
745 "AREA:users_max#$HalfBlue",
746 "AREA:users_min#$Canvas",
747 "LINE1:users_avg#$FullBlue:Users",
748 'GPRINT:users_min:MIN:%4.1lf Min,',
749 'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
750 'GPRINT:users_max:MAX:%4.1lf Max,',
751 'GPRINT:users_avg:LAST:%4.1lf Last\l'
752 ],
753 voltage => [
754 'DEF:avg={file}:voltage:AVERAGE',
755 'DEF:min={file}:voltage:MIN',
756 'DEF:max={file}:voltage:MAX',
757 "AREA:max#$HalfBlue",
758 "AREA:min#$Canvas",
759 "LINE1:avg#$FullBlue:Voltage",
760 'GPRINT:min:MIN:%5.1lf%sV Min,',
761 'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
762 'GPRINT:max:MAX:%5.1lf%sV Max,',
763 'GPRINT:avg:LAST:%5.1lf%sV Last\l'
764 ],
765 threads => [
766 "DEF:total_avg={file}:total:AVERAGE",
767 "DEF:total_min={file}:total:MIN",
768 "DEF:total_max={file}:total:MAX",
769 "DEF:running_avg={file}:running:AVERAGE",
770 "DEF:running_min={file}:running:MIN",
771 "DEF:running_max={file}:running:MAX",
772 "DEF:uninterruptible_avg={file}:uninterruptible:AVERAGE",
773 "DEF:uninterruptible_min={file}:uninterruptible:MIN",
774 "DEF:uninterruptible_max={file}:uninterruptible:MAX",
775 "DEF:onhold_avg={file}:onhold:AVERAGE",
776 "DEF:onhold_min={file}:onhold:MIN",
777 "DEF:onhold_max={file}:onhold:MAX",
778 "LINE1:total_avg#$FullYellow:Total ",
779 'GPRINT:total_min:MIN:%5.1lf Min,',
780 'GPRINT:total_avg:AVERAGE:%5.1lf Avg.,',
781 'GPRINT:total_max:MAX:%5.1lf Max,',
782 'GPRINT:total_avg:LAST:%5.1lf Last\l',
783 "LINE1:running_avg#$FullRed:Running ",
784 'GPRINT:running_min:MIN:%5.1lf Min,',
785 'GPRINT:running_avg:AVERAGE:%5.1lf Avg.,',
786 'GPRINT:running_max:MAX:%5.1lf Max,',
787 'GPRINT:running_avg:LAST:%5.1lf Last\l',
788 "LINE1:uninterruptible_avg#$FullGreen:Unintr ",
789 'GPRINT:uninterruptible_min:MIN:%5.1lf Min,',
790 'GPRINT:uninterruptible_avg:AVERAGE:%5.1lf Avg.,',
791 'GPRINT:uninterruptible_max:MAX:%5.1lf Max,',
792 'GPRINT:uninterruptible_avg:LAST:%5.1lf Last\l',
793 "LINE1:onhold_avg#$FullBlue:Onhold ",
794 'GPRINT:onhold_min:MIN:%5.1lf Min,',
795 'GPRINT:onhold_avg:AVERAGE:%5.1lf Avg.,',
796 'GPRINT:onhold_max:MAX:%5.1lf Max,',
797 'GPRINT:onhold_avg:LAST:%5.1lf Last\l'
798 ],
799 vs_memory => [
800 'DEF:vm_avg={file}:vm:AVERAGE',
801 'DEF:vm_min={file}:vm:MIN',
802 'DEF:vm_max={file}:vm:MAX',
803 'DEF:vml_avg={file}:vml:AVERAGE',
804 'DEF:vml_min={file}:vml:MIN',
805 'DEF:vml_max={file}:vml:MAX',
806 'DEF:rss_avg={file}:rss:AVERAGE',
807 'DEF:rss_min={file}:rss:MIN',
808 'DEF:rss_max={file}:rss:MAX',
809 'DEF:anon_avg={file}:anon:AVERAGE',
810 'DEF:anon_min={file}:anon:MIN',
811 'DEF:anon_max={file}:anon:MAX',
812 "LINE1:vm_avg#$FullYellow:VM ",
813 'GPRINT:vm_min:MIN:%5.1lf%s Min,',
814 'GPRINT:vm_avg:AVERAGE:%5.1lf%s Avg.,',
815 'GPRINT:vm_max:MAX:%5.1lf%s Avg.,',
816 'GPRINT:vm_avg:LAST:%5.1lf%s Last\l',
817 "LINE1:vml_avg#$FullRed:Locked ",
818 'GPRINT:vml_min:MIN:%5.1lf%s Min,',
819 'GPRINT:vml_avg:AVERAGE:%5.1lf%s Avg.,',
820 'GPRINT:vml_max:MAX:%5.1lf%s Avg.,',
821 'GPRINT:vml_avg:LAST:%5.1lf%s Last\l',
822 "LINE1:rss_avg#$FullGreen:RSS ",
823 'GPRINT:rss_min:MIN:%5.1lf%s Min,',
824 'GPRINT:rss_avg:AVERAGE:%5.1lf%s Avg.,',
825 'GPRINT:rss_max:MAX:%5.1lf%s Avg.,',
826 'GPRINT:rss_avg:LAST:%5.1lf%s Last\l',
827 "LINE1:anon_avg#$FullBlue:Anon. ",
828 'GPRINT:anon_min:MIN:%5.1lf%s Min,',
829 'GPRINT:anon_avg:AVERAGE:%5.1lf%s Avg.,',
830 'GPRINT:anon_max:MAX:%5.1lf%s Avg.,',
831 'GPRINT:anon_avg:LAST:%5.1lf%s Last\l',
832 ],
833 vs_processes => [
834 'DEF:proc_avg={file}:total:AVERAGE',
835 'DEF:proc_min={file}:total:MIN',
836 'DEF:proc_max={file}:total:MAX',
837 "AREA:proc_max#$HalfBlue",
838 "AREA:proc_min#$Canvas",
839 "LINE1:proc_avg#$FullBlue:Processes",
840 'GPRINT:proc_min:MIN:%4.1lf Min,',
841 'GPRINT:proc_avg:AVERAGE:%4.1lf Avg.,',
842 'GPRINT:proc_max:MAX:%4.1lf Max,',
843 'GPRINT:proc_avg:LAST:%4.1lf Last\l'
844 ],
845 };
846 $GraphDefs->{'disk'} = $GraphDefs->{'partition'};
847 $GraphDefs->{'meminfo'} = $GraphDefs->{'memory'};
848 }
850 our $GraphArgs =
851 {
852 apache_bytes => ['-t', 'apache traffic', '-v', 'Bit/s'],
853 apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
854 apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
855 charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
856 cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
857 cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
858 current => ['-t', '{host} current', '-v', 'Ampere'],
859 #disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'],
860 df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'],
861 disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'],
862 hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'],
863 load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'],
864 mails => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'],
865 memory => ['-t', '{host} memory usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
866 mysql_commands => ['-t', 'mysql command {inst}', '-v', 'Issues/s' ],
867 mysql_handler => ['-t', 'mysql handler {inst}', '-v', 'Issues/s' ],
868 mysql_qcache => ['-t', 'mysql query cache', '-v', 'Queries/s' ],
869 mysql_threads => ['-t', 'mysql threads', '-v', 'Threads' ],
870 nfs3_procedures => ['-t', '{host} NFSv3 {inst} procedures', '-v', 'Procedures/s' ],
871 partition => ['-t', '{host} partition {inst} usage', '-v', 'Byte/s'],
872 ping => ['-t', '{host} ping to {inst}', '-v', 'ms'],
873 processes => ['-t', '{host} processes', '-v', 'Processes'],
874 sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'],
875 swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
876 traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'],
877 users => ['-t', '{host} users', '-v', 'Users'],
878 voltage => ['-t', '{host} voltage', '-v', 'Volts'],
879 threads => ['-t', '{host} threads', '-v', 'Threads'],
880 vs_memory => ['-t', '{host} memory usage', '-v', 'Bytes'],
881 vs_processes => ['-t', '{host} processes', '-v', 'Processes'],
882 };
884 our $GraphMulti =
885 {
886 apache_scoreboard => \&output_graph_apache_scoreboard,
887 cpu => \&output_graph_cpu,
888 cpufreq => 1,
889 disk => 1,
890 load => 0,
891 mails => 0,
892 memory => 0,
893 mysql_commands => \&output_graph_mysql_commands,
894 mysql_handler => \&output_graph_mysql_handler,
895 partition => 1,
896 ping => \&output_graph_ping,
897 sensors => 1,
898 traffic => 1,
899 users => 1
900 };
902 our @Info;
903 if (defined ($ENV{'GATEWAY_INTERFACE'}))
904 {
905 @Info = ($ENV{'PATH_INFO'} || '') =~ m#([\w\-\.]+)#g;
906 }
907 else
908 {
909 @Info = @ARGV;
910 }
912 parse_pathinfo (@Info);
914 if ($TimeSpan)
915 {
916 output_graph ();
917 }
918 else
919 {
920 output_page ();
921 }
923 exit (0);
925 sub output_graph_cpu
926 {
927 my @inst = @_;
928 my @ret = ();
930 die if (@inst < 2);
932 for (@inst)
933 {
934 push (@ret,
935 "DEF:user_avg_$_=$AbsDir/cpu-$_.rrd:user:AVERAGE",
936 "DEF:user_min_$_=$AbsDir/cpu-$_.rrd:user:MIN",
937 "DEF:user_max_$_=$AbsDir/cpu-$_.rrd:user:MAX",
938 "DEF:nice_avg_$_=$AbsDir/cpu-$_.rrd:nice:AVERAGE",
939 "DEF:nice_min_$_=$AbsDir/cpu-$_.rrd:nice:MIN",
940 "DEF:nice_max_$_=$AbsDir/cpu-$_.rrd:nice:MAX",
941 "DEF:syst_avg_$_=$AbsDir/cpu-$_.rrd:syst:AVERAGE",
942 "DEF:syst_min_$_=$AbsDir/cpu-$_.rrd:syst:MIN",
943 "DEF:syst_max_$_=$AbsDir/cpu-$_.rrd:syst:MAX",
944 "DEF:wait_avg_$_=$AbsDir/cpu-$_.rrd:wait:AVERAGE",
945 "DEF:wait_min_$_=$AbsDir/cpu-$_.rrd:wait:MIN",
946 "DEF:wait_max_$_=$AbsDir/cpu-$_.rrd:wait:MAX");
947 }
949 for (qw(user nice syst wait))
950 {
951 my $def = $_;
952 my $cdef;
954 my $default_value = ($def eq 'user' or $def eq 'syst') ? 'UNKN' : '0';
956 for (qw(avg min max))
957 {
958 my $cf = $_;
960 for (@inst)
961 {
962 push (@ret, "CDEF:${def}_${cf}_notnull_${_}=${def}_${cf}_${_},UN,0,${def}_${cf}_${_},IF");
963 push (@ret, "CDEF:${def}_${cf}_defined_${_}=${def}_${cf}_${_},UN,0,1,IF");
964 }
966 $cdef = "CDEF:${def}_${cf}_num=" . join (',', map { "${def}_${cf}_defined_${_}" } (@inst));
967 $cdef .= ',+' x (scalar (@inst) - 1);
968 push (@ret, $cdef);
970 $cdef = "CDEF:${def}_${cf}=${def}_${cf}_num," . join (',', map { "${def}_${cf}_notnull_${_}" } (@inst));
971 $cdef .= ',+' x (scalar (@inst) - 1);
972 $cdef .= ",${def}_${cf}_num,${def}_${cf}_num,1,IF,/,$default_value,IF";
973 push (@ret, $cdef);
974 push (@ret, "CDEF:${def}_${cf}_notnull=${def}_${cf},UN,0,${def}_${cf},IF");
975 }
976 }
978 push (@ret,
979 "CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+",
980 "CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+",
981 "CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+",
982 "CDEF:syst_acc=syst_avg_notnull");
984 push (@ret, grep { $_ !~ m/^C?DEF/ } (@{$GraphDefs->{'cpu'}}));
986 return (@ret);
987 }
989 sub output_graph_apache_scoreboard
990 {
991 my @inst = @_;
992 my @ret = ();
994 die if (@inst < 2);
996 my @colors = get_n_colors (scalar (@inst));
998 for (my $i = 0; $i < scalar (@inst); $i++)
999 {
1000 my $inst = $inst[$i];
1001 push (@ret,
1002 "DEF:avg_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:AVERAGE",
1003 "DEF:min_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MIN",
1004 "DEF:max_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MAX");
1005 }
1007 for (my $i = 0; $i < scalar (@inst); $i++)
1008 {
1009 my $inst = $inst[$i];
1010 my $color = $colors[$i];
1012 if (length ($inst) > 15)
1013 {
1014 $inst = substr ($inst, 0, 12) . '...';
1015 }
1016 else
1017 {
1018 $inst = sprintf ('%-15s', $inst);
1019 }
1021 push (@ret,
1022 "LINE1:avg_$i#$color:$inst",
1023 "GPRINT:min_$i:MIN:%6.2lf Min,",
1024 "GPRINT:avg_$i:AVERAGE:%6.2lf Avg,",
1025 "GPRINT:max_$i:MAX:%6.2lf Max,",
1026 "GPRINT:avg_$i:LAST:%6.2lf Last\\l");
1027 }
1029 return (@ret);
1030 }
1032 sub output_graph_ping
1033 {
1034 my @inst = @_;
1035 my @ret = ();
1037 die if (@inst < 2);
1039 my @colors = get_n_colors (scalar (@inst));
1041 for (my $i = 0; $i < scalar (@inst); $i++)
1042 {
1043 my $inst = $inst[$i];
1044 push (@ret,
1045 "DEF:avg_$i=$AbsDir/ping-$inst.rrd:ping:AVERAGE",
1046 "DEF:min_$i=$AbsDir/ping-$inst.rrd:ping:MIN",
1047 "DEF:max_$i=$AbsDir/ping-$inst.rrd:ping:MAX");
1048 }
1050 for (my $i = 0; $i < scalar (@inst); $i++)
1051 {
1052 my $inst = $inst[$i];
1053 my $color = $colors[$i];
1055 if (length ($inst) > 15)
1056 {
1057 $inst = substr ($inst, 0, 12) . '...';
1058 }
1059 else
1060 {
1061 $inst = sprintf ('%-15s', $inst);
1062 }
1064 push (@ret,
1065 "LINE1:avg_$i#$color:$inst",
1066 "GPRINT:min_$i:MIN:%4.1lf ms Min,",
1067 "GPRINT:avg_$i:AVERAGE:%4.1lf ms Avg,",
1068 "GPRINT:max_$i:MAX:%4.1lf ms Max,",
1069 "GPRINT:avg_$i:LAST:%4.1lf ms Last\\l");
1070 }
1072 return (@ret);
1073 }
1075 sub output_graph_mysql_commands
1076 {
1077 my @inst = @_;
1078 my @ret = ();
1080 die if (@inst < 2);
1082 my @colors = get_n_colors (scalar (@inst));
1084 for (my $i = 0; $i < scalar (@inst); $i++)
1085 {
1086 my $inst = $inst[$i];
1087 push (@ret,
1088 "DEF:avg_$i=$AbsDir/mysql_commands-$inst.rrd:value:AVERAGE",
1089 "DEF:min_$i=$AbsDir/mysql_commands-$inst.rrd:value:MIN",
1090 "DEF:max_$i=$AbsDir/mysql_commands-$inst.rrd:value:MAX");
1091 }
1093 for (my $i = 0; $i < scalar (@inst); $i++)
1094 {
1095 my $inst = $inst[$i];
1096 my $color = $colors[$i];
1098 if (length ($inst) > 18)
1099 {
1100 $inst = substr ($inst, 0, 15) . '...';
1101 }
1102 else
1103 {
1104 $inst = sprintf ('%-18s', $inst);
1105 }
1107 push (@ret,
1108 "LINE1:avg_$i#$color:$inst",
1109 "GPRINT:min_$i:MIN:%6.1lf Min,",
1110 "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1111 "GPRINT:max_$i:MAX:%6.1lf Max,",
1112 "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1113 }
1115 return (@ret);
1116 }
1118 sub output_graph_mysql_handler
1119 {
1120 my @inst = @_;
1121 my @ret = ();
1123 die if (@inst < 2);
1125 my @colors = get_n_colors (scalar (@inst));
1127 for (my $i = 0; $i < scalar (@inst); $i++)
1128 {
1129 my $inst = $inst[$i];
1130 push (@ret,
1131 "DEF:avg_$i=$AbsDir/mysql_handler-$inst.rrd:value:AVERAGE",
1132 "DEF:min_$i=$AbsDir/mysql_handler-$inst.rrd:value:MIN",
1133 "DEF:max_$i=$AbsDir/mysql_handler-$inst.rrd:value:MAX");
1134 }
1136 for (my $i = 0; $i < scalar (@inst); $i++)
1137 {
1138 my $inst = $inst[$i];
1139 my $color = $colors[$i];
1141 if (length ($inst) > 18)
1142 {
1143 $inst = substr ($inst, 0, 15) . '...';
1144 }
1145 else
1146 {
1147 $inst = sprintf ('%-18s', $inst);
1148 }
1150 push (@ret,
1151 "LINE1:avg_$i#$color:$inst",
1152 "GPRINT:min_$i:MIN:%6.1lf Min,",
1153 "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1154 "GPRINT:max_$i:MAX:%6.1lf Max,",
1155 "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1156 }
1158 return (@ret);
1159 }
1161 sub output_graph
1162 {
1163 die unless (defined ($GraphDefs->{$Type}));
1165 my $host;
1166 my @cmd = ();
1167 my $file = $AbsDir . '/';
1168 my $files = get_all_files ($AbsDir);
1170 #
1171 # get hostname
1172 #
1173 if ($RelDir =~ m#([^/]+)$#)
1174 {
1175 $host = $1;
1176 }
1177 else
1178 {
1179 $host = $Config->{'HostName'};
1180 }
1182 #
1183 # get timespan
1184 #
1185 if ($TimeSpan =~ m/(\d+)/)
1186 {
1187 $TimeSpan = -1 * int ($1);
1188 }
1189 else
1190 {
1191 my %t = (hour => -3600, day => -86400, week => -604800, month => -2678400, year => -31622400);
1192 die unless (defined ($t{$TimeSpan}));
1193 $TimeSpan = $t{$TimeSpan};
1194 }
1196 if (scalar (@{$files->{$Type}}) == 1)
1197 {
1198 $Inst = $files->{$Type}[0];
1199 }
1201 #push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan, '-w', 800, '-h', 150);
1202 push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan);
1203 push (@cmd, @{$GraphArgs->{$Type}}) if (defined ($GraphArgs->{$Type}));
1205 for (qw(Back ShadeA ShadeB Font Canvas Grid MGrid Frame Arrow))
1206 {
1207 push (@cmd, '-c', uc ($_) . '#' . $Config->{'Colors'}{$_});
1208 }
1210 if ((length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE'))
1211 {
1212 push (@cmd, $GraphMulti->{$Type}->(@{$files->{$Type}}));
1213 }
1214 else
1215 {
1216 if (length ("$Inst"))
1217 {
1218 $file .= "$Type-$Inst.rrd";
1219 }
1220 else
1221 {
1222 $file .= "$Type.rrd";
1223 }
1225 die ("File not found: $file") unless (-e $file);
1227 push (@cmd, @{$GraphDefs->{$Type}});
1228 }
1230 for (@cmd)
1231 {
1232 $_ =~ s/{file}/$file/g;
1233 $_ =~ s/{host}/$host/g;
1234 $_ =~ s/{inst}/$Inst/g;
1235 $_ =~ s/{type}/$Type/g;
1236 }
1238 $| = 1;
1240 print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1241 Content-Type: image/png
1242 Cache-Control: no-cache
1244 HEADER
1246 if (1)
1247 {
1248 my $fh;
1249 open ($fh, ">/tmp/collection.log") or die ("open: $!");
1250 flock ($fh, LOCK_EX) or die ("flock: $!");
1252 print $fh join ("\n\t", @cmd) . "\n";
1254 close ($fh);
1255 }
1257 RRDs::graph (@cmd);
1259 die ('RRDs::error: ' . RRDs::error ()) if (RRDs::error ());
1260 }
1262 sub output_page
1263 {
1264 my $files = get_all_files ($AbsDir);
1265 my $dirs = get_all_dirs ($AbsDir);
1267 print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1268 Content-Type: text/html
1269 Cache-Control: no-cache
1271 <html>
1272 <head>
1273 <title>Collection: $RelDir</title>
1274 <style type="text/css">
1275 img { border: none; display: block; }
1276 </style>
1277 </head>
1279 <body>
1280 HEADER
1282 my $MySelf = defined ($ENV{'GATEWAY_INTERFACE'}) ? $ENV{'SCRIPT_NAME'} : $0;
1284 if ((length ($Type) != 0) and (length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1285 {
1286 print qq(\t\t<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1288 print "\t\t<ul>\n";
1289 for (@{$files->{$Type}})
1290 {
1291 print qq(\t\t\t<li><a href="$MySelf$RelDir/$Type/$_">$_</a></li>\n);
1292 }
1293 print <<HTML;
1294 </ul>
1296 <h3>Hourly</h3>
1297 <div><img src="$MySelf$RelDir/$Type/hour" /></div>
1298 <h3>Daily</h3>
1299 <div><img src="$MySelf$RelDir/$Type/day" /></div>
1300 <h3>Weekly</h3>
1301 <div><img src="$MySelf$RelDir/$Type/week" /></div>
1302 <h3>Monthly</h3>
1303 <div><img src="$MySelf$RelDir/$Type/month" /></div>
1304 <h3>Yearly</h3>
1305 <div><img src="$MySelf$RelDir/$Type/year" /></div>
1306 HTML
1307 }
1308 elsif (length ($Type) != 0)
1309 {
1310 my $ext = length ($Inst) ? "$Type/$Inst" : $Type;
1312 if ((ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1313 {
1314 print qq(<div><a href="$MySelf$RelDir/$Type">Go up</a></div>\n);
1315 }
1316 else
1317 {
1318 print qq(<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1319 }
1321 print <<HTML;
1322 <h3>Hourly</h3>
1323 <div><img src="$MySelf$RelDir/$ext/hour" /></div>
1324 <h3>Daily</h3>
1325 <div><img src="$MySelf$RelDir/$ext/day" /></div>
1326 <h3>Weekly</h3>
1327 <div><img src="$MySelf$RelDir/$ext/week" /></div>
1328 <h3>Monthly</h3>
1329 <div><img src="$MySelf$RelDir/$ext/month" /></div>
1330 <h3>Yearly</h3>
1331 <div><img src="$MySelf$RelDir/$ext/year" /></div>
1332 HTML
1333 }
1334 else
1335 {
1336 if ($RelDir)
1337 {
1338 my ($up) = $RelDir =~ m#(.*)/[^/]+$#;
1339 print qq(\t\t<div><a href="$MySelf$up">Go up</a></div>\n);
1340 }
1342 if (@$dirs)
1343 {
1344 print "<ul>\n";
1345 for (@$dirs)
1346 {
1347 print qq(<li>$AbsDir/<a href="$MySelf$RelDir/$_">$_</a></li>\n);
1348 }
1349 print "</ul>\n";
1350 }
1352 for (sort (keys %$files))
1353 {
1354 my $type = $_;
1356 if (ref ($GraphMulti->{$type}) eq 'CODE')
1357 {
1358 print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1359 qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1360 next;
1361 }
1363 for (@{$files->{$type}})
1364 {
1365 my $inst = "$_";
1367 if (length ($inst))
1368 {
1369 print qq(\t\t<a href="$MySelf$RelDir/$type/$inst" />),
1370 qq(<img src="$MySelf$RelDir/$type/$inst/day" /></a>\n);
1371 }
1372 else
1373 {
1374 print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1375 qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1376 }
1377 }
1378 }
1379 }
1381 print STDOUT <<FOOTER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1382 </body>
1383 </html>
1384 FOOTER
1385 }
1387 sub output_xml
1388 {
1389 my $files = get_all_files ();
1391 print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1392 Content-Type: text/xml
1393 Cache-Control: no-cache
1395 HEADER
1396 print STDOUT pl2xml ($files);
1397 }
1399 sub read_config
1400 {
1401 my $file = @_ ? shift : '/etc/collection.conf';
1402 my $conf;
1403 my $fh;
1405 # if (open ($fh, "< $file"))
1406 # {
1407 # my $xml;
1408 # local $/ = undef;
1409 # $xml = <$fh>;
1410 #
1411 # eval
1412 # {
1413 # $conf = xml2pl ($xml);
1414 # };
1415 # close ($fh);
1416 # }
1418 if (!$conf)
1419 {
1420 return ({
1421 Colors =>
1422 {
1423 Back => 'FFFFFF',
1424 ShadeA => 'FFFFFF',
1425 ShadeB => 'FFFFFF',
1426 Font => '000000',
1427 Canvas => 'F5F5F5',
1428 Grid => 'D0D0D0',
1429 MGrid => 'A0A0A0',
1430 Frame => '646464',
1431 Arrow => 'FF0000',
1433 FullRed => 'FF0000',
1434 FullBlue => '0000FF',
1435 FullGreen => '00E000',
1436 FullYellow => 'F0A000',
1437 FullCyan => '00A0FF',
1438 FullMagenta => 'A000FF',
1439 Alpha => 0.25,
1440 HalfRed => 'F8B8B8',
1441 HalfBlue => 'B8B8F8',
1442 HalfGreen => 'B8F0B8',
1443 HalfYellow => 'F4F4B8'
1444 },
1445 Directory => '/var/lib/collectd',
1446 HostName => (defined ($ENV{'SERVER_NAME'}) ? $ENV{'SERVER_NAME'} : 'localhost')
1447 });
1448 }
1449 else
1450 {
1451 return ($conf);
1452 }
1453 }
1455 sub parse_pathinfo
1456 {
1457 my @info = @_;
1459 $AbsDir = $Config->{'Directory'};
1460 $RelDir = '';
1462 while (@info and -d $AbsDir . '/' . $Info[0])
1463 {
1464 my $new = shift (@info);
1465 next if ($new =~ m/^\./);
1467 $AbsDir .= '/' . $new;
1468 $RelDir .= '/' . $new;
1469 }
1471 $Type = '';
1472 $Inst = '';
1473 $TimeSpan = '';
1475 confess ("parse_pathinfo: too many elements in pathinfo") if (scalar (@info) > 3);
1476 return unless (@info);
1478 $Type = shift (@info);
1479 return unless (@info);
1481 if ($info[-1] =~ m/^(hour|day|week|month|year)$/i)
1482 {
1483 $TimeSpan = pop (@info);
1484 }
1486 $Inst = shift (@info) if (@info);
1488 confess ("unrecognized elements in pathinfo") if (@info);
1489 }
1491 sub get_all_files
1492 {
1493 my $dir = @_ ? shift : $Config->{'Directory'};
1494 my $hash = {};
1495 my $dh;
1497 if (opendir ($dh, $dir))
1498 {
1499 while (my $thing = readdir ($dh))
1500 {
1501 next if ($thing =~ m/^\./);
1503 my $type;
1504 my $inst;
1506 if ($thing =~ m/^(\w+)-([\w\-\.]+)\.rrd$/)
1507 {
1508 $type = $1;
1509 $inst = $2;
1510 }
1511 elsif ($thing =~ m/^(\w+)\.rrd$/)
1512 {
1513 $type = $1;
1514 $inst = '';
1515 }
1516 else
1517 {
1518 next;
1519 }
1521 # Only load RRD files we can actually display..
1522 next unless (defined ($GraphDefs->{$type}));
1524 $hash->{$type} = [] unless (defined ($hash->{$type}));
1525 push (@{$hash->{$type}}, $inst);
1526 }
1528 closedir ($dh);
1529 }
1531 return ($hash);
1532 }
1534 sub get_all_dirs
1535 {
1536 my $dir = @_ ? shift : $Config->{'Directory'};
1537 my @ret = ();
1538 my $dh;
1540 if (opendir ($dh, $dir))
1541 {
1542 while (my $thing = readdir ($dh))
1543 {
1544 next if ($thing =~ m/^\./);
1546 next if (!-d "$dir/$thing");
1548 push (@ret, $thing);
1549 }
1551 closedir ($dh);
1552 }
1554 return (@ret) if (wantarray ());
1555 return (\@ret);
1556 }
1558 sub color_hex2rgb
1559 {
1560 my $color = shift;
1562 my ($red, $green, $blue) = map { ord (pack ("H2", $_)) } ($color =~ m/([A-Fa-f0-9]{2})/g);
1563 #print STDERR "$color -> rgb($red,$green,$blue)\n";
1565 return ($red, $green, $blue);
1566 }
1568 sub color_rgb2hex
1569 {
1570 croak unless (scalar (@_) == 3);
1572 my ($red, $green, $blue) = @_;
1574 my $ret = sprintf ("%02X%02X%02X", $red, $green, $blue);
1575 #print STDERR "rgb($red,$green,$blue) -> $ret\n";
1577 return ($ret);
1578 }
1580 sub color_calculate_transparent
1581 {
1582 my $alpha = shift;
1583 my $canvas = [color_hex2rgb (shift)];
1584 my @colors = map { [color_hex2rgb ($_)] } (@_);
1586 if (($alpha < 0.0) or ($alpha > 1.0))
1587 {
1588 $alpha = 1.0;
1589 }
1591 if ($alpha == 0.0)
1592 {
1593 return (color_rgb2hex (@$canvas));
1594 }
1595 if ($alpha == 1.0)
1596 {
1597 return (color_rgb2hex (@{$colors[-1]}));
1598 }
1600 my $ret = _color_calculate_transparent ($alpha, $canvas, @colors);
1602 return (color_rgb2hex (@$ret));
1603 }
1605 sub _color_calculate_transparent
1606 {
1607 my $alpha = shift;
1608 my $canvas = shift;
1609 my $color = shift;
1610 my @colors = @_ ? shift : ();
1611 my $ret = [0, 0, 0];
1613 for (my $i = 0; $i < 3; $i++)
1614 {
1615 $ret->[$i] = ($alpha * $color->[$i]) + ((1 - $alpha) * $canvas->[$i]);
1616 }
1618 return (_color_calculate_transparent ($alpha, $ret, @colors)) if (@colors);
1619 return ($ret);
1620 }
1622 sub get_n_colors
1623 {
1624 my $num = shift;
1625 my @ret = ();
1627 for (my $i = 0; $i < $num; $i++)
1628 {
1629 my $pos = 6 * $i / $num;
1630 my $n = int ($pos);
1631 my $p = $pos - $n;
1632 my $q = 1 - $p;
1634 my $red = 0;
1635 my $green = 0;
1636 my $blue = 0;
1638 if ($n == 0)
1639 {
1640 $red = 255;
1641 $blue = 255 * $p;
1642 }
1643 elsif ($n == 1)
1644 {
1645 $red = 255 * $q;
1646 $blue = 255;
1647 }
1648 elsif ($n == 2)
1649 {
1650 $green = 255 * $p;
1651 $blue = 255;
1652 }
1653 elsif ($n == 3)
1654 {
1655 $green = 255;
1656 $blue = 255 * $q;
1657 }
1658 elsif ($n == 4)
1659 {
1660 $red = 255 * $p;
1661 $green = 255;
1662 }
1663 elsif ($n == 5)
1664 {
1665 $red = 255;
1666 $green = 255 * $q;
1667 }
1668 else { die; }
1670 push (@ret, sprintf ("%02x%02x%02x", $red, $green, $blue));
1671 }
1673 return (@ret);
1674 }