Code

Improved the graphs generated for the apache-RRDs.
[collectd.git] / contrib / collection.cgi
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'};
53         
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:free_cached_buffers_used=free_avg,cached_avg,+,buffers_avg,+,used_avg,+',
307                         'CDEF:cached_buffers_used=cached_avg,buffers_avg,+,used_avg,+',
308                         'CDEF:buffers_used=buffers_avg,used_avg,+',
309                         "AREA:free_cached_buffers_used#$HalfGreen",
310                         "AREA:cached_buffers_used#$HalfBlue",
311                         "AREA:buffers_used#$HalfYellow",
312                         "AREA:used_avg#$HalfRed",
313                         "LINE1:free_cached_buffers_used#$FullGreen:Free        ",
314                         'GPRINT:free_min:MIN:%5.1lf%s Min,',
315                         'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
316                         'GPRINT:free_max:MAX:%5.1lf%s Max,',
317                         'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
318                         "LINE1:cached_buffers_used#$FullBlue:Page cache  ",
319                         'GPRINT:cached_min:MIN:%5.1lf%s Min,',
320                         'GPRINT:cached_avg:AVERAGE:%5.1lf%s Avg,',
321                         'GPRINT:cached_max:MAX:%5.1lf%s Max,',
322                         'GPRINT:cached_avg:LAST:%5.1lf%s Last\n',
323                         "LINE1:buffers_used#$FullYellow:Buffer cache",
324                         'GPRINT:buffers_min:MIN:%5.1lf%s Min,',
325                         'GPRINT:buffers_avg:AVERAGE:%5.1lf%s Avg,',
326                         'GPRINT:buffers_max:MAX:%5.1lf%s Max,',
327                         'GPRINT:buffers_avg:LAST:%5.1lf%s Last\n',
328                         "LINE1:used_avg#$FullRed:Used        ",
329                         'GPRINT:used_min:MIN:%5.1lf%s Min,',
330                         'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
331                         'GPRINT:used_max:MAX:%5.1lf%s Max,',
332                         'GPRINT:used_avg:LAST:%5.1lf%s Last'
333                 ],
334                 mysql_commands => [
335                         "DEF:val_avg={file}:value:AVERAGE",
336                         "DEF:val_min={file}:value:MIN",
337                         "DEF:val_max={file}:value:MAX",
338                         "AREA:val_max#$HalfBlue",
339                         "AREA:val_min#$Canvas",
340                         "LINE1:val_avg#$FullBlue:{inst}",
341                         'GPRINT:val_min:MIN:%5.2lf Min,',
342                         'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
343                         'GPRINT:val_max:MAX:%5.2lf Max,',
344                         'GPRINT:val_avg:LAST:%5.2lf Last'
345                 ],
346                 mysql_handler => [
347                         "DEF:val_avg={file}:value:AVERAGE",
348                         "DEF:val_min={file}:value:MIN",
349                         "DEF:val_max={file}:value:MAX",
350                         "AREA:val_max#$HalfBlue",
351                         "AREA:val_min#$Canvas",
352                         "LINE1:val_avg#$FullBlue:{inst}",
353                         'GPRINT:val_min:MIN:%5.2lf Min,',
354                         'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
355                         'GPRINT:val_max:MAX:%5.2lf Max,',
356                         'GPRINT:val_avg:LAST:%5.2lf Last'
357                 ],
358                 mysql_qcache => [
359                         "DEF:hits_min={file}:hits:MIN",
360                         "DEF:hits_avg={file}:hits:AVERAGE",
361                         "DEF:hits_max={file}:hits:MAX",
362                         "DEF:inserts_min={file}:inserts:MIN",
363                         "DEF:inserts_avg={file}:inserts:AVERAGE",
364                         "DEF:inserts_max={file}:inserts:MAX",
365                         "DEF:not_cached_min={file}:not_cached:MIN",
366                         "DEF:not_cached_avg={file}:not_cached:AVERAGE",
367                         "DEF:not_cached_max={file}:not_cached:MAX",
368                         "DEF:lowmem_prunes_min={file}:lowmem_prunes:MIN",
369                         "DEF:lowmem_prunes_avg={file}:lowmem_prunes:AVERAGE",
370                         "DEF:lowmem_prunes_max={file}:lowmem_prunes:MAX",
371                         "DEF:queries_min={file}:queries_in_cache:MIN",
372                         "DEF:queries_avg={file}:queries_in_cache:AVERAGE",
373                         "DEF:queries_max={file}:queries_in_cache:MAX",
374                         "CDEF:unknown=queries_avg,UNKN,+",
375                         "CDEF:not_cached_agg=hits_avg,inserts_avg,+,not_cached_avg,+",
376                         "CDEF:inserts_agg=hits_avg,inserts_avg,+",
377                         "CDEF:hits_agg=hits_avg",
378                         "AREA:not_cached_agg#$HalfYellow",
379                         "AREA:inserts_agg#$HalfBlue",
380                         "AREA:hits_agg#$HalfGreen",
381                         "LINE1:not_cached_agg#$FullYellow:Not Cached      ",
382                         'GPRINT:not_cached_min:MIN:%5.2lf Min,',
383                         'GPRINT:not_cached_avg:AVERAGE:%5.2lf Avg,',
384                         'GPRINT:not_cached_max:MAX:%5.2lf Max,',
385                         'GPRINT:not_cached_avg:LAST:%5.2lf Last\l',
386                         "LINE1:inserts_agg#$FullBlue:Inserts         ",
387                         'GPRINT:inserts_min:MIN:%5.2lf Min,',
388                         'GPRINT:inserts_avg:AVERAGE:%5.2lf Avg,',
389                         'GPRINT:inserts_max:MAX:%5.2lf Max,',
390                         'GPRINT:inserts_avg:LAST:%5.2lf Last\l',
391                         "LINE1:hits_agg#$FullGreen:Hits            ",
392                         'GPRINT:hits_min:MIN:%5.2lf Min,',
393                         'GPRINT:hits_avg:AVERAGE:%5.2lf Avg,',
394                         'GPRINT:hits_max:MAX:%5.2lf Max,',
395                         'GPRINT:hits_avg:LAST:%5.2lf Last\l',
396                         "LINE1:lowmem_prunes_avg#$FullRed:Lowmem Prunes   ",
397                         'GPRINT:lowmem_prunes_min:MIN:%5.2lf Min,',
398                         'GPRINT:lowmem_prunes_avg:AVERAGE:%5.2lf Avg,',
399                         'GPRINT:lowmem_prunes_max:MAX:%5.2lf Max,',
400                         'GPRINT:lowmem_prunes_avg:LAST:%5.2lf Last\l',
401                         "LINE1:unknown#$Canvas:Queries in cache",
402                         'GPRINT:queries_min:MIN:%5.0lf Min,',
403                         'GPRINT:queries_avg:AVERAGE:%5.0lf Avg,',
404                         'GPRINT:queries_max:MAX:%5.0lf Max,',
405                         'GPRINT:queries_avg:LAST:%5.0lf Last\l'
406                 ],
407                 mysql_threads => [
408                         "DEF:running_min={file}:running:MIN",
409                         "DEF:running_avg={file}:running:AVERAGE",
410                         "DEF:running_max={file}:running:MAX",
411                         "DEF:connected_min={file}:connected:MIN",
412                         "DEF:connected_avg={file}:connected:AVERAGE",
413                         "DEF:connected_max={file}:connected:MAX",
414                         "DEF:cached_min={file}:cached:MIN",
415                         "DEF:cached_avg={file}:cached:AVERAGE",
416                         "DEF:cached_max={file}:cached:MAX",
417                         "DEF:created_min={file}:created:MIN",
418                         "DEF:created_avg={file}:created:AVERAGE",
419                         "DEF:created_max={file}:created:MAX",
420                         "CDEF:unknown=created_avg,UNKN,+",
421                         "CDEF:cached_agg=connected_avg,cached_avg,+",
422                         "AREA:cached_agg#$HalfGreen",
423                         "AREA:connected_avg#$HalfBlue",
424                         "AREA:running_avg#$HalfRed",
425                         "LINE1:cached_agg#$FullGreen:Cached   ",
426                         'GPRINT:cached_min:MIN:%5.1lf Min,',
427                         'GPRINT:cached_avg:AVERAGE:%5.1lf Avg,',
428                         'GPRINT:cached_max:MAX:%5.1lf Max,',
429                         'GPRINT:cached_avg:LAST:%5.1lf Last\l',
430                         "LINE1:connected_avg#$FullBlue:Connected",
431                         'GPRINT:connected_min:MIN:%5.1lf Min,',
432                         'GPRINT:connected_avg:AVERAGE:%5.1lf Avg,',
433                         'GPRINT:connected_max:MAX:%5.1lf Max,',
434                         'GPRINT:connected_avg:LAST:%5.1lf Last\l',
435                         "LINE1:running_avg#$FullRed:Running  ",
436                         'GPRINT:running_min:MIN:%5.1lf Min,',
437                         'GPRINT:running_avg:AVERAGE:%5.1lf Avg,',
438                         'GPRINT:running_max:MAX:%5.1lf Max,',
439                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
440                         "LINE1:unknown#$Canvas:Created  ",
441                         'GPRINT:created_min:MIN:%5.0lf Min,',
442                         'GPRINT:created_avg:AVERAGE:%5.0lf Avg,',
443                         'GPRINT:created_max:MAX:%5.0lf Max,',
444                         'GPRINT:created_avg:LAST:%5.0lf Last\l'
445                 ],
446                 nfs3_procedures => [
447                         "DEF:null_avg={file}:null:AVERAGE",
448                         "DEF:getattr_avg={file}:getattr:AVERAGE",
449                         "DEF:setattr_avg={file}:setattr:AVERAGE",
450                         "DEF:lookup_avg={file}:lookup:AVERAGE",
451                         "DEF:access_avg={file}:access:AVERAGE",
452                         "DEF:readlink_avg={file}:readlink:AVERAGE",
453                         "DEF:read_avg={file}:read:AVERAGE",
454                         "DEF:write_avg={file}:write:AVERAGE",
455                         "DEF:create_avg={file}:create:AVERAGE",
456                         "DEF:mkdir_avg={file}:mkdir:AVERAGE",
457                         "DEF:symlink_avg={file}:symlink:AVERAGE",
458                         "DEF:mknod_avg={file}:mknod:AVERAGE",
459                         "DEF:remove_avg={file}:remove:AVERAGE",
460                         "DEF:rmdir_avg={file}:rmdir:AVERAGE",
461                         "DEF:rename_avg={file}:rename:AVERAGE",
462                         "DEF:link_avg={file}:link:AVERAGE",
463                         "DEF:readdir_avg={file}:readdir:AVERAGE",
464                         "DEF:readdirplus_avg={file}:readdirplus:AVERAGE",
465                         "DEF:fsstat_avg={file}:fsstat:AVERAGE",
466                         "DEF:fsinfo_avg={file}:fsinfo:AVERAGE",
467                         "DEF:pathconf_avg={file}:pathconf:AVERAGE",
468                         "DEF:commit_avg={file}:commit:AVERAGE",
469                         "DEF:null_max={file}:null:MAX",
470                         "DEF:getattr_max={file}:getattr:MAX",
471                         "DEF:setattr_max={file}:setattr:MAX",
472                         "DEF:lookup_max={file}:lookup:MAX",
473                         "DEF:access_max={file}:access:MAX",
474                         "DEF:readlink_max={file}:readlink:MAX",
475                         "DEF:read_max={file}:read:MAX",
476                         "DEF:write_max={file}:write:MAX",
477                         "DEF:create_max={file}:create:MAX",
478                         "DEF:mkdir_max={file}:mkdir:MAX",
479                         "DEF:symlink_max={file}:symlink:MAX",
480                         "DEF:mknod_max={file}:mknod:MAX",
481                         "DEF:remove_max={file}:remove:MAX",
482                         "DEF:rmdir_max={file}:rmdir:MAX",
483                         "DEF:rename_max={file}:rename:MAX",
484                         "DEF:link_max={file}:link:MAX",
485                         "DEF:readdir_max={file}:readdir:MAX",
486                         "DEF:readdirplus_max={file}:readdirplus:MAX",
487                         "DEF:fsstat_max={file}:fsstat:MAX",
488                         "DEF:fsinfo_max={file}:fsinfo:MAX",
489                         "DEF:pathconf_max={file}:pathconf:MAX",
490                         "DEF:commit_max={file}:commit:MAX",
491                         "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
492                         "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
493                         "CDEF:stack_read=read_avg",
494                         "CDEF:stack_getattr=stack_read,getattr_avg,+",
495                         "CDEF:stack_access=stack_getattr,access_avg,+",
496                         "CDEF:stack_lookup=stack_access,lookup_avg,+",
497                         "CDEF:stack_write=stack_lookup,write_avg,+",
498                         "CDEF:stack_commit=stack_write,commit_avg,+",
499                         "CDEF:stack_setattr=stack_commit,setattr_avg,+",
500                         "CDEF:stack_other=stack_setattr,other_avg,+",
501                         "AREA:stack_other#$HalfRed",
502                         "AREA:stack_setattr#$HalfGreen",
503                         "AREA:stack_commit#$HalfYellow",
504                         "AREA:stack_write#$HalfGreen",
505                         "AREA:stack_lookup#$HalfBlue",
506                         "AREA:stack_access#$HalfMagenta",
507                         "AREA:stack_getattr#$HalfCyan",
508                         "AREA:stack_read#$HalfBlue",
509                         "LINE1:stack_other#$FullRed:Other  ",
510                         'GPRINT:other_max:MAX:%5.1lf Max,',
511                         'GPRINT:other_avg:AVERAGE:%5.1lf Avg,',
512                         'GPRINT:other_avg:LAST:%5.1lf Last\l',
513                         "LINE1:stack_setattr#$FullGreen:setattr",
514                         'GPRINT:setattr_max:MAX:%5.1lf Max,',
515                         'GPRINT:setattr_avg:AVERAGE:%5.1lf Avg,',
516                         'GPRINT:setattr_avg:LAST:%5.1lf Last\l',
517                         "LINE1:stack_commit#$FullYellow:commit ",
518                         'GPRINT:commit_max:MAX:%5.1lf Max,',
519                         'GPRINT:commit_avg:AVERAGE:%5.1lf Avg,',
520                         'GPRINT:commit_avg:LAST:%5.1lf Last\l',
521                         "LINE1:stack_write#$FullGreen:write  ",
522                         'GPRINT:write_max:MAX:%5.1lf Max,',
523                         'GPRINT:write_avg:AVERAGE:%5.1lf Avg,',
524                         'GPRINT:write_avg:LAST:%5.1lf Last\l',
525                         "LINE1:stack_lookup#$FullBlue:lookup ",
526                         'GPRINT:lookup_max:MAX:%5.1lf Max,',
527                         'GPRINT:lookup_avg:AVERAGE:%5.1lf Avg,',
528                         'GPRINT:lookup_avg:LAST:%5.1lf Last\l',
529                         "LINE1:stack_access#$FullMagenta:access ",
530                         'GPRINT:access_max:MAX:%5.1lf Max,',
531                         'GPRINT:access_avg:AVERAGE:%5.1lf Avg,',
532                         'GPRINT:access_avg:LAST:%5.1lf Last\l',
533                         "LINE1:stack_getattr#$FullCyan:getattr",
534                         'GPRINT:getattr_max:MAX:%5.1lf Max,',
535                         'GPRINT:getattr_avg:AVERAGE:%5.1lf Avg,',
536                         'GPRINT:getattr_avg:LAST:%5.1lf Last\l',
537                         "LINE1:stack_read#$FullBlue:read   ",
538                         'GPRINT:read_max:MAX:%5.1lf Max,',
539                         'GPRINT:read_avg:AVERAGE:%5.1lf Avg,',
540                         'GPRINT:read_avg:LAST:%5.1lf Last\l'
541                 ],
542                 partition => [
543                         "DEF:rbyte_avg={file}:rbytes:AVERAGE",
544                         "DEF:rbyte_min={file}:rbytes:MIN",
545                         "DEF:rbyte_max={file}:rbytes:MAX",
546                         "DEF:wbyte_avg={file}:wbytes:AVERAGE",
547                         "DEF:wbyte_min={file}:wbytes:MIN",
548                         "DEF:wbyte_max={file}:wbytes:MAX",
549                         'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
550                         "AREA:wbyte_avg#$HalfGreen",
551                         "AREA:rbyte_avg#$HalfBlue",
552                         "AREA:overlap#$HalfBlueGreen",
553                         "LINE1:wbyte_avg#$FullGreen:Write",
554                         'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
555                         'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
556                         'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
557                         'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
558                         "LINE1:rbyte_avg#$FullBlue:Read ",
559                         'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
560                         'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
561                         'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
562                         'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l'
563                 ],
564                 ping => ['DEF:ping_avg={file}:ping:AVERAGE',
565                         'DEF:ping_min={file}:ping:MIN',
566                         'DEF:ping_max={file}:ping:MAX',
567                         "AREA:ping_max#$HalfBlue",
568                         "AREA:ping_min#$Canvas",
569                         "LINE1:ping_avg#$FullBlue:Ping",
570                         'GPRINT:ping_min:MIN:%4.1lf ms Min,',
571                         'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
572                         'GPRINT:ping_max:MAX:%4.1lf ms Max,',
573                         'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
574                 processes => [
575                         "DEF:running_avg={file}:running:AVERAGE",
576                         "DEF:running_min={file}:running:MIN",
577                         "DEF:running_max={file}:running:MAX",
578                         "DEF:sleeping_avg={file}:sleeping:AVERAGE",
579                         "DEF:sleeping_min={file}:sleeping:MIN",
580                         "DEF:sleeping_max={file}:sleeping:MAX",
581                         "DEF:zombies_avg={file}:zombies:AVERAGE",
582                         "DEF:zombies_min={file}:zombies:MIN",
583                         "DEF:zombies_max={file}:zombies:MAX",
584                         "DEF:stopped_avg={file}:stopped:AVERAGE",
585                         "DEF:stopped_min={file}:stopped:MIN",
586                         "DEF:stopped_max={file}:stopped:MAX",
587                         "DEF:paging_avg={file}:paging:AVERAGE",
588                         "DEF:paging_min={file}:paging:MIN",
589                         "DEF:paging_max={file}:paging:MAX",
590                         "DEF:blocked_avg={file}:blocked:AVERAGE",
591                         "DEF:blocked_min={file}:blocked:MIN",
592                         "DEF:blocked_max={file}:blocked:MAX",
593                         'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
594                         'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
595                         'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
596                         'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
597                         'CDEF:running_acc=sleeping_avg,running_avg,+',
598                         'CDEF:sleeping_acc=sleeping_avg',
599                         "AREA:paging_acc#$HalfYellow",
600                         "AREA:blocked_acc#$HalfCyan",
601                         "AREA:zombies_acc#$HalfRed",
602                         "AREA:stopped_acc#$HalfMagenta",
603                         "AREA:running_acc#$HalfGreen",
604                         "AREA:sleeping_acc#$HalfBlue",
605                         "LINE1:paging_acc#$FullYellow:Paging  ",
606                         'GPRINT:paging_min:MIN:%5.1lf Min,',
607                         'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
608                         'GPRINT:paging_max:MAX:%5.1lf Max,',
609                         'GPRINT:paging_avg:LAST:%5.1lf Last\l',
610                         "LINE1:blocked_acc#$FullCyan:Blocked ",
611                         'GPRINT:blocked_min:MIN:%5.1lf Min,',
612                         'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
613                         'GPRINT:blocked_max:MAX:%5.1lf Max,',
614                         'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
615                         "LINE1:zombies_acc#$FullRed:Zombies ",
616                         'GPRINT:zombies_min:MIN:%5.1lf Min,',
617                         'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
618                         'GPRINT:zombies_max:MAX:%5.1lf Max,',
619                         'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
620                         "LINE1:stopped_acc#$FullMagenta:Stopped ",
621                         'GPRINT:stopped_min:MIN:%5.1lf Min,',
622                         'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
623                         'GPRINT:stopped_max:MAX:%5.1lf Max,',
624                         'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
625                         "LINE1:running_acc#$FullGreen:Running ",
626                         'GPRINT:running_min:MIN:%5.1lf Min,',
627                         'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
628                         'GPRINT:running_max:MAX:%5.1lf Max,',
629                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
630                         "LINE1:sleeping_acc#$FullBlue:Sleeping",
631                         'GPRINT:sleeping_min:MIN:%5.1lf Min,',
632                         'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
633                         'GPRINT:sleeping_max:MAX:%5.1lf Max,',
634                         'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
635                 ],
636                 sensors => [
637                         'DEF:temp_avg={file}:value:AVERAGE',
638                         'DEF:temp_min={file}:value:MIN',
639                         'DEF:temp_max={file}:value:MAX',
640                         "AREA:temp_max#$HalfBlue",
641                         "AREA:temp_min#$Canvas",
642                         "LINE1:temp_avg#$FullBlue:Value",
643                         'GPRINT:temp_min:MIN:%4.1lf Min,',
644                         'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
645                         'GPRINT:temp_max:MAX:%4.1lf Max,',
646                         'GPRINT:temp_avg:LAST:%4.1lf Last\l'
647                 ],
648                 swap => [
649                         'DEF:used_avg={file}:used:AVERAGE',
650                         'DEF:used_min={file}:used:MIN',
651                         'DEF:used_max={file}:used:MAX',
652                         'DEF:free_avg={file}:free:AVERAGE',
653                         'DEF:free_min={file}:free:MIN',
654                         'DEF:free_max={file}:free:MAX',
655                         'DEF:cach_avg={file}:cached:AVERAGE',
656                         'DEF:cach_min={file}:cached:MIN',
657                         'DEF:cach_max={file}:cached:MAX',
658                         'DEF:resv_avg={file}:resv:AVERAGE',
659                         'DEF:resv_min={file}:resv:MIN',
660                         'DEF:resv_max={file}:resv:MAX',
661                         'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
662                         'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
663                         'CDEF:used_acc=used_avg',
664                         'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
665                         'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
666                         'CDEF:free_acc=cach_acc,free_avg,+',
667                         "AREA:free_acc#$HalfGreen",
668                         "AREA:cach_acc#$HalfBlue",
669                         "AREA:resv_acc#$HalfYellow",
670                         "AREA:used_acc#$HalfRed",
671                         "LINE1:free_acc#$FullGreen:Free    ",
672                         'GPRINT:free_min:MIN:%5.1lf%s Min,',
673                         'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
674                         'GPRINT:free_max:MAX:%5.1lf%s Max,',
675                         'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
676                         "LINE1:cach_acc#$FullBlue:Cached  ",
677                         'GPRINT:cach_min:MIN:%5.1lf%s Min,',
678                         'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
679                         'GPRINT:cach_max:MAX:%5.1lf%s Max,',
680                         'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
681                         "LINE1:resv_acc#$FullYellow:Reserved",
682                         'GPRINT:resv_min:MIN:%5.1lf%s Min,',
683                         'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
684                         'GPRINT:resv_max:MAX:%5.1lf%s Max,',
685                         'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
686                         "LINE1:used_acc#$FullRed:Used    ",
687                         'GPRINT:used_min:MIN:%5.1lf%s Min,',
688                         'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
689                         'GPRINT:used_max:MAX:%5.1lf%s Max,',
690                         'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
691                 ],
692                 traffic => ['DEF:out_min_raw={file}:outgoing:MIN',
693                         'DEF:out_avg_raw={file}:outgoing:AVERAGE',
694                         'DEF:out_max_raw={file}:outgoing:MAX',
695                         'DEF:inc_min_raw={file}:incoming:MIN',
696                         'DEF:inc_avg_raw={file}:incoming:AVERAGE',
697                         'DEF:inc_max_raw={file}:incoming:MAX',
698                         'CDEF:out_min=out_min_raw,8,*',
699                         'CDEF:out_avg=out_avg_raw,8,*',
700                         'CDEF:out_max=out_max_raw,8,*',
701                         'CDEF:inc_min=inc_min_raw,8,*',
702                         'CDEF:inc_avg=inc_avg_raw,8,*',
703                         'CDEF:inc_max=inc_max_raw,8,*',
704                         'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
705                         'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
706                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
707                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
708                         'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
709                         'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
710                         'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
711                         'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
712                         "AREA:out_avg#$HalfGreen",
713                         "AREA:inc_avg#$HalfBlue",
714                         "AREA:overlap#$HalfBlueGreen",
715                         "LINE1:out_avg#$FullGreen:Outgoing",
716                         'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
717                         'GPRINT:out_max:MAX:%5.1lf%s Max,',
718                         'GPRINT:out_avg:LAST:%5.1lf%s Last',
719                         'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
720                         "LINE1:inc_avg#$FullBlue:Incoming",
721                         #'GPRINT:inc_min:MIN:%5.1lf %s Min,',
722                         'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
723                         'GPRINT:inc_max:MAX:%5.1lf%s Max,',
724                         'GPRINT:inc_avg:LAST:%5.1lf%s Last',
725                         'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
726                 ],
727                 cpufreq => [
728                         'DEF:cpufreq_avg={file}:value:AVERAGE',
729                         'DEF:cpufreq_min={file}:value:MIN',
730                         'DEF:cpufreq_max={file}:value:MAX',
731                         "AREA:cpufreq_max#$HalfBlue",
732                         "AREA:cpufreq_min#$Canvas",
733                         "LINE1:cpufreq_avg#$FullBlue:Frequency",
734                         'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
735                         'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
736                         'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
737                         'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l'
738                 ],
739                 users => [
740                             'DEF:users_avg={file}:users:AVERAGE',
741                             'DEF:users_min={file}:users:MIN',
742                             'DEF:users_max={file}:users:MAX',
743                             "AREA:users_max#$HalfBlue",
744                             "AREA:users_min#$Canvas",
745                             "LINE1:users_avg#$FullBlue:Users",
746                             'GPRINT:users_min:MIN:%4.1lf Min,',
747                             'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
748                             'GPRINT:users_max:MAX:%4.1lf Max,',
749                             'GPRINT:users_avg:LAST:%4.1lf Last\l'
750                 ],
751                 voltage => [
752                         'DEF:avg={file}:voltage:AVERAGE',
753                         'DEF:min={file}:voltage:MIN',
754                         'DEF:max={file}:voltage:MAX',
755                         "AREA:max#$HalfBlue",
756                         "AREA:min#$Canvas",
757                         "LINE1:avg#$FullBlue:Voltage",
758                         'GPRINT:min:MIN:%5.1lf%sV Min,',
759                         'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
760                         'GPRINT:max:MAX:%5.1lf%sV Max,',
761                         'GPRINT:avg:LAST:%5.1lf%sV Last\l'
762                 ],
763                 threads => [
764                         "DEF:total_avg={file}:total:AVERAGE",
765                         "DEF:total_min={file}:total:MIN",
766                         "DEF:total_max={file}:total:MAX",
767                         "DEF:running_avg={file}:running:AVERAGE",
768                         "DEF:running_min={file}:running:MIN",
769                         "DEF:running_max={file}:running:MAX",
770                         "DEF:uninterruptible_avg={file}:uninterruptible:AVERAGE",
771                         "DEF:uninterruptible_min={file}:uninterruptible:MIN",
772                         "DEF:uninterruptible_max={file}:uninterruptible:MAX",
773                         "DEF:onhold_avg={file}:onhold:AVERAGE",
774                         "DEF:onhold_min={file}:onhold:MIN",
775                         "DEF:onhold_max={file}:onhold:MAX",
776                         "LINE1:total_avg#$FullYellow:Total   ",
777                         'GPRINT:total_min:MIN:%5.1lf Min,',
778                         'GPRINT:total_avg:AVERAGE:%5.1lf Avg.,',
779                         'GPRINT:total_max:MAX:%5.1lf Max,',
780                         'GPRINT:total_avg:LAST:%5.1lf Last\l',
781                         "LINE1:running_avg#$FullRed:Running ",
782                         'GPRINT:running_min:MIN:%5.1lf Min,',
783                         'GPRINT:running_avg:AVERAGE:%5.1lf Avg.,',          
784                         'GPRINT:running_max:MAX:%5.1lf Max,',
785                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
786                         "LINE1:uninterruptible_avg#$FullGreen:Unintr  ",
787                         'GPRINT:uninterruptible_min:MIN:%5.1lf Min,',
788                         'GPRINT:uninterruptible_avg:AVERAGE:%5.1lf Avg.,',
789                         'GPRINT:uninterruptible_max:MAX:%5.1lf Max,',
790                         'GPRINT:uninterruptible_avg:LAST:%5.1lf Last\l',
791                         "LINE1:onhold_avg#$FullBlue:Onhold  ",
792                         'GPRINT:onhold_min:MIN:%5.1lf Min,',
793                         'GPRINT:onhold_avg:AVERAGE:%5.1lf Avg.,',
794                         'GPRINT:onhold_max:MAX:%5.1lf Max,',
795                         'GPRINT:onhold_avg:LAST:%5.1lf Last\l'
796                 ],
797                 vs_memory => [
798                         'DEF:vm_avg={file}:vm:AVERAGE',
799                         'DEF:vm_min={file}:vm:MIN',
800                         'DEF:vm_max={file}:vm:MAX',
801                         'DEF:vml_avg={file}:vml:AVERAGE',
802                         'DEF:vml_min={file}:vml:MIN',
803                         'DEF:vml_max={file}:vml:MAX',
804                         'DEF:rss_avg={file}:rss:AVERAGE',
805                         'DEF:rss_min={file}:rss:MIN',
806                         'DEF:rss_max={file}:rss:MAX',
807                         'DEF:anon_avg={file}:anon:AVERAGE',
808                         'DEF:anon_min={file}:anon:MIN',
809                         'DEF:anon_max={file}:anon:MAX',
810                         "LINE1:vm_avg#$FullYellow:VM     ",
811                         'GPRINT:vm_min:MIN:%5.1lf%s Min,',
812                         'GPRINT:vm_avg:AVERAGE:%5.1lf%s Avg.,',
813                         'GPRINT:vm_max:MAX:%5.1lf%s Avg.,',
814                         'GPRINT:vm_avg:LAST:%5.1lf%s Last\l',
815                         "LINE1:vml_avg#$FullRed:Locked ",
816                         'GPRINT:vml_min:MIN:%5.1lf%s Min,',
817                         'GPRINT:vml_avg:AVERAGE:%5.1lf%s Avg.,',
818                         'GPRINT:vml_max:MAX:%5.1lf%s Avg.,',
819                         'GPRINT:vml_avg:LAST:%5.1lf%s Last\l',
820                         "LINE1:rss_avg#$FullGreen:RSS    ",
821                         'GPRINT:rss_min:MIN:%5.1lf%s Min,',
822                         'GPRINT:rss_avg:AVERAGE:%5.1lf%s Avg.,',
823                         'GPRINT:rss_max:MAX:%5.1lf%s Avg.,',
824                         'GPRINT:rss_avg:LAST:%5.1lf%s Last\l',
825                         "LINE1:anon_avg#$FullBlue:Anon.  ",
826                         'GPRINT:anon_min:MIN:%5.1lf%s Min,',
827                         'GPRINT:anon_avg:AVERAGE:%5.1lf%s Avg.,',
828                         'GPRINT:anon_max:MAX:%5.1lf%s Avg.,',
829                         'GPRINT:anon_avg:LAST:%5.1lf%s Last\l',
830                 ],
831                 vs_processes => [
832                         'DEF:proc_avg={file}:total:AVERAGE',
833                         'DEF:proc_min={file}:total:MIN',
834                         'DEF:proc_max={file}:total:MAX',
835                         "AREA:proc_max#$HalfBlue",
836                         "AREA:proc_min#$Canvas",
837                         "LINE1:proc_avg#$FullBlue:Processes",
838                         'GPRINT:proc_min:MIN:%4.1lf Min,',
839                         'GPRINT:proc_avg:AVERAGE:%4.1lf Avg.,',
840                         'GPRINT:proc_max:MAX:%4.1lf Max,',
841                         'GPRINT:proc_avg:LAST:%4.1lf Last\l'
842                 ],
843         };
844         $GraphDefs->{'disk'} = $GraphDefs->{'partition'};
845         $GraphDefs->{'meminfo'} = $GraphDefs->{'memory'};
848 our $GraphArgs =
850         apache_bytes => ['-t', 'apache traffic', '-v', 'Bit/s'],
851         apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
852         apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
853         charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
854         cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
855         cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
856         current => ['-t', '{host} current', '-v', 'Ampere'],
857         #disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'],
858         df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'],
859         disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'],
860         hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'],
861         load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'],
862         mails   => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'],
863         memory => ['-t', '{host} memory usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
864         mysql_commands => ['-t', 'mysql command {inst}', '-v', 'Issues/s' ],
865         mysql_handler => ['-t', 'mysql handler {inst}', '-v', 'Issues/s' ],
866         mysql_qcache => ['-t', 'mysql query cache', '-v', 'Queries/s' ],
867         mysql_threads => ['-t', 'mysql threads', '-v', 'Threads' ],
868         nfs3_procedures => ['-t', '{host} NFSv3 {inst} procedures', '-v', 'Procedures/s' ],
869         partition => ['-t', '{host} partition {inst} usage', '-v', 'Byte/s'],
870         ping => ['-t', '{host} ping to {inst}', '-v', 'ms'],
871         processes => ['-t', '{host} processes', '-v', 'Processes'],
872         sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'],
873         swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
874         traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'],
875         users => ['-t', '{host} users', '-v', 'Users'],
876         voltage => ['-t', '{host} voltage', '-v', 'Volts'],
877         threads => ['-t', '{host} threads', '-v', 'Threads'],
878         vs_memory => ['-t', '{host} memory usage', '-v', 'Bytes'],
879         vs_processes => ['-t', '{host} processes', '-v', 'Processes'],
880 };
882 our $GraphMulti =
884         apache_scoreboard => \&output_graph_apache_scoreboard,
885         cpu     => \&output_graph_cpu,
886         cpufreq => 1,
887         disk    => 1,
888         load    => 0,
889         mails   => 0,
890         memory  => 0,
891         mysql_commands => \&output_graph_mysql_commands,
892         mysql_handler => \&output_graph_mysql_handler,
893         partition => 1,
894         ping    => \&output_graph_ping,
895         sensors => 1,
896         traffic => 1,
897     users => 1
898 };
900 our @Info;
901 if (defined ($ENV{'GATEWAY_INTERFACE'}))
903         @Info = ($ENV{'PATH_INFO'} || '') =~ m#([\w\-\.]+)#g;
905 else
907         @Info = @ARGV;
910 parse_pathinfo (@Info);
912 if ($TimeSpan)
914         output_graph ();
916 else
918         output_page ();
921 exit (0);
923 sub output_graph_cpu
925         my @inst = @_;
926         my @ret = ();
928         die if (@inst < 2);
930         for (@inst)
931         {
932                 push (@ret,
933                         "DEF:user_avg_$_=$AbsDir/cpu-$_.rrd:user:AVERAGE",
934                         "DEF:user_min_$_=$AbsDir/cpu-$_.rrd:user:MIN",
935                         "DEF:user_max_$_=$AbsDir/cpu-$_.rrd:user:MAX",
936                         "DEF:nice_avg_$_=$AbsDir/cpu-$_.rrd:nice:AVERAGE",
937                         "DEF:nice_min_$_=$AbsDir/cpu-$_.rrd:nice:MIN",
938                         "DEF:nice_max_$_=$AbsDir/cpu-$_.rrd:nice:MAX",
939                         "DEF:syst_avg_$_=$AbsDir/cpu-$_.rrd:syst:AVERAGE",
940                         "DEF:syst_min_$_=$AbsDir/cpu-$_.rrd:syst:MIN",
941                         "DEF:syst_max_$_=$AbsDir/cpu-$_.rrd:syst:MAX",
942                         "DEF:wait_avg_$_=$AbsDir/cpu-$_.rrd:wait:AVERAGE",
943                         "DEF:wait_min_$_=$AbsDir/cpu-$_.rrd:wait:MIN",
944                         "DEF:wait_max_$_=$AbsDir/cpu-$_.rrd:wait:MAX");
945         }
947         for (qw(user nice syst wait))
948         {
949                 my $def = $_;
950                 my $cdef;
952                 my $default_value = ($def eq 'user' or $def eq 'syst') ? 'UNKN' : '0';
954                 for (qw(avg min max))
955                 {
956                         my $cf = $_;
958                         for (@inst)
959                         {
960                                 push (@ret, "CDEF:${def}_${cf}_notnull_${_}=${def}_${cf}_${_},UN,0,${def}_${cf}_${_},IF");
961                                 push (@ret, "CDEF:${def}_${cf}_defined_${_}=${def}_${cf}_${_},UN,0,1,IF");
962                         }
964                         $cdef = "CDEF:${def}_${cf}_num=" . join (',', map { "${def}_${cf}_defined_${_}" } (@inst));
965                         $cdef .= ',+' x (scalar (@inst) - 1);
966                         push (@ret, $cdef);
968                         $cdef = "CDEF:${def}_${cf}=${def}_${cf}_num," . join (',', map { "${def}_${cf}_notnull_${_}" } (@inst));
969                         $cdef .= ',+' x (scalar (@inst) - 1);
970                         $cdef .= ",${def}_${cf}_num,${def}_${cf}_num,1,IF,/,$default_value,IF";
971                         push (@ret, $cdef);
972                         push (@ret, "CDEF:${def}_${cf}_notnull=${def}_${cf},UN,0,${def}_${cf},IF");
973                 }
974         }
976         push (@ret,
977                 "CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+",
978                 "CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+",
979                 "CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+",
980                 "CDEF:syst_acc=syst_avg_notnull");
982         push (@ret, grep { $_ !~ m/^C?DEF/ } (@{$GraphDefs->{'cpu'}}));
984         return (@ret);
987 sub output_graph_apache_scoreboard
989         my @inst = @_;
990         my @ret = ();
992         die if (@inst < 2);
994         my @colors = get_n_colors (scalar (@inst));
996         for (my $i = 0; $i < scalar (@inst); $i++)
997         {
998                 my $inst = $inst[$i];
999                 push (@ret,
1000                         "DEF:avg_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:AVERAGE",
1001                         "DEF:min_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MIN",
1002                         "DEF:max_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MAX");
1003         }
1005         for (my $i = 0; $i < scalar (@inst); $i++)
1006         {
1007                 my $inst = $inst[$i];
1008                 my $color = $colors[$i];
1010                 if (length ($inst) > 15)
1011                 {
1012                         $inst = substr ($inst, 0, 12) . '...';
1013                 }
1014                 else
1015                 {
1016                         $inst = sprintf ('%-15s', $inst);
1017                 }
1019                 push (@ret,
1020                         "LINE1:avg_$i#$color:$inst",
1021                         "GPRINT:min_$i:MIN:%6.2lf Min,",
1022                         "GPRINT:avg_$i:AVERAGE:%6.2lf Avg,",
1023                         "GPRINT:max_$i:MAX:%6.2lf Max,",
1024                         "GPRINT:avg_$i:LAST:%6.2lf Last\\l");
1025         }
1027         return (@ret);
1030 sub output_graph_ping
1032         my @inst = @_;
1033         my @ret = ();
1035         die if (@inst < 2);
1037         my @colors = get_n_colors (scalar (@inst));
1039         for (my $i = 0; $i < scalar (@inst); $i++)
1040         {
1041                 my $inst = $inst[$i];
1042                 push (@ret,
1043                         "DEF:avg_$i=$AbsDir/ping-$inst.rrd:ping:AVERAGE",
1044                         "DEF:min_$i=$AbsDir/ping-$inst.rrd:ping:MIN",
1045                         "DEF:max_$i=$AbsDir/ping-$inst.rrd:ping:MAX");
1046         }
1048         for (my $i = 0; $i < scalar (@inst); $i++)
1049         {
1050                 my $inst = $inst[$i];
1051                 my $color = $colors[$i];
1053                 if (length ($inst) > 15)
1054                 {
1055                         $inst = substr ($inst, 0, 12) . '...';
1056                 }
1057                 else
1058                 {
1059                         $inst = sprintf ('%-15s', $inst);
1060                 }
1062                 push (@ret,
1063                         "LINE1:avg_$i#$color:$inst",
1064                         "GPRINT:min_$i:MIN:%4.1lf ms Min,",
1065                         "GPRINT:avg_$i:AVERAGE:%4.1lf ms Avg,",
1066                         "GPRINT:max_$i:MAX:%4.1lf ms Max,",
1067                         "GPRINT:avg_$i:LAST:%4.1lf ms Last\\l");
1068         }
1070         return (@ret);
1073 sub output_graph_mysql_commands
1075         my @inst = @_;
1076         my @ret = ();
1078         die if (@inst < 2);
1080         my @colors = get_n_colors (scalar (@inst));
1082         for (my $i = 0; $i < scalar (@inst); $i++)
1083         {
1084                 my $inst = $inst[$i];
1085                 push (@ret,
1086                         "DEF:avg_$i=$AbsDir/mysql_commands-$inst.rrd:value:AVERAGE",
1087                         "DEF:min_$i=$AbsDir/mysql_commands-$inst.rrd:value:MIN",
1088                         "DEF:max_$i=$AbsDir/mysql_commands-$inst.rrd:value:MAX");
1089         }
1091         for (my $i = 0; $i < scalar (@inst); $i++)
1092         {
1093                 my $inst = $inst[$i];
1094                 my $color = $colors[$i];
1096                 if (length ($inst) > 18)
1097                 {
1098                         $inst = substr ($inst, 0, 15) . '...';
1099                 }
1100                 else
1101                 {
1102                         $inst = sprintf ('%-18s', $inst);
1103                 }
1105                 push (@ret,
1106                         "LINE1:avg_$i#$color:$inst",
1107                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1108                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1109                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1110                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1111         }
1113         return (@ret);
1116 sub output_graph_mysql_handler
1118         my @inst = @_;
1119         my @ret = ();
1121         die if (@inst < 2);
1123         my @colors = get_n_colors (scalar (@inst));
1125         for (my $i = 0; $i < scalar (@inst); $i++)
1126         {
1127                 my $inst = $inst[$i];
1128                 push (@ret,
1129                         "DEF:avg_$i=$AbsDir/mysql_handler-$inst.rrd:value:AVERAGE",
1130                         "DEF:min_$i=$AbsDir/mysql_handler-$inst.rrd:value:MIN",
1131                         "DEF:max_$i=$AbsDir/mysql_handler-$inst.rrd:value:MAX");
1132         }
1134         for (my $i = 0; $i < scalar (@inst); $i++)
1135         {
1136                 my $inst = $inst[$i];
1137                 my $color = $colors[$i];
1139                 if (length ($inst) > 18)
1140                 {
1141                         $inst = substr ($inst, 0, 15) . '...';
1142                 }
1143                 else
1144                 {
1145                         $inst = sprintf ('%-18s', $inst);
1146                 }
1148                 push (@ret,
1149                         "LINE1:avg_$i#$color:$inst",
1150                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1151                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1152                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1153                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1154         }
1156         return (@ret);
1159 sub output_graph
1161         die unless (defined ($GraphDefs->{$Type}));
1163         my $host;
1164         my @cmd = ();
1165         my $file = $AbsDir . '/';
1166         my $files = get_all_files ($AbsDir);
1168         #
1169         # get hostname
1170         #
1171         if ($RelDir =~ m#([^/]+)$#)
1172         {
1173                 $host = $1;
1174         }
1175         else
1176         {
1177                 $host = $Config->{'HostName'};
1178         }
1180         #
1181         # get timespan
1182         #
1183         if ($TimeSpan =~ m/(\d+)/)
1184         {
1185                 $TimeSpan = -1 * int ($1);
1186         }
1187         else
1188         {
1189                 my %t = (hour => -3600, day => -86400, week => -604800, month => -2678400, year => -31622400);
1190                 die unless (defined ($t{$TimeSpan}));
1191                 $TimeSpan = $t{$TimeSpan};
1192         }
1194         if (scalar (@{$files->{$Type}}) == 1)
1195         {
1196                 $Inst = $files->{$Type}[0];
1197         }
1199         push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan);
1200         push (@cmd, @{$GraphArgs->{$Type}}) if (defined ($GraphArgs->{$Type}));
1202         for (qw(Back ShadeA ShadeB Font Canvas Grid MGrid Frame Arrow))
1203         {
1204                 push (@cmd, '-c', uc ($_) . '#' . $Config->{'Colors'}{$_});
1205         }
1207         if ((length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE'))
1208         {
1209                 push (@cmd, $GraphMulti->{$Type}->(@{$files->{$Type}}));
1210         }
1211         else
1212         {
1213                 if (length ("$Inst"))
1214                 {
1215                         $file .= "$Type-$Inst.rrd";
1216                 }
1217                 else
1218                 {
1219                         $file .= "$Type.rrd";
1220                 }
1222                 die ("File not found: $file") unless (-e $file);
1224                 push (@cmd, @{$GraphDefs->{$Type}});
1225         }
1227         for (@cmd)
1228         {
1229                 $_ =~ s/{file}/$file/g;
1230                 $_ =~ s/{host}/$host/g;
1231                 $_ =~ s/{inst}/$Inst/g;
1232                 $_ =~ s/{type}/$Type/g;
1233         }
1235         $| = 1;
1237         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1238 Content-Type: image/png
1239 Cache-Control: no-cache
1241 HEADER
1243         if (1)
1244         {
1245                 my $fh;
1246                 open ($fh, ">/tmp/collection.log") or die ("open: $!");
1247                 flock ($fh, LOCK_EX) or die ("flock: $!");
1249                 print $fh join ("\n\t", @cmd) . "\n";
1251                 close ($fh);
1252         }
1254         RRDs::graph (@cmd);
1256         die ('RRDs::error: ' . RRDs::error ()) if (RRDs::error ());
1259 sub output_page
1261         my $files = get_all_files ($AbsDir);
1262         my $dirs  = get_all_dirs  ($AbsDir);
1264         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1265 Content-Type: text/html
1266 Cache-Control: no-cache
1268 <html>
1269         <head>
1270                 <title>Collection: $RelDir</title>
1271                 <style type="text/css">
1272                         img { border: none; display: block; }
1273                 </style>
1274         </head>
1276         <body>
1277 HEADER
1279         my $MySelf = defined ($ENV{'GATEWAY_INTERFACE'}) ? $ENV{'SCRIPT_NAME'} : $0;
1281         if ((length ($Type) != 0) and (length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1282         {
1283                 print qq(\t\t<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1285                 print "\t\t<ul>\n";
1286                 for (@{$files->{$Type}})
1287                 {
1288                         print qq(\t\t\t<li><a href="$MySelf$RelDir/$Type/$_">$_</a></li>\n);
1289                 }
1290                 print <<HTML;
1291                 </ul>
1293                 <h3>Daily</h3>
1294                 <div><img src="$MySelf$RelDir/$Type/day" /></div>
1295                 <h3>Weekly</h3>
1296                 <div><img src="$MySelf$RelDir/$Type/week" /></div>
1297                 <h3>Monthly</h3>
1298                 <div><img src="$MySelf$RelDir/$Type/month" /></div>
1299                 <h3>Yearly</h3>
1300                 <div><img src="$MySelf$RelDir/$Type/year" /></div>
1301 HTML
1302         }
1303         elsif (length ($Type) != 0)
1304         {
1305                 my $ext = length ($Inst) ? "$Type/$Inst" : $Type;
1307                 if ((ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1308                 {
1309                         print qq(<div><a href="$MySelf$RelDir/$Type">Go up</a></div>\n);
1310                 }
1311                 else
1312                 {
1313                         print qq(<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1314                 }
1316                 print <<HTML;
1317                 <h3>Daily</h3>
1318                 <div><img src="$MySelf$RelDir/$ext/day" /></div>
1319                 <h3>Weekly</h3>
1320                 <div><img src="$MySelf$RelDir/$ext/week" /></div>
1321                 <h3>Monthly</h3>
1322                 <div><img src="$MySelf$RelDir/$ext/month" /></div>
1323                 <h3>Yearly</h3>
1324                 <div><img src="$MySelf$RelDir/$ext/year" /></div>
1325 HTML
1326         }
1327         else
1328         {
1329                 if ($RelDir)
1330                 {
1331                         my ($up) = $RelDir =~ m#(.*)/[^/]+$#;
1332                         print qq(\t\t<div><a href="$MySelf$up">Go up</a></div>\n);
1333                 }
1335                 if (@$dirs)
1336                 {
1337                         print "<ul>\n";
1338                         for (@$dirs)
1339                         {
1340                                 print qq(<li>$AbsDir/<a href="$MySelf$RelDir/$_">$_</a></li>\n);
1341                         }
1342                         print "</ul>\n";
1343                 }
1345                 for (sort (keys %$files))
1346                 {
1347                         my $type = $_;
1349                         if (ref ($GraphMulti->{$type}) eq 'CODE')
1350                         {
1351                                 print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1352                                 qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1353                                 next;
1354                         }
1356                         for (@{$files->{$type}})
1357                         {
1358                                 my $inst = "$_";
1360                                 if (length ($inst))
1361                                 {
1362                                         print qq(\t\t<a href="$MySelf$RelDir/$type/$inst" />),
1363                                         qq(<img src="$MySelf$RelDir/$type/$inst/day" /></a>\n);
1364                                 }
1365                                 else
1366                                 {
1367                                         print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1368                                         qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1369                                 }
1370                         }
1371                 }
1372         }
1374         print STDOUT <<FOOTER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1375         </body>
1376 </html>
1377 FOOTER
1380 sub output_xml
1382         my $files = get_all_files ();
1384         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1385 Content-Type: text/xml
1386 Cache-Control: no-cache
1388 HEADER
1389         print STDOUT pl2xml ($files);
1392 sub read_config
1394         my $file = @_ ? shift : '/etc/collection.conf';
1395         my $conf;
1396         my $fh;
1398 #       if (open ($fh, "< $file"))
1399 #       {
1400 #               my $xml;
1401 #               local $/ = undef;
1402 #               $xml = <$fh>;
1404 #               eval
1405 #               {
1406 #                       $conf = xml2pl ($xml);
1407 #               };
1408 #               close ($fh);
1409 #       }
1411         if (!$conf)
1412         {
1413                 return ({
1414                                 Colors =>
1415                                 {
1416                                         Back    => 'FFFFFF',
1417                                         ShadeA  => 'FFFFFF',
1418                                         ShadeB  => 'FFFFFF',
1419                                         Font    => '000000',
1420                                         Canvas  => 'F5F5F5',
1421                                         Grid    => 'D0D0D0',
1422                                         MGrid   => 'A0A0A0',
1423                                         Frame   => '646464',
1424                                         Arrow   => 'FF0000',
1426                                         FullRed         => 'FF0000',
1427                                         FullBlue        => '0000FF',
1428                                         FullGreen       => '00E000',
1429                                         FullYellow      => 'F0A000',
1430                                         FullCyan        => '00A0FF',
1431                                         FullMagenta     => 'A000FF',
1432                                         Alpha           => 0.25,
1433                                         HalfRed         => 'F8B8B8',
1434                                         HalfBlue        => 'B8B8F8',
1435                                         HalfGreen       => 'B8F0B8',
1436                                         HalfYellow      => 'F4F4B8'
1437                                 },
1438                                 Directory => '/var/lib/collectd',
1439                                 HostName  => (defined ($ENV{'SERVER_NAME'}) ? $ENV{'SERVER_NAME'} : 'localhost')
1440                         });
1441         }
1442         else
1443         {
1444                 return ($conf);
1445         }
1448 sub parse_pathinfo
1450         my @info = @_;
1452         $AbsDir = $Config->{'Directory'};
1453         $RelDir = '';
1455         while (@info and -d $AbsDir . '/' . $Info[0])
1456         {
1457                 my $new = shift (@info);
1458                 next if ($new =~ m/^\./);
1460                 $AbsDir .= '/' . $new;
1461                 $RelDir .= '/' . $new;
1462         }
1464         $Type = '';
1465         $Inst = '';
1466         $TimeSpan = '';
1468         confess ("parse_pathinfo: too many elements in pathinfo") if (scalar (@info) > 3);
1469         return unless (@info);
1471         $Type = shift (@info);
1472         return unless (@info);
1474         if ($info[-1] =~ m/^(hour|day|week|month|year)$/i)
1475         {
1476                 $TimeSpan = pop (@info);
1477         }
1479         $Inst = shift (@info) if (@info);
1481         confess ("unrecognized elements in pathinfo") if (@info);
1484 sub get_all_files
1486         my $dir = @_ ? shift : $Config->{'Directory'};
1487         my $hash = {};
1488         my $dh;
1490         if (opendir ($dh, $dir))
1491         {
1492                 while (my $thing = readdir ($dh))
1493                 {
1494                         next if ($thing =~ m/^\./);
1496                         my $type;
1497                         my $inst;
1499                         if ($thing =~ m/^(\w+)-([\w\-\.]+)\.rrd$/)
1500                         {
1501                                 $type = $1;
1502                                 $inst = $2;
1503                         }
1504                         elsif ($thing =~ m/^(\w+)\.rrd$/)
1505                         {
1506                                 $type = $1;
1507                                 $inst = '';
1508                         }
1509                         else
1510                         {
1511                                 next;
1512                         }
1514                         # Only load RRD files we can actually display..
1515                         next unless (defined ($GraphDefs->{$type}));
1517                         $hash->{$type} = [] unless (defined ($hash->{$type}));
1518                         push (@{$hash->{$type}}, $inst);
1519                 }
1521                 closedir ($dh);
1522         }
1524         return ($hash);
1527 sub get_all_dirs
1529         my $dir = @_ ? shift : $Config->{'Directory'};
1530         my @ret = ();
1531         my $dh;
1533         if (opendir ($dh, $dir))
1534         {
1535                 while (my $thing = readdir ($dh))
1536                 {
1537                         next if ($thing =~ m/^\./);
1539                         next if (!-d "$dir/$thing");
1541                         push (@ret, $thing);
1542                 }
1544                 closedir ($dh);
1545         }
1547         return (@ret) if (wantarray ());
1548         return (\@ret);
1551 sub color_hex2rgb
1553         my $color = shift;
1555         my ($red, $green, $blue) = map { ord (pack ("H2", $_)) } ($color =~ m/([A-Fa-f0-9]{2})/g);
1556         #print STDERR "$color -> rgb($red,$green,$blue)\n";
1558         return ($red, $green, $blue);
1561 sub color_rgb2hex
1563         croak unless (scalar (@_) == 3);
1564         
1565         my ($red, $green, $blue) = @_;
1567         my $ret = sprintf ("%02X%02X%02X", $red, $green, $blue);
1568         #print STDERR "rgb($red,$green,$blue) -> $ret\n";
1570         return ($ret);
1573 sub color_calculate_transparent
1575         my $alpha = shift;
1576         my $canvas = [color_hex2rgb (shift)];
1577         my @colors = map { [color_hex2rgb ($_)] } (@_);
1579         if (($alpha < 0.0) or ($alpha > 1.0))
1580         {
1581                 $alpha = 1.0;
1582         }
1584         if ($alpha == 0.0)
1585         {
1586                 return (color_rgb2hex (@$canvas));
1587         }
1588         if ($alpha == 1.0)
1589         {
1590                 return (color_rgb2hex (@{$colors[-1]}));
1591         }
1593         my $ret = _color_calculate_transparent ($alpha, $canvas, @colors);
1595         return (color_rgb2hex (@$ret));
1598 sub _color_calculate_transparent
1600         my $alpha = shift;
1601         my $canvas = shift;
1602         my $color = shift;
1603         my @colors = @_ ? shift : ();
1604         my $ret = [0, 0, 0];
1606         for (my $i = 0; $i < 3; $i++)
1607         {
1608                 $ret->[$i] = ($alpha * $color->[$i]) + ((1 - $alpha) * $canvas->[$i]);
1609         }
1611         return (_color_calculate_transparent ($alpha, $ret, @colors)) if (@colors);
1612         return ($ret);
1615 sub get_n_colors
1617         my $num = shift;
1618         my @ret = ();
1620         for (my $i = 0; $i < $num; $i++)
1621         {
1622                 my $pos = 6 * $i / $num;
1623                 my $n = int ($pos);
1624                 my $p = $pos - $n;
1625                 my $q = 1 - $p;
1627                 my $red   = 0;
1628                 my $green = 0;
1629                 my $blue  = 0;
1631                 if ($n == 0)
1632                 {
1633                         $red  = 255;
1634                         $blue = 255 * $p;
1635                 }
1636                 elsif ($n == 1)
1637                 {
1638                         $red  = 255 * $q;
1639                         $blue = 255;
1640                 }
1641                 elsif ($n == 2)
1642                 {
1643                         $green = 255 * $p;
1644                         $blue  = 255;
1645                 }
1646                 elsif ($n == 3)
1647                 {
1648                         $green = 255;
1649                         $blue  = 255 * $q;
1650                 }
1651                 elsif ($n == 4)
1652                 {
1653                         $red   = 255 * $p;
1654                         $green = 255;
1655                 }
1656                 elsif ($n == 5)
1657                 {
1658                         $red   = 255;
1659                         $green = 255 * $q;
1660                 }
1661                 else { die; }
1663                 push (@ret, sprintf ("%02x%02x%02x", $red, $green, $blue));
1664         }
1666         return (@ret);