Code

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