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