rrdtool plugin: Fixed misc. bugs and changed license to GPLv2 only.
[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                 apache_bytes => ['DEF:min_raw={file}:count:MIN',
57                         'DEF:avg_raw={file}:count:AVERAGE',
58                         'DEF:max_raw={file}:count:MAX',
59                         'CDEF:min=min_raw,8,*',
60                         'CDEF:avg=avg_raw,8,*',
61                         'CDEF:max=max_raw,8,*',
62                         'CDEF:mytime=avg_raw,TIME,TIME,IF',
63                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
64                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
65                         'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
66                         'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
67                         "AREA:avg#$HalfBlue",
68                         "LINE1:avg#$FullBlue:Bit/s",
69                         'GPRINT:min:MIN:%5.1lf%s Min,',
70                         'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
71                         'GPRINT:max:MAX:%5.1lf%s Max,',
72                         'GPRINT:avg:LAST:%5.1lf%s Last',
73                         'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
74                 ],
75                 apache_requests => ['DEF:min={file}:count:MIN',
76                         'DEF:avg={file}:count:AVERAGE',
77                         'DEF:max={file}:count:MAX',
78                         "AREA:max#$HalfBlue",
79                         "AREA:min#$Canvas",
80                         "LINE1:avg#$FullBlue:Requests/s",
81                         'GPRINT:min:MIN:%6.2lf Min,',
82                         'GPRINT:avg:AVERAGE:%6.2lf Avg,',
83                         'GPRINT:max:MAX:%6.2lf Max,',
84                         'GPRINT:avg:LAST:%6.2lf Last'
85                 ],
86                 apache_scoreboard => ['DEF:min={file}:count:MIN',
87                         'DEF:avg={file}:count:AVERAGE',
88                         'DEF:max={file}:count:MAX',
89                         "AREA:max#$HalfBlue",
90                         "AREA:min#$Canvas",
91                         "LINE1:avg#$FullBlue:Processes",
92                         'GPRINT:min:MIN:%6.2lf Min,',
93                         'GPRINT:avg:AVERAGE:%6.2lf Avg,',
94                         'GPRINT:max:MAX:%6.2lf Max,',
95                         'GPRINT:avg:LAST:%6.2lf Last'
96                 ],
97                 charge => [
98                         'DEF:avg={file}:charge:AVERAGE',
99                         'DEF:min={file}:charge:MIN',
100                         'DEF:max={file}:charge:MAX',
101                         "AREA:max#$HalfBlue",
102                         "AREA:min#$Canvas",
103                         "LINE1:avg#$FullBlue:Charge",
104                         'GPRINT:min:MIN:%5.1lf%sAh Min,',
105                         'GPRINT:avg:AVERAGE:%5.1lf%sAh Avg,',
106                         'GPRINT:max:MAX:%5.1lf%sAh Max,',
107                         'GPRINT:avg:LAST:%5.1lf%sAh Last\l'
108                 ],
109                 charge_percent => [
110                         'DEF:avg={file}:percent:AVERAGE',
111                         'DEF:min={file}:percent:MIN',
112                         'DEF:max={file}:percent:MAX',
113                         "AREA:max#$HalfBlue",
114                         "AREA:min#$Canvas",
115                         "LINE1:avg#$FullBlue:Charge",
116                         'GPRINT:min:MIN:%5.1lf%s%% Min,',
117                         'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
118                         'GPRINT:max:MAX:%5.1lf%s%% Max,',
119                         'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
120                 ],
121                 cpu => ['DEF:user_avg={file}:user:AVERAGE',
122                         'DEF:user_min={file}:user:MIN',
123                         'DEF:user_max={file}:user:MAX',
124                         'DEF:nice_avg={file}:nice:AVERAGE',
125                         'DEF:nice_min={file}:nice:MIN',
126                         'DEF:nice_max={file}:nice:MAX',
127                         'DEF:syst_avg={file}:syst:AVERAGE',
128                         'DEF:syst_min={file}:syst:MIN',
129                         'DEF:syst_max={file}:syst:MAX',
130                         'DEF:idle_avg={file}:idle:AVERAGE',
131                         'DEF:idle_min={file}:idle:MIN',
132                         'DEF:idle_max={file}:idle:MAX',
133                         'DEF:wait_avg={file}:wait:AVERAGE',
134                         'DEF:wait_min={file}:wait:MIN',
135                         'DEF:wait_max={file}:wait:MAX',
136                         'CDEF:user_avg_notnull=user_avg,UN,0,user_avg,IF',
137                         'CDEF:nice_avg_notnull=nice_avg,UN,0,nice_avg,IF',
138                         'CDEF:syst_avg_notnull=syst_avg,UN,0,syst_avg,IF',
139                         'CDEF:idle_avg_notnull=idle_avg,UN,0,idle_avg,IF',
140                         'CDEF:wait_avg_notnull=wait_avg,UN,0,wait_avg,IF',
141                         'CDEF:totl_avg_notnull=user_avg_notnull,nice_avg_notnull,+,syst_avg_notnull,+,idle_avg_notnull,+,wait_avg_notnull,+',
142                         'CDEF:user_avg_pct=user_avg_notnull,100,*,totl_avg_notnull,/',
143                         'CDEF:nice_avg_pct=nice_avg_notnull,100,*,totl_avg_notnull,/',
144                         'CDEF:syst_avg_pct=syst_avg_notnull,100,*,totl_avg_notnull,/',
145                         'CDEF:wait_avg_pct=wait_avg_notnull,100,*,totl_avg_notnull,/',
146                         'CDEF:nice_acc=syst_avg_pct,wait_avg_pct,user_avg_pct,nice_avg_pct,+,+,+',
147                         'CDEF:user_acc=syst_avg_pct,wait_avg_pct,user_avg_pct,+,+',
148                         'CDEF:wait_acc=syst_avg_pct,wait_avg_pct,+',
149                         'CDEF:syst_acc=syst_avg_pct',
150 #                       'CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+',
151 #                       'CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+',
152 #                       'CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+',
153 #                       'CDEF:syst_acc=syst_avg_notnull',
154                         "AREA:nice_acc#$HalfGreen",
155                         "AREA:user_acc#$HalfBlue",
156                         "AREA:wait_acc#$HalfYellow",
157                         "AREA:syst_acc#$HalfRed",
158                         "LINE1:nice_acc#$FullGreen:Nice   ",
159                         'GPRINT:nice_min:MIN:%5.1lf%% Min,',
160                         'GPRINT:nice_avg:AVERAGE:%5.1lf%% Avg,',
161                         'GPRINT:nice_max:MAX:%5.1lf%% Max,',
162                         'GPRINT:nice_avg:LAST:%5.1lf%% Last\l',
163                         "LINE1:user_acc#$FullBlue:User   ",
164                         'GPRINT:user_min:MIN:%5.1lf%% Min,',
165                         'GPRINT:user_avg:AVERAGE:%5.1lf%% Avg,',
166                         'GPRINT:user_max:MAX:%5.1lf%% Max,',
167                         'GPRINT:user_avg:LAST:%5.1lf%% Last\l',
168                         "LINE1:wait_acc#$FullYellow:Wait-IO",
169                         'GPRINT:wait_min:MIN:%5.1lf%% Min,',
170                         'GPRINT:wait_avg:AVERAGE:%5.1lf%% Avg,',
171                         'GPRINT:wait_max:MAX:%5.1lf%% Max,',
172                         'GPRINT:wait_avg:LAST:%5.1lf%% Last\l',
173                         "LINE1:syst_acc#$FullRed:System ",
174                         'GPRINT:syst_min:MIN:%5.1lf%% Min,',
175                         'GPRINT:syst_avg:AVERAGE:%5.1lf%% Avg,',
176                         'GPRINT:syst_max:MAX:%5.1lf%% Max,',
177                         'GPRINT:syst_avg:LAST:%5.1lf%% Last\l'
178                 ],
179                 current => [
180                         'DEF:avg={file}:current:AVERAGE',
181                         'DEF:min={file}:current:MIN',
182                         'DEF:max={file}:current:MAX',
183                         "AREA:max#$HalfBlue",
184                         "AREA:min#$Canvas",
185                         "LINE1:avg#$FullBlue:Current",
186                         'GPRINT:min:MIN:%5.1lf%sA Min,',
187                         'GPRINT:avg:AVERAGE:%5.1lf%sA Avg,',
188                         'GPRINT:max:MAX:%5.1lf%sA Max,',
189                         'GPRINT:avg:LAST:%5.1lf%sA Last\l'
190                 ],
191                 df => [
192                         'DEF:free_avg={file}:free:AVERAGE',
193                         'DEF:free_min={file}:free:MIN',
194                         'DEF:free_max={file}:free:MAX',
195                         'DEF:used_avg={file}:used:AVERAGE',
196                         'DEF:used_min={file}:used:MIN',
197                         'DEF:used_max={file}:used:MAX',
198                         'CDEF:total=free_avg,used_avg,+',
199                         'CDEF:free_pct=100,free_avg,*,total,/',
200                         'CDEF:used_pct=100,used_avg,*,total,/',
201                         'CDEF:free_acc=free_pct,used_pct,+',
202                         'CDEF:used_acc=used_pct',
203                         "AREA:free_acc#$HalfGreen",
204                         "AREA:used_acc#$HalfRed",
205                         "LINE1:free_acc#$FullGreen:Free",
206                         'GPRINT:free_min:MIN:%5.1lf%sB Min,',
207                         'GPRINT:free_avg:AVERAGE:%5.1lf%sB Avg,',
208                         'GPRINT:free_max:MAX:%5.1lf%sB Max,',
209                         'GPRINT:free_avg:LAST:%5.1lf%sB Last\l',
210                         "LINE1:used_acc#$FullRed:Used",
211                         'GPRINT:used_min:MIN:%5.1lf%sB Min,',
212                         'GPRINT:used_avg:AVERAGE:%5.1lf%sB Avg,',
213                         'GPRINT:used_max:MAX:%5.1lf%sB Max,',
214                         'GPRINT:used_avg:LAST:%5.1lf%sB Last\l'
215                 ],
216                 disk => [
217                         'DEF:rtime_avg={file}:rtime:AVERAGE',
218                         'DEF:rtime_min={file}:rtime:MIN',
219                         'DEF:rtime_max={file}:rtime:MAX',
220                         'DEF:wtime_avg={file}:wtime:AVERAGE',
221                         'DEF:wtime_min={file}:wtime:MIN',
222                         'DEF:wtime_max={file}:wtime:MAX',
223                         'CDEF:rtime_avg_ms=rtime_avg,1000,/',
224                         'CDEF:rtime_min_ms=rtime_min,1000,/',
225                         'CDEF:rtime_max_ms=rtime_max,1000,/',
226                         'CDEF:wtime_avg_ms=wtime_avg,1000,/',
227                         'CDEF:wtime_min_ms=wtime_min,1000,/',
228                         'CDEF:wtime_max_ms=wtime_max,1000,/',
229                         'CDEF:total_avg_ms=rtime_avg_ms,wtime_avg_ms,+',
230                         'CDEF:total_min_ms=rtime_min_ms,wtime_min_ms,+',
231                         'CDEF:total_max_ms=rtime_max_ms,wtime_max_ms,+',
232                         "AREA:total_max_ms#$HalfRed",
233                         "AREA:total_min_ms#$Canvas",
234                         "LINE1:wtime_avg_ms#$FullGreen:Write",
235                         'GPRINT:wtime_min_ms:MIN:%5.1lf%s Min,',
236                         'GPRINT:wtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
237                         'GPRINT:wtime_max_ms:MAX:%5.1lf%s Max,',
238                         'GPRINT:wtime_avg_ms:LAST:%5.1lf%s Last\n',
239                         "LINE1:rtime_avg_ms#$FullBlue:Read ",
240                         'GPRINT:rtime_min_ms:MIN:%5.1lf%s Min,',
241                         'GPRINT:rtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
242                         'GPRINT:rtime_max_ms:MAX:%5.1lf%s Max,',
243                         'GPRINT:rtime_avg_ms:LAST:%5.1lf%s Last\n',
244                         "LINE1:total_avg_ms#$FullRed:Total",
245                         'GPRINT:total_min_ms:MIN:%5.1lf%s Min,',
246                         'GPRINT:total_avg_ms:AVERAGE:%5.1lf%s Avg,',
247                         'GPRINT:total_max_ms:MAX:%5.1lf%s Max,',
248                         'GPRINT:total_avg_ms:LAST:%5.1lf%s Last'
249                 ],
250                 dns_traffic => ['DEF:rsp_min_raw={file}:responses:MIN',
251                         'DEF:rsp_avg_raw={file}:responses:AVERAGE',
252                         'DEF:rsp_max_raw={file}:responses:MAX',
253                         'DEF:qry_min_raw={file}:queries:MIN',
254                         'DEF:qry_avg_raw={file}:queries:AVERAGE',
255                         'DEF:qry_max_raw={file}:queries:MAX',
256                         'CDEF:rsp_min=rsp_min_raw,8,*',
257                         'CDEF:rsp_avg=rsp_avg_raw,8,*',
258                         'CDEF:rsp_max=rsp_max_raw,8,*',
259                         'CDEF:qry_min=qry_min_raw,8,*',
260                         'CDEF:qry_avg=qry_avg_raw,8,*',
261                         'CDEF:qry_max=qry_max_raw,8,*',
262                         'CDEF:overlap=rsp_avg,qry_avg,GT,qry_avg,rsp_avg,IF',
263                         'CDEF:mytime=rsp_avg_raw,TIME,TIME,IF',
264                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
265                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
266                         'CDEF:rsp_avg_sample=rsp_avg_raw,UN,0,rsp_avg_raw,IF,sample_len,*',
267                         'CDEF:rsp_avg_sum=PREV,UN,0,PREV,IF,rsp_avg_sample,+',
268                         'CDEF:qry_avg_sample=qry_avg_raw,UN,0,qry_avg_raw,IF,sample_len,*',
269                         'CDEF:qry_avg_sum=PREV,UN,0,PREV,IF,qry_avg_sample,+',
270                         "AREA:rsp_avg#$HalfGreen",
271                         "AREA:qry_avg#$HalfBlue",
272                         "AREA:overlap#$HalfBlueGreen",
273                         "LINE1:rsp_avg#$FullGreen:Responses",
274                         'GPRINT:rsp_avg:AVERAGE:%5.1lf%s Avg,',
275                         'GPRINT:rsp_max:MAX:%5.1lf%s Max,',
276                         'GPRINT:rsp_avg:LAST:%5.1lf%s Last',
277                         'GPRINT:rsp_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
278                         "LINE1:qry_avg#$FullBlue:Queries  ",
279                         #'GPRINT:qry_min:MIN:%5.1lf %s Min,',
280                         'GPRINT:qry_avg:AVERAGE:%5.1lf%s Avg,',
281                         'GPRINT:qry_max:MAX:%5.1lf%s Max,',
282                         'GPRINT:qry_avg:LAST:%5.1lf%s Last',
283                         'GPRINT:qry_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
284                 ],
285                 fanspeed => [
286                         'DEF:temp_avg={file}:value:AVERAGE',
287                         'DEF:temp_min={file}:value:MIN',
288                         'DEF:temp_max={file}:value:MAX',
289                         "AREA:temp_max#$HalfMagenta",
290                         "AREA:temp_min#$Canvas",
291                         "LINE1:temp_avg#$FullMagenta:RPM",
292                         'GPRINT:temp_min:MIN:%4.1lf Min,',
293                         'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
294                         'GPRINT:temp_max:MAX:%4.1lf Max,',
295                         'GPRINT:temp_avg:LAST:%4.1lf Last\l'
296                 ],
297                 frequency_offset => [ # NTPd
298                         'DEF:ppm_avg={file}:ppm:AVERAGE',
299                         'DEF:ppm_min={file}:ppm:MIN',
300                         'DEF:ppm_max={file}:ppm:MAX',
301                         "AREA:ppm_max#$HalfBlue",
302                         "AREA:ppm_min#$Canvas",
303                         "LINE1:ppm_avg#$FullBlue:{inst}",
304                         'GPRINT:ppm_min:MIN:%5.2lf Min,',
305                         'GPRINT:ppm_avg:AVERAGE:%5.2lf Avg,',
306                         'GPRINT:ppm_max:MAX:%5.2lf Max,',
307                         'GPRINT:ppm_avg:LAST:%5.2lf Last'
308                 ],
309                 hddtemp => [
310                         'DEF:temp_avg={file}:value:AVERAGE',
311                         'DEF:temp_min={file}:value:MIN',
312                         'DEF:temp_max={file}:value:MAX',
313                         "AREA:temp_max#$HalfRed",
314                         "AREA:temp_min#$Canvas",
315                         "LINE1:temp_avg#$FullRed:Temperature",
316                         'GPRINT:temp_min:MIN:%4.1lf Min,',
317                         'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
318                         'GPRINT:temp_max:MAX:%4.1lf Max,',
319                         'GPRINT:temp_avg:LAST:%4.1lf Last\l'
320                 ],
321                 if_packets => ['DEF:tx_min={file}:tx:MIN',
322                         'DEF:tx_avg={file}:tx:AVERAGE',
323                         'DEF:tx_max={file}:tx:MAX',
324                         'DEF:rx_min={file}:rx:MIN',
325                         'DEF:rx_avg={file}:rx:AVERAGE',
326                         'DEF:rx_max={file}:rx:MAX',
327                         'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
328                         'CDEF:mytime=tx_avg,TIME,TIME,IF',
329                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
330                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
331                         'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
332                         'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
333                         'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
334                         'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
335                         "AREA:tx_avg#$HalfGreen",
336                         "AREA:rx_avg#$HalfBlue",
337                         "AREA:overlap#$HalfBlueGreen",
338                         "LINE1:tx_avg#$FullGreen:TX",
339                         'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
340                         'GPRINT:tx_max:MAX:%5.1lf%s Max,',
341                         'GPRINT:tx_avg:LAST:%5.1lf%s Last',
342                         'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
343                         "LINE1:rx_avg#$FullBlue:RX",
344                         #'GPRINT:rx_min:MIN:%5.1lf %s Min,',
345                         'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
346                         'GPRINT:rx_max:MAX:%5.1lf%s Max,',
347                         'GPRINT:rx_avg:LAST:%5.1lf%s Last',
348                         'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l'
349                 ],
350                 load => ['DEF:s_avg={file}:shortterm:AVERAGE',
351                         'DEF:s_min={file}:shortterm:MIN',
352                         'DEF:s_max={file}:shortterm:MAX',
353                         'DEF:m_avg={file}:midterm:AVERAGE',
354                         'DEF:m_min={file}:midterm:MIN',
355                         'DEF:m_max={file}:midterm:MAX',
356                         'DEF:l_avg={file}:longterm:AVERAGE',
357                         'DEF:l_min={file}:longterm:MIN',
358                         'DEF:l_max={file}:longterm:MAX',
359                         "AREA:s_max#$HalfGreen",
360                         "AREA:s_min#$Canvas",
361                         "LINE1:s_avg#$FullGreen: 1m average",
362                         'GPRINT:s_min:MIN:%4.2lf Min,',
363                         'GPRINT:s_avg:AVERAGE:%4.2lf Avg,',
364                         'GPRINT:s_max:MAX:%4.2lf Max,',
365                         'GPRINT:s_avg:LAST:%4.2lf Last\n',
366                         "LINE1:m_avg#$FullBlue: 5m average",
367                         'GPRINT:m_min:MIN:%4.2lf Min,',
368                         'GPRINT:m_avg:AVERAGE:%4.2lf Avg,',
369                         'GPRINT:m_max:MAX:%4.2lf Max,',
370                         'GPRINT:m_avg:LAST:%4.2lf Last\n',
371                         "LINE1:l_avg#$FullRed:15m average",
372                         'GPRINT:l_min:MIN:%4.2lf Min,',
373                         'GPRINT:l_avg:AVERAGE:%4.2lf Avg,',
374                         'GPRINT:l_max:MAX:%4.2lf Max,',
375                         'GPRINT:l_avg:LAST:%4.2lf Last'
376                 ],
377                 load_percent => [
378                         'DEF:avg={file}:percent:AVERAGE',
379                         'DEF:min={file}:percent:MIN',
380                         'DEF:max={file}:percent:MAX',
381                         "AREA:max#$HalfBlue",
382                         "AREA:min#$Canvas",
383                         "LINE1:avg#$FullBlue:Load",
384                         'GPRINT:min:MIN:%5.1lf%s%% Min,',
385                         'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
386                         'GPRINT:max:MAX:%5.1lf%s%% Max,',
387                         'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
388                 ],
389                 mails => ['DEF:rawgood={file}:good:AVERAGE',
390                         'DEF:rawspam={file}:spam:AVERAGE',
391                         'CDEF:good=rawgood,UN,0,rawgood,IF',
392                         'CDEF:spam=rawspam,UN,0,rawspam,IF',
393                         'CDEF:negspam=spam,-1,*',
394                         "AREA:good#$HalfGreen",
395                         "LINE1:good#$FullGreen:Good mails",
396                         'GPRINT:good:AVERAGE:%4.1lf Avg,',
397                         'GPRINT:good:MAX:%4.1lf Max,',
398                         'GPRINT:good:LAST:%4.1lf Last\n',
399                         "AREA:negspam#$HalfRed",
400                         "LINE1:negspam#$FullRed:Spam mails",
401                         'GPRINT:spam:AVERAGE:%4.1lf Avg,',
402                         'GPRINT:spam:MAX:%4.1lf Max,',
403                         'GPRINT:spam:LAST:%4.1lf Last',
404                         'HRULE:0#000000'],
405                 memory => [
406                         'DEF:used_avg={file}:used:AVERAGE',
407                         'DEF:free_avg={file}:free:AVERAGE',
408                         'DEF:buffers_avg={file}:buffers:AVERAGE',
409                         'DEF:cached_avg={file}:cached:AVERAGE',
410                         'DEF:used_min={file}:used:MIN',
411                         'DEF:free_min={file}:free:MIN',
412                         'DEF:buffers_min={file}:buffers:MIN',
413                         'DEF:cached_min={file}:cached:MIN',
414                         'DEF:used_max={file}:used:MAX',
415                         'DEF:free_max={file}:free:MAX',
416                         'DEF:buffers_max={file}:buffers:MAX',
417                         'DEF:cached_max={file}:cached:MAX',
418                         'CDEF:cached_avg_nn=cached_avg,UN,0,cached_avg,IF',
419                         'CDEF:buffers_avg_nn=buffers_avg,UN,0,buffers_avg,IF',
420                         'CDEF:free_cached_buffers_used=free_avg,cached_avg_nn,+,buffers_avg_nn,+,used_avg,+',
421                         'CDEF:cached_buffers_used=cached_avg,buffers_avg_nn,+,used_avg,+',
422                         'CDEF:buffers_used=buffers_avg,used_avg,+',
423                         "AREA:free_cached_buffers_used#$HalfGreen",
424                         "AREA:cached_buffers_used#$HalfBlue",
425                         "AREA:buffers_used#$HalfYellow",
426                         "AREA:used_avg#$HalfRed",
427                         "LINE1:free_cached_buffers_used#$FullGreen:Free        ",
428                         'GPRINT:free_min:MIN:%5.1lf%s Min,',
429                         'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
430                         'GPRINT:free_max:MAX:%5.1lf%s Max,',
431                         'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
432                         "LINE1:cached_buffers_used#$FullBlue:Page cache  ",
433                         'GPRINT:cached_min:MIN:%5.1lf%s Min,',
434                         'GPRINT:cached_avg:AVERAGE:%5.1lf%s Avg,',
435                         'GPRINT:cached_max:MAX:%5.1lf%s Max,',
436                         'GPRINT:cached_avg:LAST:%5.1lf%s Last\n',
437                         "LINE1:buffers_used#$FullYellow:Buffer cache",
438                         'GPRINT:buffers_min:MIN:%5.1lf%s Min,',
439                         'GPRINT:buffers_avg:AVERAGE:%5.1lf%s Avg,',
440                         'GPRINT:buffers_max:MAX:%5.1lf%s Max,',
441                         'GPRINT:buffers_avg:LAST:%5.1lf%s Last\n',
442                         "LINE1:used_avg#$FullRed:Used        ",
443                         'GPRINT:used_min:MIN:%5.1lf%s Min,',
444                         'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
445                         'GPRINT:used_max:MAX:%5.1lf%s Max,',
446                         'GPRINT:used_avg:LAST:%5.1lf%s Last'
447                 ],
448                 mysql_commands => [
449                         "DEF:val_avg={file}:value:AVERAGE",
450                         "DEF:val_min={file}:value:MIN",
451                         "DEF:val_max={file}:value:MAX",
452                         "AREA:val_max#$HalfBlue",
453                         "AREA:val_min#$Canvas",
454                         "LINE1:val_avg#$FullBlue:{inst}",
455                         'GPRINT:val_min:MIN:%5.2lf Min,',
456                         'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
457                         'GPRINT:val_max:MAX:%5.2lf Max,',
458                         'GPRINT:val_avg:LAST:%5.2lf Last'
459                 ],
460                 mysql_handler => [
461                         "DEF:val_avg={file}:value:AVERAGE",
462                         "DEF:val_min={file}:value:MIN",
463                         "DEF:val_max={file}:value:MAX",
464                         "AREA:val_max#$HalfBlue",
465                         "AREA:val_min#$Canvas",
466                         "LINE1:val_avg#$FullBlue:{inst}",
467                         'GPRINT:val_min:MIN:%5.2lf Min,',
468                         'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
469                         'GPRINT:val_max:MAX:%5.2lf Max,',
470                         'GPRINT:val_avg:LAST:%5.2lf Last'
471                 ],
472                 mysql_qcache => [
473                         "DEF:hits_min={file}:hits:MIN",
474                         "DEF:hits_avg={file}:hits:AVERAGE",
475                         "DEF:hits_max={file}:hits:MAX",
476                         "DEF:inserts_min={file}:inserts:MIN",
477                         "DEF:inserts_avg={file}:inserts:AVERAGE",
478                         "DEF:inserts_max={file}:inserts:MAX",
479                         "DEF:not_cached_min={file}:not_cached:MIN",
480                         "DEF:not_cached_avg={file}:not_cached:AVERAGE",
481                         "DEF:not_cached_max={file}:not_cached:MAX",
482                         "DEF:lowmem_prunes_min={file}:lowmem_prunes:MIN",
483                         "DEF:lowmem_prunes_avg={file}:lowmem_prunes:AVERAGE",
484                         "DEF:lowmem_prunes_max={file}:lowmem_prunes:MAX",
485                         "DEF:queries_min={file}:queries_in_cache:MIN",
486                         "DEF:queries_avg={file}:queries_in_cache:AVERAGE",
487                         "DEF:queries_max={file}:queries_in_cache:MAX",
488                         "CDEF:unknown=queries_avg,UNKN,+",
489                         "CDEF:not_cached_agg=hits_avg,inserts_avg,+,not_cached_avg,+",
490                         "CDEF:inserts_agg=hits_avg,inserts_avg,+",
491                         "CDEF:hits_agg=hits_avg",
492                         "AREA:not_cached_agg#$HalfYellow",
493                         "AREA:inserts_agg#$HalfBlue",
494                         "AREA:hits_agg#$HalfGreen",
495                         "LINE1:not_cached_agg#$FullYellow:Not Cached      ",
496                         'GPRINT:not_cached_min:MIN:%5.2lf Min,',
497                         'GPRINT:not_cached_avg:AVERAGE:%5.2lf Avg,',
498                         'GPRINT:not_cached_max:MAX:%5.2lf Max,',
499                         'GPRINT:not_cached_avg:LAST:%5.2lf Last\l',
500                         "LINE1:inserts_agg#$FullBlue:Inserts         ",
501                         'GPRINT:inserts_min:MIN:%5.2lf Min,',
502                         'GPRINT:inserts_avg:AVERAGE:%5.2lf Avg,',
503                         'GPRINT:inserts_max:MAX:%5.2lf Max,',
504                         'GPRINT:inserts_avg:LAST:%5.2lf Last\l',
505                         "LINE1:hits_agg#$FullGreen:Hits            ",
506                         'GPRINT:hits_min:MIN:%5.2lf Min,',
507                         'GPRINT:hits_avg:AVERAGE:%5.2lf Avg,',
508                         'GPRINT:hits_max:MAX:%5.2lf Max,',
509                         'GPRINT:hits_avg:LAST:%5.2lf Last\l',
510                         "LINE1:lowmem_prunes_avg#$FullRed:Lowmem Prunes   ",
511                         'GPRINT:lowmem_prunes_min:MIN:%5.2lf Min,',
512                         'GPRINT:lowmem_prunes_avg:AVERAGE:%5.2lf Avg,',
513                         'GPRINT:lowmem_prunes_max:MAX:%5.2lf Max,',
514                         'GPRINT:lowmem_prunes_avg:LAST:%5.2lf Last\l',
515                         "LINE1:unknown#$Canvas:Queries in cache",
516                         'GPRINT:queries_min:MIN:%5.0lf Min,',
517                         'GPRINT:queries_avg:AVERAGE:%5.0lf Avg,',
518                         'GPRINT:queries_max:MAX:%5.0lf Max,',
519                         'GPRINT:queries_avg:LAST:%5.0lf Last\l'
520                 ],
521                 mysql_threads => [
522                         "DEF:running_min={file}:running:MIN",
523                         "DEF:running_avg={file}:running:AVERAGE",
524                         "DEF:running_max={file}:running:MAX",
525                         "DEF:connected_min={file}:connected:MIN",
526                         "DEF:connected_avg={file}:connected:AVERAGE",
527                         "DEF:connected_max={file}:connected:MAX",
528                         "DEF:cached_min={file}:cached:MIN",
529                         "DEF:cached_avg={file}:cached:AVERAGE",
530                         "DEF:cached_max={file}:cached:MAX",
531                         "DEF:created_min={file}:created:MIN",
532                         "DEF:created_avg={file}:created:AVERAGE",
533                         "DEF:created_max={file}:created:MAX",
534                         "CDEF:unknown=created_avg,UNKN,+",
535                         "CDEF:cached_agg=connected_avg,cached_avg,+",
536                         "AREA:cached_agg#$HalfGreen",
537                         "AREA:connected_avg#$HalfBlue",
538                         "AREA:running_avg#$HalfRed",
539                         "LINE1:cached_agg#$FullGreen:Cached   ",
540                         'GPRINT:cached_min:MIN:%5.1lf Min,',
541                         'GPRINT:cached_avg:AVERAGE:%5.1lf Avg,',
542                         'GPRINT:cached_max:MAX:%5.1lf Max,',
543                         'GPRINT:cached_avg:LAST:%5.1lf Last\l',
544                         "LINE1:connected_avg#$FullBlue:Connected",
545                         'GPRINT:connected_min:MIN:%5.1lf Min,',
546                         'GPRINT:connected_avg:AVERAGE:%5.1lf Avg,',
547                         'GPRINT:connected_max:MAX:%5.1lf Max,',
548                         'GPRINT:connected_avg:LAST:%5.1lf Last\l',
549                         "LINE1:running_avg#$FullRed:Running  ",
550                         'GPRINT:running_min:MIN:%5.1lf Min,',
551                         'GPRINT:running_avg:AVERAGE:%5.1lf Avg,',
552                         'GPRINT:running_max:MAX:%5.1lf Max,',
553                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
554                         "LINE1:unknown#$Canvas:Created  ",
555                         'GPRINT:created_min:MIN:%5.0lf Min,',
556                         'GPRINT:created_avg:AVERAGE:%5.0lf Avg,',
557                         'GPRINT:created_max:MAX:%5.0lf Max,',
558                         'GPRINT:created_avg:LAST:%5.0lf Last\l'
559                 ],
560                 nfs3_procedures => [
561                         "DEF:null_avg={file}:null:AVERAGE",
562                         "DEF:getattr_avg={file}:getattr:AVERAGE",
563                         "DEF:setattr_avg={file}:setattr:AVERAGE",
564                         "DEF:lookup_avg={file}:lookup:AVERAGE",
565                         "DEF:access_avg={file}:access:AVERAGE",
566                         "DEF:readlink_avg={file}:readlink:AVERAGE",
567                         "DEF:read_avg={file}:read:AVERAGE",
568                         "DEF:write_avg={file}:write:AVERAGE",
569                         "DEF:create_avg={file}:create:AVERAGE",
570                         "DEF:mkdir_avg={file}:mkdir:AVERAGE",
571                         "DEF:symlink_avg={file}:symlink:AVERAGE",
572                         "DEF:mknod_avg={file}:mknod:AVERAGE",
573                         "DEF:remove_avg={file}:remove:AVERAGE",
574                         "DEF:rmdir_avg={file}:rmdir:AVERAGE",
575                         "DEF:rename_avg={file}:rename:AVERAGE",
576                         "DEF:link_avg={file}:link:AVERAGE",
577                         "DEF:readdir_avg={file}:readdir:AVERAGE",
578                         "DEF:readdirplus_avg={file}:readdirplus:AVERAGE",
579                         "DEF:fsstat_avg={file}:fsstat:AVERAGE",
580                         "DEF:fsinfo_avg={file}:fsinfo:AVERAGE",
581                         "DEF:pathconf_avg={file}:pathconf:AVERAGE",
582                         "DEF:commit_avg={file}:commit:AVERAGE",
583                         "DEF:null_max={file}:null:MAX",
584                         "DEF:getattr_max={file}:getattr:MAX",
585                         "DEF:setattr_max={file}:setattr:MAX",
586                         "DEF:lookup_max={file}:lookup:MAX",
587                         "DEF:access_max={file}:access:MAX",
588                         "DEF:readlink_max={file}:readlink:MAX",
589                         "DEF:read_max={file}:read:MAX",
590                         "DEF:write_max={file}:write:MAX",
591                         "DEF:create_max={file}:create:MAX",
592                         "DEF:mkdir_max={file}:mkdir:MAX",
593                         "DEF:symlink_max={file}:symlink:MAX",
594                         "DEF:mknod_max={file}:mknod:MAX",
595                         "DEF:remove_max={file}:remove:MAX",
596                         "DEF:rmdir_max={file}:rmdir:MAX",
597                         "DEF:rename_max={file}:rename:MAX",
598                         "DEF:link_max={file}:link:MAX",
599                         "DEF:readdir_max={file}:readdir:MAX",
600                         "DEF:readdirplus_max={file}:readdirplus:MAX",
601                         "DEF:fsstat_max={file}:fsstat:MAX",
602                         "DEF:fsinfo_max={file}:fsinfo:MAX",
603                         "DEF:pathconf_max={file}:pathconf:MAX",
604                         "DEF:commit_max={file}:commit:MAX",
605                         "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
606                         "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
607                         "CDEF:stack_read=read_avg",
608                         "CDEF:stack_getattr=stack_read,getattr_avg,+",
609                         "CDEF:stack_access=stack_getattr,access_avg,+",
610                         "CDEF:stack_lookup=stack_access,lookup_avg,+",
611                         "CDEF:stack_write=stack_lookup,write_avg,+",
612                         "CDEF:stack_commit=stack_write,commit_avg,+",
613                         "CDEF:stack_setattr=stack_commit,setattr_avg,+",
614                         "CDEF:stack_other=stack_setattr,other_avg,+",
615                         "AREA:stack_other#$HalfRed",
616                         "AREA:stack_setattr#$HalfGreen",
617                         "AREA:stack_commit#$HalfYellow",
618                         "AREA:stack_write#$HalfGreen",
619                         "AREA:stack_lookup#$HalfBlue",
620                         "AREA:stack_access#$HalfMagenta",
621                         "AREA:stack_getattr#$HalfCyan",
622                         "AREA:stack_read#$HalfBlue",
623                         "LINE1:stack_other#$FullRed:Other  ",
624                         'GPRINT:other_max:MAX:%5.1lf Max,',
625                         'GPRINT:other_avg:AVERAGE:%5.1lf Avg,',
626                         'GPRINT:other_avg:LAST:%5.1lf Last\l',
627                         "LINE1:stack_setattr#$FullGreen:setattr",
628                         'GPRINT:setattr_max:MAX:%5.1lf Max,',
629                         'GPRINT:setattr_avg:AVERAGE:%5.1lf Avg,',
630                         'GPRINT:setattr_avg:LAST:%5.1lf Last\l',
631                         "LINE1:stack_commit#$FullYellow:commit ",
632                         'GPRINT:commit_max:MAX:%5.1lf Max,',
633                         'GPRINT:commit_avg:AVERAGE:%5.1lf Avg,',
634                         'GPRINT:commit_avg:LAST:%5.1lf Last\l',
635                         "LINE1:stack_write#$FullGreen:write  ",
636                         'GPRINT:write_max:MAX:%5.1lf Max,',
637                         'GPRINT:write_avg:AVERAGE:%5.1lf Avg,',
638                         'GPRINT:write_avg:LAST:%5.1lf Last\l',
639                         "LINE1:stack_lookup#$FullBlue:lookup ",
640                         'GPRINT:lookup_max:MAX:%5.1lf Max,',
641                         'GPRINT:lookup_avg:AVERAGE:%5.1lf Avg,',
642                         'GPRINT:lookup_avg:LAST:%5.1lf Last\l',
643                         "LINE1:stack_access#$FullMagenta:access ",
644                         'GPRINT:access_max:MAX:%5.1lf Max,',
645                         'GPRINT:access_avg:AVERAGE:%5.1lf Avg,',
646                         'GPRINT:access_avg:LAST:%5.1lf Last\l',
647                         "LINE1:stack_getattr#$FullCyan:getattr",
648                         'GPRINT:getattr_max:MAX:%5.1lf Max,',
649                         'GPRINT:getattr_avg:AVERAGE:%5.1lf Avg,',
650                         'GPRINT:getattr_avg:LAST:%5.1lf Last\l',
651                         "LINE1:stack_read#$FullBlue:read   ",
652                         'GPRINT:read_max:MAX:%5.1lf Max,',
653                         'GPRINT:read_avg:AVERAGE:%5.1lf Avg,',
654                         'GPRINT:read_avg:LAST:%5.1lf Last\l'
655                 ],
656                 partition => [
657                         "DEF:rbyte_avg={file}:rbytes:AVERAGE",
658                         "DEF:rbyte_min={file}:rbytes:MIN",
659                         "DEF:rbyte_max={file}:rbytes:MAX",
660                         "DEF:wbyte_avg={file}:wbytes:AVERAGE",
661                         "DEF:wbyte_min={file}:wbytes:MIN",
662                         "DEF:wbyte_max={file}:wbytes:MAX",
663                         'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
664                         "AREA:wbyte_avg#$HalfGreen",
665                         "AREA:rbyte_avg#$HalfBlue",
666                         "AREA:overlap#$HalfBlueGreen",
667                         "LINE1:wbyte_avg#$FullGreen:Write",
668                         'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
669                         'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
670                         'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
671                         'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
672                         "LINE1:rbyte_avg#$FullBlue:Read ",
673                         'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
674                         'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
675                         'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
676                         'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l'
677                 ],
678                 ping => ['DEF:ping_avg={file}:ping:AVERAGE',
679                         'DEF:ping_min={file}:ping:MIN',
680                         'DEF:ping_max={file}:ping:MAX',
681                         "AREA:ping_max#$HalfBlue",
682                         "AREA:ping_min#$Canvas",
683                         "LINE1:ping_avg#$FullBlue:Ping",
684                         'GPRINT:ping_min:MIN:%4.1lf ms Min,',
685                         'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
686                         'GPRINT:ping_max:MAX:%4.1lf ms Max,',
687                         'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
688                 processes => [
689                         "DEF:running_avg={file}:running:AVERAGE",
690                         "DEF:running_min={file}:running:MIN",
691                         "DEF:running_max={file}:running:MAX",
692                         "DEF:sleeping_avg={file}:sleeping:AVERAGE",
693                         "DEF:sleeping_min={file}:sleeping:MIN",
694                         "DEF:sleeping_max={file}:sleeping:MAX",
695                         "DEF:zombies_avg={file}:zombies:AVERAGE",
696                         "DEF:zombies_min={file}:zombies:MIN",
697                         "DEF:zombies_max={file}:zombies:MAX",
698                         "DEF:stopped_avg={file}:stopped:AVERAGE",
699                         "DEF:stopped_min={file}:stopped:MIN",
700                         "DEF:stopped_max={file}:stopped:MAX",
701                         "DEF:paging_avg={file}:paging:AVERAGE",
702                         "DEF:paging_min={file}:paging:MIN",
703                         "DEF:paging_max={file}:paging:MAX",
704                         "DEF:blocked_avg={file}:blocked:AVERAGE",
705                         "DEF:blocked_min={file}:blocked:MIN",
706                         "DEF:blocked_max={file}:blocked:MAX",
707                         'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
708                         'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
709                         'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
710                         'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
711                         'CDEF:running_acc=sleeping_avg,running_avg,+',
712                         'CDEF:sleeping_acc=sleeping_avg',
713                         "AREA:paging_acc#$HalfYellow",
714                         "AREA:blocked_acc#$HalfCyan",
715                         "AREA:zombies_acc#$HalfRed",
716                         "AREA:stopped_acc#$HalfMagenta",
717                         "AREA:running_acc#$HalfGreen",
718                         "AREA:sleeping_acc#$HalfBlue",
719                         "LINE1:paging_acc#$FullYellow:Paging  ",
720                         'GPRINT:paging_min:MIN:%5.1lf Min,',
721                         'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
722                         'GPRINT:paging_max:MAX:%5.1lf Max,',
723                         'GPRINT:paging_avg:LAST:%5.1lf Last\l',
724                         "LINE1:blocked_acc#$FullCyan:Blocked ",
725                         'GPRINT:blocked_min:MIN:%5.1lf Min,',
726                         'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
727                         'GPRINT:blocked_max:MAX:%5.1lf Max,',
728                         'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
729                         "LINE1:zombies_acc#$FullRed:Zombies ",
730                         'GPRINT:zombies_min:MIN:%5.1lf Min,',
731                         'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
732                         'GPRINT:zombies_max:MAX:%5.1lf Max,',
733                         'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
734                         "LINE1:stopped_acc#$FullMagenta:Stopped ",
735                         'GPRINT:stopped_min:MIN:%5.1lf Min,',
736                         'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
737                         'GPRINT:stopped_max:MAX:%5.1lf Max,',
738                         'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
739                         "LINE1:running_acc#$FullGreen:Running ",
740                         'GPRINT:running_min:MIN:%5.1lf Min,',
741                         'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
742                         'GPRINT:running_max:MAX:%5.1lf Max,',
743                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
744                         "LINE1:sleeping_acc#$FullBlue:Sleeping",
745                         'GPRINT:sleeping_min:MIN:%5.1lf Min,',
746                         'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
747                         'GPRINT:sleeping_max:MAX:%5.1lf Max,',
748                         'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
749                 ],
750                 ps_rss => [
751                         'DEF:avg={file}:byte:AVERAGE',
752                         'DEF:min={file}:byte:MIN',
753                         'DEF:max={file}:byte:MAX',
754                         "AREA:avg#$HalfBlue",
755                         "LINE1:avg#$FullBlue:RSS",
756                         'GPRINT:min:MIN:%5.1lf%s Min,',
757                         'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
758                         'GPRINT:max:MAX:%5.1lf%s Max,',
759                         'GPRINT:avg:LAST:%5.1lf%s Last\l'
760                 ],
761                 ps_cputime => [
762                         'DEF:user_avg_raw={file}:user:AVERAGE',
763                         'DEF:user_min_raw={file}:user:MIN',
764                         'DEF:user_max_raw={file}:user:MAX',
765                         'DEF:syst_avg_raw={file}:syst:AVERAGE',
766                         'DEF:syst_min_raw={file}:syst:MIN',
767                         'DEF:syst_max_raw={file}:syst:MAX',
768                         'CDEF:user_avg=user_avg_raw,1000000,/',
769                         'CDEF:user_min=user_min_raw,1000000,/',
770                         'CDEF:user_max=user_max_raw,1000000,/',
771                         'CDEF:syst_avg=syst_avg_raw,1000000,/',
772                         'CDEF:syst_min=syst_min_raw,1000000,/',
773                         'CDEF:syst_max=syst_max_raw,1000000,/',
774                         'CDEF:user_syst=syst_avg,UN,0,syst_avg,IF,user_avg,+',
775                         "AREA:user_syst#$HalfBlue",
776                         "AREA:syst_avg#$HalfRed",
777                         "LINE1:user_syst#$FullBlue:User  ",
778                         'GPRINT:user_min:MIN:%5.1lf%s Min,',
779                         'GPRINT:user_avg:AVERAGE:%5.1lf%s Avg,',
780                         'GPRINT:user_max:MAX:%5.1lf%s Max,',
781                         'GPRINT:user_avg:LAST:%5.1lf%s Last\l',
782                         "LINE1:syst_avg#$FullRed:System",
783                         'GPRINT:syst_min:MIN:%5.1lf%s Min,',
784                         'GPRINT:syst_avg:AVERAGE:%5.1lf%s Avg,',
785                         'GPRINT:syst_max:MAX:%5.1lf%s Max,',
786                         'GPRINT:syst_avg:LAST:%5.1lf%s Last\l'
787                 ],
788                 ps_count => [
789                         'DEF:procs_avg={file}:processes:AVERAGE',
790                         'DEF:procs_min={file}:processes:MIN',
791                         'DEF:procs_max={file}:processes:MAX',
792                         'DEF:thrds_avg={file}:threads:AVERAGE',
793                         'DEF:thrds_min={file}:threads:MIN',
794                         'DEF:thrds_max={file}:threads:MAX',
795                         "AREA:thrds_avg#$HalfBlue",
796                         "AREA:procs_avg#$HalfRed",
797                         "LINE1:thrds_avg#$FullBlue:Threads  ",
798                         'GPRINT:thrds_min:MIN:%5.1lf Min,',
799                         'GPRINT:thrds_avg:AVERAGE:%5.1lf Avg,',
800                         'GPRINT:thrds_max:MAX:%5.1lf Max,',
801                         'GPRINT:thrds_avg:LAST:%5.1lf Last\l',
802                         "LINE1:procs_avg#$FullRed:Processes",
803                         'GPRINT:procs_min:MIN:%5.1lf Min,',
804                         'GPRINT:procs_avg:AVERAGE:%5.1lf Avg,',
805                         'GPRINT:procs_max:MAX:%5.1lf Max,',
806                         'GPRINT:procs_avg:LAST:%5.1lf Last\l'
807                 ],
808                 ps_pagefaults => [
809                         'DEF:minor_avg={file}:minflt:AVERAGE',
810                         'DEF:minor_min={file}:minflt:MIN',
811                         'DEF:minor_max={file}:minflt:MAX',
812                         'DEF:major_avg={file}:majflt:AVERAGE',
813                         'DEF:major_min={file}:majflt:MIN',
814                         'DEF:major_max={file}:majflt:MAX',
815                         'CDEF:minor_major=major_avg,UN,0,major_avg,IF,minor_avg,+',
816                         "AREA:minor_major#$HalfBlue",
817                         "AREA:major_avg#$HalfRed",
818                         "LINE1:minor_major#$FullBlue:Minor",
819                         'GPRINT:minor_min:MIN:%5.1lf%s Min,',
820                         'GPRINT:minor_avg:AVERAGE:%5.1lf%s Avg,',
821                         'GPRINT:minor_max:MAX:%5.1lf%s Max,',
822                         'GPRINT:minor_avg:LAST:%5.1lf%s Last\l',
823                         "LINE1:major_avg#$FullRed:Major",
824                         'GPRINT:major_min:MIN:%5.1lf%s Min,',
825                         'GPRINT:major_avg:AVERAGE:%5.1lf%s Avg,',
826                         'GPRINT:major_max:MAX:%5.1lf%s Max,',
827                         'GPRINT:major_avg:LAST:%5.1lf%s Last\l'
828                 ],
829                 qtype => [
830                         'DEF:avg={file}:value:AVERAGE',
831                         'DEF:min={file}:value:MIN',
832                         'DEF:max={file}:value:MAX',
833                         "AREA:max#$HalfBlue",
834                         "AREA:min#$Canvas",
835                         "LINE1:avg#$FullBlue:Queries/s",
836                         'GPRINT:min:MIN:%9.3lf Min,',
837                         'GPRINT:avg:AVERAGE:%9.3lf Average,',
838                         'GPRINT:max:MAX:%9.3lf Max,',
839                         'GPRINT:avg:LAST:%9.3lf Last\l'
840                 ],
841                 rcode => [
842                         'DEF:avg={file}:value:AVERAGE',
843                         'DEF:min={file}:value:MIN',
844                         'DEF:max={file}:value:MAX',
845                         "AREA:max#$HalfBlue",
846                         "AREA:min#$Canvas",
847                         "LINE1:avg#$FullBlue:Queries/s",
848                         'GPRINT:min:MIN:%9.3lf Min,',
849                         'GPRINT:avg:AVERAGE:%9.3lf Average,',
850                         'GPRINT:max:MAX:%9.3lf Max,',
851                         'GPRINT:avg:LAST:%9.3lf Last\l'
852                 ],
853                 swap => [
854                         'DEF:used_avg={file}:used:AVERAGE',
855                         'DEF:used_min={file}:used:MIN',
856                         'DEF:used_max={file}:used:MAX',
857                         'DEF:free_avg={file}:free:AVERAGE',
858                         'DEF:free_min={file}:free:MIN',
859                         'DEF:free_max={file}:free:MAX',
860                         'DEF:cach_avg={file}:cached:AVERAGE',
861                         'DEF:cach_min={file}:cached:MIN',
862                         'DEF:cach_max={file}:cached:MAX',
863                         'DEF:resv_avg={file}:resv:AVERAGE',
864                         'DEF:resv_min={file}:resv:MIN',
865                         'DEF:resv_max={file}:resv:MAX',
866                         'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
867                         'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
868                         'CDEF:used_acc=used_avg',
869                         'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
870                         'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
871                         'CDEF:free_acc=cach_acc,free_avg,+',
872                         "AREA:free_acc#$HalfGreen",
873                         "AREA:cach_acc#$HalfBlue",
874                         "AREA:resv_acc#$HalfYellow",
875                         "AREA:used_acc#$HalfRed",
876                         "LINE1:free_acc#$FullGreen:Free    ",
877                         'GPRINT:free_min:MIN:%5.1lf%s Min,',
878                         'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
879                         'GPRINT:free_max:MAX:%5.1lf%s Max,',
880                         'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
881                         "LINE1:cach_acc#$FullBlue:Cached  ",
882                         'GPRINT:cach_min:MIN:%5.1lf%s Min,',
883                         'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
884                         'GPRINT:cach_max:MAX:%5.1lf%s Max,',
885                         'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
886                         "LINE1:resv_acc#$FullYellow:Reserved",
887                         'GPRINT:resv_min:MIN:%5.1lf%s Min,',
888                         'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
889                         'GPRINT:resv_max:MAX:%5.1lf%s Max,',
890                         'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
891                         "LINE1:used_acc#$FullRed:Used    ",
892                         'GPRINT:used_min:MIN:%5.1lf%s Min,',
893                         'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
894                         'GPRINT:used_max:MAX:%5.1lf%s Max,',
895                         'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
896                 ],
897                 temperature => [
898                         'DEF:temp_avg={file}:value:AVERAGE',
899                         'DEF:temp_min={file}:value:MIN',
900                         'DEF:temp_max={file}:value:MAX',
901                         "AREA:temp_max#$HalfRed",
902                         "AREA:temp_min#$Canvas",
903                         "LINE1:temp_avg#$FullRed:Temperature",
904                         'GPRINT:temp_min:MIN:%4.1lf Min,',
905                         'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
906                         'GPRINT:temp_max:MAX:%4.1lf Max,',
907                         'GPRINT:temp_avg:LAST:%4.1lf Last\l'
908                 ],
909                 timeleft => [
910                         'DEF:avg={file}:timeleft:AVERAGE',
911                         'DEF:min={file}:timeleft:MIN',
912                         'DEF:max={file}:timeleft:MAX',
913                         "AREA:max#$HalfBlue",
914                         "AREA:min#$Canvas",
915                         "LINE1:avg#$FullBlue:Time left [min]",
916                         'GPRINT:min:MIN:%5.1lf%s Min,',
917                         'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
918                         'GPRINT:max:MAX:%5.1lf%s Max,',
919                         'GPRINT:avg:LAST:%5.1lf%s Last\l'
920                 ],
921                 time_offset => [ # NTPd
922                         'DEF:s_avg={file}:seconds:AVERAGE',
923                         'DEF:s_min={file}:seconds:MIN',
924                         'DEF:s_max={file}:seconds:MAX',
925                         "AREA:s_max#$HalfBlue",
926                         "AREA:s_min#$Canvas",
927                         "LINE1:s_avg#$FullBlue:{inst}",
928                         'GPRINT:s_min:MIN:%7.3lf%s Min,',
929                         'GPRINT:s_avg:AVERAGE:%7.3lf%s Avg,',
930                         'GPRINT:s_max:MAX:%7.3lf%s Max,',
931                         'GPRINT:s_avg:LAST:%7.3lf%s Last'
932                 ],
933                 traffic => ['DEF:out_min_raw={file}:outgoing:MIN',
934                         'DEF:out_avg_raw={file}:outgoing:AVERAGE',
935                         'DEF:out_max_raw={file}:outgoing:MAX',
936                         'DEF:inc_min_raw={file}:incoming:MIN',
937                         'DEF:inc_avg_raw={file}:incoming:AVERAGE',
938                         'DEF:inc_max_raw={file}:incoming:MAX',
939                         'CDEF:out_min=out_min_raw,8,*',
940                         'CDEF:out_avg=out_avg_raw,8,*',
941                         'CDEF:out_max=out_max_raw,8,*',
942                         'CDEF:inc_min=inc_min_raw,8,*',
943                         'CDEF:inc_avg=inc_avg_raw,8,*',
944                         'CDEF:inc_max=inc_max_raw,8,*',
945                         'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
946                         'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
947                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
948                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
949                         'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
950                         'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
951                         'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
952                         'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
953                         "AREA:out_avg#$HalfGreen",
954                         "AREA:inc_avg#$HalfBlue",
955                         "AREA:overlap#$HalfBlueGreen",
956                         "LINE1:out_avg#$FullGreen:Outgoing",
957                         'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
958                         'GPRINT:out_max:MAX:%5.1lf%s Max,',
959                         'GPRINT:out_avg:LAST:%5.1lf%s Last',
960                         'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
961                         "LINE1:inc_avg#$FullBlue:Incoming",
962                         #'GPRINT:inc_min:MIN:%5.1lf %s Min,',
963                         'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
964                         'GPRINT:inc_max:MAX:%5.1lf%s Max,',
965                         'GPRINT:inc_avg:LAST:%5.1lf%s Last',
966                         'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
967                 ],
968                 cpufreq => [
969                         'DEF:cpufreq_avg={file}:value:AVERAGE',
970                         'DEF:cpufreq_min={file}:value:MIN',
971                         'DEF:cpufreq_max={file}:value:MAX',
972                         "AREA:cpufreq_max#$HalfBlue",
973                         "AREA:cpufreq_min#$Canvas",
974                         "LINE1:cpufreq_avg#$FullBlue:Frequency",
975                         'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
976                         'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
977                         'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
978                         'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l'
979                 ],
980                 multimeter => [
981                             'DEF:multimeter_avg={file}:value:AVERAGE',
982                             'DEF:multimeter_min={file}:value:MIN',
983                             'DEF:multimeter_max={file}:value:MAX',
984                             "AREA:multimeter_max#$HalfBlue",
985                             "AREA:multimeter_min#$Canvas",
986                             "LINE1:multimeter_avg#$FullBlue:Multimeter",
987                             'GPRINT:multimeter_min:MIN:%4.1lf Min,',
988                             'GPRINT:multimeter_avg:AVERAGE:%4.1lf Average,',
989                             'GPRINT:multimeter_max:MAX:%4.1lf Max,',
990                             'GPRINT:multimeter_avg:LAST:%4.1lf Last\l'
991                 ],
992                 users => [
993                             'DEF:users_avg={file}:users:AVERAGE',
994                             'DEF:users_min={file}:users:MIN',
995                             'DEF:users_max={file}:users:MAX',
996                             "AREA:users_max#$HalfBlue",
997                             "AREA:users_min#$Canvas",
998                             "LINE1:users_avg#$FullBlue:Users",
999                             'GPRINT:users_min:MIN:%4.1lf Min,',
1000                             'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
1001                             'GPRINT:users_max:MAX:%4.1lf Max,',
1002                             'GPRINT:users_avg:LAST:%4.1lf Last\l'
1003                 ],
1004                 voltage => [
1005                         'DEF:avg={file}:voltage:AVERAGE',
1006                         'DEF:min={file}:voltage:MIN',
1007                         'DEF:max={file}:voltage:MAX',
1008                         "AREA:max#$HalfBlue",
1009                         "AREA:min#$Canvas",
1010                         "LINE1:avg#$FullBlue:Voltage",
1011                         'GPRINT:min:MIN:%5.1lf%sV Min,',
1012                         'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
1013                         'GPRINT:max:MAX:%5.1lf%sV Max,',
1014                         'GPRINT:avg:LAST:%5.1lf%sV Last\l'
1015                 ],
1016                 vs_threads => [
1017                         "DEF:total_avg={file}:total:AVERAGE",
1018                         "DEF:total_min={file}:total:MIN",
1019                         "DEF:total_max={file}:total:MAX",
1020                         "DEF:running_avg={file}:running:AVERAGE",
1021                         "DEF:running_min={file}:running:MIN",
1022                         "DEF:running_max={file}:running:MAX",
1023                         "DEF:uninterruptible_avg={file}:uninterruptible:AVERAGE",
1024                         "DEF:uninterruptible_min={file}:uninterruptible:MIN",
1025                         "DEF:uninterruptible_max={file}:uninterruptible:MAX",
1026                         "DEF:onhold_avg={file}:onhold:AVERAGE",
1027                         "DEF:onhold_min={file}:onhold:MIN",
1028                         "DEF:onhold_max={file}:onhold:MAX",
1029                         "LINE1:total_avg#$FullYellow:Total   ",
1030                         'GPRINT:total_min:MIN:%5.1lf Min,',
1031                         'GPRINT:total_avg:AVERAGE:%5.1lf Avg.,',
1032                         'GPRINT:total_max:MAX:%5.1lf Max,',
1033                         'GPRINT:total_avg:LAST:%5.1lf Last\l',
1034                         "LINE1:running_avg#$FullRed:Running ",
1035                         'GPRINT:running_min:MIN:%5.1lf Min,',
1036                         'GPRINT:running_avg:AVERAGE:%5.1lf Avg.,',          
1037                         'GPRINT:running_max:MAX:%5.1lf Max,',
1038                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
1039                         "LINE1:uninterruptible_avg#$FullGreen:Unintr  ",
1040                         'GPRINT:uninterruptible_min:MIN:%5.1lf Min,',
1041                         'GPRINT:uninterruptible_avg:AVERAGE:%5.1lf Avg.,',
1042                         'GPRINT:uninterruptible_max:MAX:%5.1lf Max,',
1043                         'GPRINT:uninterruptible_avg:LAST:%5.1lf Last\l',
1044                         "LINE1:onhold_avg#$FullBlue:Onhold  ",
1045                         'GPRINT:onhold_min:MIN:%5.1lf Min,',
1046                         'GPRINT:onhold_avg:AVERAGE:%5.1lf Avg.,',
1047                         'GPRINT:onhold_max:MAX:%5.1lf Max,',
1048                         'GPRINT:onhold_avg:LAST:%5.1lf Last\l'
1049                 ],
1050                 vs_memory => [
1051                         'DEF:vm_avg={file}:vm:AVERAGE',
1052                         'DEF:vm_min={file}:vm:MIN',
1053                         'DEF:vm_max={file}:vm:MAX',
1054                         'DEF:vml_avg={file}:vml:AVERAGE',
1055                         'DEF:vml_min={file}:vml:MIN',
1056                         'DEF:vml_max={file}:vml:MAX',
1057                         'DEF:rss_avg={file}:rss:AVERAGE',
1058                         'DEF:rss_min={file}:rss:MIN',
1059                         'DEF:rss_max={file}:rss:MAX',
1060                         'DEF:anon_avg={file}:anon:AVERAGE',
1061                         'DEF:anon_min={file}:anon:MIN',
1062                         'DEF:anon_max={file}:anon:MAX',
1063                         "LINE1:vm_avg#$FullYellow:VM     ",
1064                         'GPRINT:vm_min:MIN:%5.1lf%s Min,',
1065                         'GPRINT:vm_avg:AVERAGE:%5.1lf%s Avg.,',
1066                         'GPRINT:vm_max:MAX:%5.1lf%s Avg.,',
1067                         'GPRINT:vm_avg:LAST:%5.1lf%s Last\l',
1068                         "LINE1:vml_avg#$FullRed:Locked ",
1069                         'GPRINT:vml_min:MIN:%5.1lf%s Min,',
1070                         'GPRINT:vml_avg:AVERAGE:%5.1lf%s Avg.,',
1071                         'GPRINT:vml_max:MAX:%5.1lf%s Avg.,',
1072                         'GPRINT:vml_avg:LAST:%5.1lf%s Last\l',
1073                         "LINE1:rss_avg#$FullGreen:RSS    ",
1074                         'GPRINT:rss_min:MIN:%5.1lf%s Min,',
1075                         'GPRINT:rss_avg:AVERAGE:%5.1lf%s Avg.,',
1076                         'GPRINT:rss_max:MAX:%5.1lf%s Avg.,',
1077                         'GPRINT:rss_avg:LAST:%5.1lf%s Last\l',
1078                         "LINE1:anon_avg#$FullBlue:Anon.  ",
1079                         'GPRINT:anon_min:MIN:%5.1lf%s Min,',
1080                         'GPRINT:anon_avg:AVERAGE:%5.1lf%s Avg.,',
1081                         'GPRINT:anon_max:MAX:%5.1lf%s Avg.,',
1082                         'GPRINT:anon_avg:LAST:%5.1lf%s Last\l',
1083                 ],
1084                 vs_processes => [
1085                         'DEF:proc_avg={file}:total:AVERAGE',
1086                         'DEF:proc_min={file}:total:MIN',
1087                         'DEF:proc_max={file}:total:MAX',
1088                         "AREA:proc_max#$HalfBlue",
1089                         "AREA:proc_min#$Canvas",
1090                         "LINE1:proc_avg#$FullBlue:Processes",
1091                         'GPRINT:proc_min:MIN:%4.1lf Min,',
1092                         'GPRINT:proc_avg:AVERAGE:%4.1lf Avg.,',
1093                         'GPRINT:proc_max:MAX:%4.1lf Max,',
1094                         'GPRINT:proc_avg:LAST:%4.1lf Last\l'
1095                 ],
1096         };
1097         $GraphDefs->{'disk'} = $GraphDefs->{'partition'};
1098         $GraphDefs->{'if_errors'} = $GraphDefs->{'if_packets'};
1099         $GraphDefs->{'meminfo'} = $GraphDefs->{'memory'};
1100         $GraphDefs->{'sensors'} = $GraphDefs->{'temperature'};
1101
1102         $GraphDefs->{'delay'}           = $GraphDefs->{'time_offset'};
1103         $GraphDefs->{'time_dispersion'} = $GraphDefs->{'time_offset'};
1104 }
1105
1106 our $GraphArgs =
1107 {
1108         apache_bytes => ['-t', 'apache traffic', '-v', 'Bit/s'],
1109         apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
1110         apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
1111         charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
1112         charge_percent => ['-t', '{host} charge', '-v', 'Percent'],
1113         cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
1114         cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
1115         current => ['-t', '{host} current', '-v', 'Ampere'],
1116         #disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'],
1117         delay => ['-t', 'NTPd peer delay ({inst})', '-v', 'Seconds'],
1118         df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'],
1119         disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'],
1120         dns_traffic => ['-t', '{host} DNS traffic', '-v', 'Bit/s'],
1121         fanspeed => ['-t', '{host} fanspeed {inst}', '-v', 'RPM'],
1122         frequency_offset => ['-t', 'NTPd frequency offset ({inst})', '-v', 'Parts per million'],
1123         hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'],
1124         if_errors => ['-t', '{host} {inst} errors', '-v', 'Errors/s'],
1125         if_packets => ['-t', '{host} {inst} packets', '-v', 'Packets/s'],
1126         load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'],
1127         load_percent => ['-t', '{host} load', '-v', 'Percent'],
1128         mails   => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'],
1129         memory => ['-t', '{host} memory usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
1130         mysql_commands => ['-t', 'mysql command {inst}', '-v', 'Issues/s' ],
1131         mysql_handler => ['-t', 'mysql handler {inst}', '-v', 'Issues/s' ],
1132         mysql_qcache => ['-t', 'mysql query cache', '-v', 'Queries/s' ],
1133         mysql_threads => ['-t', 'mysql threads', '-v', 'Threads' ],
1134         nfs3_procedures => ['-t', '{host} NFSv3 {inst} procedures', '-v', 'Procedures/s' ],
1135         partition => ['-t', '{host} partition {inst} usage', '-v', 'Byte/s'],
1136         ping => ['-t', '{host} ping to {inst}', '-v', 'ms'],
1137         processes => ['-t', '{host} processes', '-v', 'Processes'],
1138         ps_rss => ['-t', '{host} process {inst} RSS', '-v', 'Bytes', '-b', '1024'],
1139         ps_cputime => ['-t', '{host} process {inst} CPU usage', '-v', 'Seconds'],
1140         ps_count => ['-t', '{host} process {inst} count', '-v', 'Threads/Processes'],
1141         ps_pagefaults => ['-t', '{host} process {inst} pagefaults', '-v', 'Pagefaults/s'],
1142         qtype => ['-t', 'QType {inst}', '-v', 'Queries/s'],
1143         rcode => ['-t', 'RCode {inst}', '-v', 'Queries/s'],
1144         sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'],
1145         swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
1146         temperature => ['-t', '{host} temperature {inst}', '-v', '°Celsius'],
1147         timeleft => ['-t', '{host} UPS time left', '-v', 'Time [min]'],
1148         time_offset => ['-t', 'NTPd time offset ({inst})', '-v', 'Seconds'],
1149         time_dispersion => ['-t', 'NTPd time dispersion ({inst})', '-v', 'Seconds'],
1150         traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'],
1151         users => ['-t', '{host} users', '-v', 'Users'],
1152         multimeter => ['-t', '{host} multimeter', '-v', 'Value'],
1153         voltage => ['-t', '{host} voltage {inst}', '-v', 'Volts'],
1154         vs_threads => ['-t', '{host} threads', '-v', 'Threads'],
1155         vs_memory => ['-t', '{host} memory usage', '-v', 'Bytes'],
1156         vs_processes => ['-t', '{host} processes', '-v', 'Processes'],
1157 };
1158
1159 our $GraphMulti =
1160 {
1161         apache_scoreboard => \&output_graph_apache_scoreboard,
1162         cpu     => \&output_graph_cpu,
1163         cpufreq => 1,
1164         disk    => 1,
1165         load    => 0,
1166         mails   => 0,
1167         memory  => 0,
1168         mysql_commands => \&output_graph_mysql_commands,
1169         mysql_handler => \&output_graph_mysql_handler,
1170         partition => 1,
1171         ping    => \&output_graph_ping,
1172         qtype => \&output_graph_named_qtype,
1173         rcode => \&output_graph_named_rcode,
1174         sensors => 1,
1175         traffic => 1,
1176         users => 1,
1177         multimeter => 1
1178 };
1179
1180 our @Info;
1181 if (defined ($ENV{'GATEWAY_INTERFACE'}))
1182 {
1183         @Info = ($ENV{'PATH_INFO'} || '') =~ m#([\w\-\.]+)#g;
1184 }
1185 else
1186 {
1187         @Info = @ARGV;
1188 }
1189
1190 parse_pathinfo (@Info);
1191
1192 if ($TimeSpan)
1193 {
1194         output_graph ();
1195 }
1196 else
1197 {
1198         output_page ();
1199 }
1200
1201 exit (0);
1202
1203 sub output_graph_cpu
1204 {
1205         my @inst = @_;
1206         my @ret = ();
1207
1208         die if (@inst < 2);
1209
1210         for (@inst)
1211         {
1212                 push (@ret,
1213                         "DEF:user_avg_$_=$AbsDir/cpu-$_.rrd:user:AVERAGE",
1214                         "DEF:user_min_$_=$AbsDir/cpu-$_.rrd:user:MIN",
1215                         "DEF:user_max_$_=$AbsDir/cpu-$_.rrd:user:MAX",
1216                         "DEF:nice_avg_$_=$AbsDir/cpu-$_.rrd:nice:AVERAGE",
1217                         "DEF:nice_min_$_=$AbsDir/cpu-$_.rrd:nice:MIN",
1218                         "DEF:nice_max_$_=$AbsDir/cpu-$_.rrd:nice:MAX",
1219                         "DEF:syst_avg_$_=$AbsDir/cpu-$_.rrd:syst:AVERAGE",
1220                         "DEF:syst_min_$_=$AbsDir/cpu-$_.rrd:syst:MIN",
1221                         "DEF:syst_max_$_=$AbsDir/cpu-$_.rrd:syst:MAX",
1222                         "DEF:wait_avg_$_=$AbsDir/cpu-$_.rrd:wait:AVERAGE",
1223                         "DEF:wait_min_$_=$AbsDir/cpu-$_.rrd:wait:MIN",
1224                         "DEF:wait_max_$_=$AbsDir/cpu-$_.rrd:wait:MAX");
1225         }
1226
1227         for (qw(user nice syst wait))
1228         {
1229                 my $def = $_;
1230                 my $cdef;
1231
1232                 my $default_value = ($def eq 'user' or $def eq 'syst') ? 'UNKN' : '0';
1233
1234                 for (qw(avg min max))
1235                 {
1236                         my $cf = $_;
1237
1238                         for (@inst)
1239                         {
1240                                 push (@ret, "CDEF:${def}_${cf}_notnull_${_}=${def}_${cf}_${_},UN,0,${def}_${cf}_${_},IF");
1241                                 push (@ret, "CDEF:${def}_${cf}_defined_${_}=${def}_${cf}_${_},UN,0,1,IF");
1242                         }
1243
1244                         $cdef = "CDEF:${def}_${cf}_num=" . join (',', map { "${def}_${cf}_defined_${_}" } (@inst));
1245                         $cdef .= ',+' x (scalar (@inst) - 1);
1246                         push (@ret, $cdef);
1247
1248                         $cdef = "CDEF:${def}_${cf}=${def}_${cf}_num," . join (',', map { "${def}_${cf}_notnull_${_}" } (@inst));
1249                         $cdef .= ',+' x (scalar (@inst) - 1);
1250                         $cdef .= ",${def}_${cf}_num,${def}_${cf}_num,1,IF,/,$default_value,IF";
1251                         push (@ret, $cdef);
1252                         push (@ret, "CDEF:${def}_${cf}_notnull=${def}_${cf},UN,0,${def}_${cf},IF");
1253                 }
1254         }
1255
1256         push (@ret,
1257                 "CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+",
1258                 "CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+",
1259                 "CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+",
1260                 "CDEF:syst_acc=syst_avg_notnull");
1261
1262         push (@ret, grep { $_ !~ m/^C?DEF/ } (@{$GraphDefs->{'cpu'}}));
1263
1264         return (@ret);
1265 }
1266
1267 sub output_graph_apache_scoreboard
1268 {
1269         my @inst = @_;
1270         my @ret = ();
1271
1272         die if (@inst < 2);
1273
1274         my @colors = get_n_colors (scalar (@inst));
1275
1276         for (my $i = 0; $i < scalar (@inst); $i++)
1277         {
1278                 my $inst = $inst[$i];
1279                 push (@ret,
1280                         "DEF:avg_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:AVERAGE",
1281                         "DEF:min_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MIN",
1282                         "DEF:max_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MAX");
1283         }
1284
1285         for (my $i = 0; $i < scalar (@inst); $i++)
1286         {
1287                 my $inst = $inst[$i];
1288                 my $color = $colors[$i];
1289
1290                 if (length ($inst) > 15)
1291                 {
1292                         $inst = substr ($inst, 0, 12) . '...';
1293                 }
1294                 else
1295                 {
1296                         $inst = sprintf ('%-15s', $inst);
1297                 }
1298
1299                 push (@ret,
1300                         "LINE1:avg_$i#$color:$inst",
1301                         "GPRINT:min_$i:MIN:%6.2lf Min,",
1302                         "GPRINT:avg_$i:AVERAGE:%6.2lf Avg,",
1303                         "GPRINT:max_$i:MAX:%6.2lf Max,",
1304                         "GPRINT:avg_$i:LAST:%6.2lf Last\\l");
1305         }
1306
1307         return (@ret);
1308 }
1309
1310 sub output_graph_ping
1311 {
1312         my @inst = @_;
1313         my @ret = ();
1314
1315         die if (@inst < 2);
1316
1317         my @colors = get_n_colors (scalar (@inst));
1318
1319         for (my $i = 0; $i < scalar (@inst); $i++)
1320         {
1321                 my $inst = $inst[$i];
1322                 push (@ret,
1323                         "DEF:avg_$i=$AbsDir/ping-$inst.rrd:ping:AVERAGE",
1324                         "DEF:min_$i=$AbsDir/ping-$inst.rrd:ping:MIN",
1325                         "DEF:max_$i=$AbsDir/ping-$inst.rrd:ping:MAX");
1326         }
1327
1328         for (my $i = 0; $i < scalar (@inst); $i++)
1329         {
1330                 my $inst = $inst[$i];
1331                 my $color = $colors[$i];
1332
1333                 if (length ($inst) > 15)
1334                 {
1335                         $inst = substr ($inst, 0, 12) . '...';
1336                 }
1337                 else
1338                 {
1339                         $inst = sprintf ('%-15s', $inst);
1340                 }
1341
1342                 push (@ret,
1343                         "LINE1:avg_$i#$color:$inst",
1344                         "GPRINT:min_$i:MIN:%4.1lf ms Min,",
1345                         "GPRINT:avg_$i:AVERAGE:%4.1lf ms Avg,",
1346                         "GPRINT:max_$i:MAX:%4.1lf ms Max,",
1347                         "GPRINT:avg_$i:LAST:%4.1lf ms Last\\l");
1348         }
1349
1350         return (@ret);
1351 }
1352
1353 sub output_graph_mysql_commands
1354 {
1355         my @inst = @_;
1356         my @ret = ();
1357
1358         die if (@inst < 2);
1359
1360         my @colors = get_n_colors (scalar (@inst));
1361
1362         for (my $i = 0; $i < scalar (@inst); $i++)
1363         {
1364                 my $inst = $inst[$i];
1365                 push (@ret,
1366                         "DEF:avg_$i=$AbsDir/mysql_commands-$inst.rrd:value:AVERAGE",
1367                         "DEF:min_$i=$AbsDir/mysql_commands-$inst.rrd:value:MIN",
1368                         "DEF:max_$i=$AbsDir/mysql_commands-$inst.rrd:value:MAX");
1369         }
1370
1371         for (my $i = 0; $i < scalar (@inst); $i++)
1372         {
1373                 my $inst = $inst[$i];
1374                 my $color = $colors[$i];
1375
1376                 if (length ($inst) > 18)
1377                 {
1378                         $inst = substr ($inst, 0, 15) . '...';
1379                 }
1380                 else
1381                 {
1382                         $inst = sprintf ('%-18s', $inst);
1383                 }
1384
1385                 push (@ret,
1386                         "LINE1:avg_$i#$color:$inst",
1387                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1388                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1389                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1390                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1391         }
1392
1393         return (@ret);
1394 }
1395
1396 sub output_graph_mysql_handler
1397 {
1398         my @inst = @_;
1399         my @ret = ();
1400
1401         die if (@inst < 2);
1402
1403         my @colors = get_n_colors (scalar (@inst));
1404
1405         for (my $i = 0; $i < scalar (@inst); $i++)
1406         {
1407                 my $inst = $inst[$i];
1408                 push (@ret,
1409                         "DEF:avg_$i=$AbsDir/mysql_handler-$inst.rrd:value:AVERAGE",
1410                         "DEF:min_$i=$AbsDir/mysql_handler-$inst.rrd:value:MIN",
1411                         "DEF:max_$i=$AbsDir/mysql_handler-$inst.rrd:value:MAX");
1412         }
1413
1414         for (my $i = 0; $i < scalar (@inst); $i++)
1415         {
1416                 my $inst = $inst[$i];
1417                 my $color = $colors[$i];
1418
1419                 if (length ($inst) > 18)
1420                 {
1421                         $inst = substr ($inst, 0, 15) . '...';
1422                 }
1423                 else
1424                 {
1425                         $inst = sprintf ('%-18s', $inst);
1426                 }
1427
1428                 push (@ret,
1429                         "LINE1:avg_$i#$color:$inst",
1430                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1431                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1432                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1433                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1434         }
1435
1436         return (@ret);
1437 }
1438
1439 sub output_graph_named_qtype
1440 {
1441         my @inst = @_;
1442         my @ret = ();
1443
1444         die if (@inst < 2);
1445
1446         my @colors = get_n_colors (scalar (@inst));
1447
1448         for (my $i = 0; $i < scalar (@inst); $i++)
1449         {
1450                 my $inst = $inst[$i];
1451                 push (@ret,
1452                         "DEF:avg_$i=$AbsDir/qtype-$inst.rrd:value:AVERAGE",
1453                         "DEF:min_$i=$AbsDir/qtype-$inst.rrd:value:MIN",
1454                         "DEF:max_$i=$AbsDir/qtype-$inst.rrd:value:MAX");
1455         }
1456
1457         for (my $i = 0; $i < scalar (@inst); $i++)
1458         {
1459                 my $inst = $inst[$i];
1460                 my $color = $colors[$i];
1461                 my $type = ($i == 0) ? 'AREA' : 'STACK';
1462
1463                 if (length ($inst) > 5)
1464                 {
1465                         $inst = substr ($inst, 0, 5);
1466                 }
1467                 else
1468                 {
1469                         $inst = sprintf ('%-5s', $inst);
1470                 }
1471
1472                 push (@ret,
1473                         "$type:avg_$i#$color:$inst",
1474                         "GPRINT:min_$i:MIN:%9.3lf Min,",
1475                         "GPRINT:avg_$i:AVERAGE:%9.3lf Avg,",
1476                         "GPRINT:max_$i:MAX:%9.3lf Max,",
1477                         "GPRINT:avg_$i:LAST:%9.3lf Last\\l");
1478         }
1479
1480         return (@ret);
1481 }
1482
1483 sub output_graph_named_rcode
1484 {
1485         my @inst = @_;
1486         my @ret = ();
1487
1488         die if (@inst < 2);
1489
1490         my @colors = get_n_colors (scalar (@inst));
1491
1492         for (my $i = 0; $i < scalar (@inst); $i++)
1493         {
1494                 my $inst = $inst[$i];
1495                 push (@ret,
1496                         "DEF:avg_$i=$AbsDir/rcode-$inst.rrd:value:AVERAGE",
1497                         "DEF:min_$i=$AbsDir/rcode-$inst.rrd:value:MIN",
1498                         "DEF:max_$i=$AbsDir/rcode-$inst.rrd:value:MAX");
1499         }
1500
1501         for (my $i = 0; $i < scalar (@inst); $i++)
1502         {
1503                 my $inst = $inst[$i];
1504                 my $color = $colors[$i];
1505                 my $type = ($i == 0) ? 'AREA' : 'STACK';
1506
1507                 if (length ($inst) > 8)
1508                 {
1509                         $inst = substr ($inst, 0, 6) . '..';
1510                 }
1511                 else
1512                 {
1513                         $inst = sprintf ('%-8s', $inst);
1514                 }
1515
1516                 push (@ret,
1517                         "$type:avg_$i#$color:$inst",
1518                         "GPRINT:min_$i:MIN:%9.3lf Min,",
1519                         "GPRINT:avg_$i:AVERAGE:%9.3lf Avg,",
1520                         "GPRINT:max_$i:MAX:%9.3lf Max,",
1521                         "GPRINT:avg_$i:LAST:%9.3lf Last\\l");
1522         }
1523
1524         return (@ret);
1525 }
1526 sub output_graph
1527 {
1528         die unless (defined ($GraphDefs->{$Type}));
1529
1530         my $host;
1531         my @cmd = ();
1532         my $file = $AbsDir . '/';
1533         my $files = get_all_files ($AbsDir);
1534
1535         #
1536         # get hostname
1537         #
1538         if ($RelDir =~ m#([^/]+)$#)
1539         {
1540                 $host = $1;
1541         }
1542         else
1543         {
1544                 $host = $Config->{'HostName'};
1545         }
1546
1547         #
1548         # get timespan
1549         #
1550         if ($TimeSpan =~ m/(\d+)/)
1551         {
1552                 $TimeSpan = -1 * int ($1);
1553         }
1554         else
1555         {
1556                 my %t = (hour => -3600, day => -86400, week => -604800, month => -2678400, year => -31622400);
1557                 die unless (defined ($t{$TimeSpan}));
1558                 $TimeSpan = $t{$TimeSpan};
1559         }
1560
1561         if (scalar (@{$files->{$Type}}) == 1)
1562         {
1563                 $Inst = $files->{$Type}[0];
1564         }
1565
1566         #push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan, '-w', 800, '-h', 150);
1567         push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan);
1568         push (@cmd, @{$GraphArgs->{$Type}}) if (defined ($GraphArgs->{$Type}));
1569
1570         for (qw(Back ShadeA ShadeB Font Canvas Grid MGrid Frame Arrow))
1571         {
1572                 push (@cmd, '-c', uc ($_) . '#' . $Config->{'Colors'}{$_});
1573         }
1574
1575         if ((length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE'))
1576         {
1577                 push (@cmd, $GraphMulti->{$Type}->(@{$files->{$Type}}));
1578         }
1579         else
1580         {
1581                 if (length ("$Inst"))
1582                 {
1583                         $file .= "$Type-$Inst.rrd";
1584                 }
1585                 else
1586                 {
1587                         $file .= "$Type.rrd";
1588                 }
1589
1590                 die ("File not found: $file") unless (-e $file);
1591
1592                 push (@cmd, @{$GraphDefs->{$Type}});
1593         }
1594
1595         for (@cmd)
1596         {
1597                 $_ =~ s/{file}/$file/g;
1598                 $_ =~ s/{host}/$host/g;
1599                 $_ =~ s/{inst}/$Inst/g;
1600                 $_ =~ s/{type}/$Type/g;
1601         }
1602
1603         $| = 1;
1604
1605         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1606 Content-Type: image/png
1607 Cache-Control: no-cache
1608
1609 HEADER
1610
1611         if (1)
1612         {
1613                 my $fh;
1614                 open ($fh, ">/tmp/collection.log") or die ("open: $!");
1615                 flock ($fh, LOCK_EX) or die ("flock: $!");
1616
1617                 print $fh join ("\n\t", @cmd) . "\n";
1618
1619                 close ($fh);
1620         }
1621
1622         RRDs::graph (@cmd);
1623
1624         die ('RRDs::error: ' . RRDs::error ()) if (RRDs::error ());
1625 }
1626
1627 sub output_page
1628 {
1629         my $files = get_all_files ($AbsDir);
1630         my $dirs  = get_all_dirs  ($AbsDir);
1631
1632         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1633 Content-Type: text/html
1634 Cache-Control: no-cache
1635
1636 <html>
1637         <head>
1638                 <title>Collection: $RelDir</title>
1639                 <style type="text/css">
1640                         img { border: none; display: block; }
1641                 </style>
1642         </head>
1643
1644         <body>
1645 HEADER
1646
1647         my $MySelf = defined ($ENV{'GATEWAY_INTERFACE'}) ? $ENV{'SCRIPT_NAME'} : $0;
1648
1649         if ((length ($Type) != 0) and (length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1650         {
1651                 print qq(\t\t<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1652
1653                 print "\t\t<ul>\n";
1654                 for (@{$files->{$Type}})
1655                 {
1656                         print qq(\t\t\t<li><a href="$MySelf$RelDir/$Type/$_">$_</a></li>\n);
1657                 }
1658                 print <<HTML;
1659                 </ul>
1660
1661                 <h3>Hourly</h3>
1662                 <div><img src="$MySelf$RelDir/$Type/hour" /></div>
1663                 <h3>Daily</h3>
1664                 <div><img src="$MySelf$RelDir/$Type/day" /></div>
1665                 <h3>Weekly</h3>
1666                 <div><img src="$MySelf$RelDir/$Type/week" /></div>
1667                 <h3>Monthly</h3>
1668                 <div><img src="$MySelf$RelDir/$Type/month" /></div>
1669                 <h3>Yearly</h3>
1670                 <div><img src="$MySelf$RelDir/$Type/year" /></div>
1671 HTML
1672         }
1673         elsif (length ($Type) != 0)
1674         {
1675                 my $ext = length ($Inst) ? "$Type/$Inst" : $Type;
1676
1677                 if ((ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1678                 {
1679                         print qq(<div><a href="$MySelf$RelDir/$Type">Go up</a></div>\n);
1680                 }
1681                 else
1682                 {
1683                         print qq(<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1684                 }
1685
1686                 print <<HTML;
1687                 <h3>Hourly</h3>
1688                 <div><img src="$MySelf$RelDir/$ext/hour" /></div>
1689                 <h3>Daily</h3>
1690                 <div><img src="$MySelf$RelDir/$ext/day" /></div>
1691                 <h3>Weekly</h3>
1692                 <div><img src="$MySelf$RelDir/$ext/week" /></div>
1693                 <h3>Monthly</h3>
1694                 <div><img src="$MySelf$RelDir/$ext/month" /></div>
1695                 <h3>Yearly</h3>
1696                 <div><img src="$MySelf$RelDir/$ext/year" /></div>
1697 HTML
1698         }
1699         else
1700         {
1701                 if ($RelDir)
1702                 {
1703                         my ($up) = $RelDir =~ m#(.*)/[^/]+$#;
1704                         print qq(\t\t<div><a href="$MySelf$up">Go up</a></div>\n);
1705                 }
1706
1707                 if (@$dirs)
1708                 {
1709                         print "<ul>\n";
1710                         for (@$dirs)
1711                         {
1712                                 print qq(<li>$AbsDir/<a href="$MySelf$RelDir/$_">$_</a></li>\n);
1713                         }
1714                         print "</ul>\n";
1715                 }
1716
1717                 for (sort (keys %$files))
1718                 {
1719                         my $type = $_;
1720
1721                         if (ref ($GraphMulti->{$type}) eq 'CODE')
1722                         {
1723                                 print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1724                                 qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1725                                 next;
1726                         }
1727
1728                         for (@{$files->{$type}})
1729                         {
1730                                 my $inst = "$_";
1731
1732                                 if (length ($inst))
1733                                 {
1734                                         print qq(\t\t<a href="$MySelf$RelDir/$type/$inst" />),
1735                                         qq(<img src="$MySelf$RelDir/$type/$inst/day" /></a>\n);
1736                                 }
1737                                 else
1738                                 {
1739                                         print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1740                                         qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1741                                 }
1742                         }
1743                 }
1744         }
1745
1746         print STDOUT <<FOOTER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1747         </body>
1748 </html>
1749 FOOTER
1750 }
1751
1752 sub output_xml
1753 {
1754         my $files = get_all_files ();
1755
1756         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1757 Content-Type: text/xml
1758 Cache-Control: no-cache
1759
1760 HEADER
1761         print STDOUT pl2xml ($files);
1762 }
1763
1764 sub read_config
1765 {
1766         my $file = @_ ? shift : '/etc/collection.conf';
1767         my $conf;
1768         my $fh;
1769
1770 #       if (open ($fh, "< $file"))
1771 #       {
1772 #               my $xml;
1773 #               local $/ = undef;
1774 #               $xml = <$fh>;
1775 #
1776 #               eval
1777 #               {
1778 #                       $conf = xml2pl ($xml);
1779 #               };
1780 #               close ($fh);
1781 #       }
1782
1783         if (!$conf)
1784         {
1785                 return ({
1786                                 Colors =>
1787                                 {
1788                                         Back    => 'FFFFFF',
1789                                         ShadeA  => 'FFFFFF',
1790                                         ShadeB  => 'FFFFFF',
1791                                         Font    => '000000',
1792                                         Canvas  => 'F5F5F5',
1793                                         Grid    => 'D0D0D0',
1794                                         MGrid   => 'A0A0A0',
1795                                         Frame   => '646464',
1796                                         Arrow   => 'FF0000',
1797
1798                                         FullRed         => 'FF0000',
1799                                         FullBlue        => '0000FF',
1800                                         FullGreen       => '00E000',
1801                                         FullYellow      => 'F0A000',
1802                                         FullCyan        => '00A0FF',
1803                                         FullMagenta     => 'A000FF',
1804                                         Alpha           => 0.25,
1805                                         HalfRed         => 'F8B8B8',
1806                                         HalfBlue        => 'B8B8F8',
1807                                         HalfGreen       => 'B8F0B8',
1808                                         HalfYellow      => 'F4F4B8'
1809                                 },
1810                                 Directory => '/var/lib/collectd',
1811                                 HostName  => (defined ($ENV{'SERVER_NAME'}) ? $ENV{'SERVER_NAME'} : 'localhost')
1812                         });
1813         }
1814         else
1815         {
1816                 return ($conf);
1817         }
1818 }
1819
1820 sub parse_pathinfo
1821 {
1822         my @info = @_;
1823
1824         $AbsDir = $Config->{'Directory'};
1825         $RelDir = '';
1826
1827         while (@info and -d $AbsDir . '/' . $info[0])
1828         {
1829                 my $new = shift (@info);
1830                 next if ($new =~ m/^\./);
1831
1832                 $AbsDir .= '/' . $new;
1833                 $RelDir .= '/' . $new;
1834         }
1835
1836         $Type = '';
1837         $Inst = '';
1838         $TimeSpan = '';
1839
1840         confess ("parse_pathinfo: too many elements in pathinfo") if (scalar (@info) > 3);
1841         return unless (@info);
1842
1843         $Type = shift (@info);
1844         return unless (@info);
1845
1846         if ($info[-1] =~ m/^(hour|day|week|month|year)$/i)
1847         {
1848                 $TimeSpan = pop (@info);
1849         }
1850
1851         $Inst = shift (@info) if (@info);
1852
1853         confess ("unrecognized elements in pathinfo") if (@info);
1854 }
1855
1856 sub get_all_files
1857 {
1858         my $dir = @_ ? shift : $Config->{'Directory'};
1859         my $hash = {};
1860         my $dh;
1861
1862         if (opendir ($dh, $dir))
1863         {
1864                 while (my $thing = readdir ($dh))
1865                 {
1866                         next if ($thing =~ m/^\./);
1867
1868                         my $type;
1869                         my $inst;
1870
1871                         if ($thing =~ m/^(\w+)-([\w\-\.]+)\.rrd$/)
1872                         {
1873                                 $type = $1;
1874                                 $inst = $2;
1875                         }
1876                         elsif ($thing =~ m/^(\w+)\.rrd$/)
1877                         {
1878                                 $type = $1;
1879                                 $inst = '';
1880                         }
1881                         else
1882                         {
1883                                 next;
1884                         }
1885
1886                         # Only load RRD files we can actually display..
1887                         next unless (defined ($GraphDefs->{$type}));
1888
1889                         $hash->{$type} = [] unless (defined ($hash->{$type}));
1890                         push (@{$hash->{$type}}, $inst);
1891                 }
1892
1893                 closedir ($dh);
1894         }
1895
1896         return ($hash);
1897 }
1898
1899 sub get_all_dirs
1900 {
1901         my $dir = @_ ? shift : $Config->{'Directory'};
1902         my @ret = ();
1903         my $dh;
1904
1905         if (opendir ($dh, $dir))
1906         {
1907                 while (my $thing = readdir ($dh))
1908                 {
1909                         next if ($thing =~ m/^\./);
1910
1911                         next if (!-d "$dir/$thing");
1912
1913                         push (@ret, $thing);
1914                 }
1915
1916                 closedir ($dh);
1917         }
1918
1919         return (@ret) if (wantarray ());
1920         return (\@ret);
1921 }
1922
1923 sub color_hex2rgb
1924 {
1925         my $color = shift;
1926
1927         my ($red, $green, $blue) = map { ord (pack ("H2", $_)) } ($color =~ m/([A-Fa-f0-9]{2})/g);
1928         #print STDERR "$color -> rgb($red,$green,$blue)\n";
1929
1930         return ($red, $green, $blue);
1931 }
1932
1933 sub color_rgb2hex
1934 {
1935         croak unless (scalar (@_) == 3);
1936         
1937         my ($red, $green, $blue) = @_;
1938
1939         my $ret = sprintf ("%02X%02X%02X", $red, $green, $blue);
1940         #print STDERR "rgb($red,$green,$blue) -> $ret\n";
1941
1942         return ($ret);
1943 }
1944
1945 sub color_calculate_transparent
1946 {
1947         my $alpha = shift;
1948         my $canvas = [color_hex2rgb (shift)];
1949         my @colors = map { [color_hex2rgb ($_)] } (@_);
1950
1951         if (($alpha < 0.0) or ($alpha > 1.0))
1952         {
1953                 $alpha = 1.0;
1954         }
1955
1956         if ($alpha == 0.0)
1957         {
1958                 return (color_rgb2hex (@$canvas));
1959         }
1960         if ($alpha == 1.0)
1961         {
1962                 return (color_rgb2hex (@{$colors[-1]}));
1963         }
1964
1965         my $ret = _color_calculate_transparent ($alpha, $canvas, @colors);
1966
1967         return (color_rgb2hex (@$ret));
1968 }
1969
1970 sub _color_calculate_transparent
1971 {
1972         my $alpha = shift;
1973         my $canvas = shift;
1974         my $color = shift;
1975         my @colors = @_ ? shift : ();
1976         my $ret = [0, 0, 0];
1977
1978         for (my $i = 0; $i < 3; $i++)
1979         {
1980                 $ret->[$i] = ($alpha * $color->[$i]) + ((1 - $alpha) * $canvas->[$i]);
1981         }
1982
1983         return (_color_calculate_transparent ($alpha, $ret, @colors)) if (@colors);
1984         return ($ret);
1985 }
1986
1987 sub get_n_colors
1988 {
1989         my $num = shift;
1990         my @ret = ();
1991
1992         for (my $i = 0; $i < $num; $i++)
1993         {
1994                 my $pos = 6 * $i / $num;
1995                 my $n = int ($pos);
1996                 my $p = $pos - $n;
1997                 my $q = 1 - $p;
1998
1999                 my $red   = 0;
2000                 my $green = 0;
2001                 my $blue  = 0;
2002
2003                 if ($n == 0)
2004                 {
2005                         $red  = 255;
2006                         $blue = 255 * $p;
2007                 }
2008                 elsif ($n == 1)
2009                 {
2010                         $red  = 255 * $q;
2011                         $blue = 255;
2012                 }
2013                 elsif ($n == 2)
2014                 {
2015                         $green = 255 * $p;
2016                         $blue  = 255;
2017                 }
2018                 elsif ($n == 3)
2019                 {
2020                         $green = 255;
2021                         $blue  = 255 * $q;
2022                 }
2023                 elsif ($n == 4)
2024                 {
2025                         $red   = 255 * $p;
2026                         $green = 255;
2027                 }
2028                 elsif ($n == 5)
2029                 {
2030                         $red   = 255;
2031                         $green = 255 * $q;
2032                 }
2033                 else { die; }
2034
2035                 push (@ret, sprintf ("%02x%02x%02x", $red, $green, $blue));
2036         }
2037
2038         return (@ret);
2039 }