contrib/collection.cgi: Added graphs for `opcode' RRD-files (from the dns plugin)
[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                 opcode => [
657                         'DEF:avg={file}:value:AVERAGE',
658                         'DEF:min={file}:value:MIN',
659                         'DEF:max={file}:value:MAX',
660                         "AREA:max#$HalfBlue",
661                         "AREA:min#$Canvas",
662                         "LINE1:avg#$FullBlue:Queries/s",
663                         'GPRINT:min:MIN:%9.3lf Min,',
664                         'GPRINT:avg:AVERAGE:%9.3lf Average,',
665                         'GPRINT:max:MAX:%9.3lf Max,',
666                         'GPRINT:avg:LAST:%9.3lf Last\l'
667                 ],
668                 partition => [
669                         "DEF:rbyte_avg={file}:rbytes:AVERAGE",
670                         "DEF:rbyte_min={file}:rbytes:MIN",
671                         "DEF:rbyte_max={file}:rbytes:MAX",
672                         "DEF:wbyte_avg={file}:wbytes:AVERAGE",
673                         "DEF:wbyte_min={file}:wbytes:MIN",
674                         "DEF:wbyte_max={file}:wbytes:MAX",
675                         'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
676                         "AREA:wbyte_avg#$HalfGreen",
677                         "AREA:rbyte_avg#$HalfBlue",
678                         "AREA:overlap#$HalfBlueGreen",
679                         "LINE1:wbyte_avg#$FullGreen:Write",
680                         'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
681                         'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
682                         'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
683                         'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
684                         "LINE1:rbyte_avg#$FullBlue:Read ",
685                         'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
686                         'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
687                         'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
688                         'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l'
689                 ],
690                 ping => ['DEF:ping_avg={file}:ping:AVERAGE',
691                         'DEF:ping_min={file}:ping:MIN',
692                         'DEF:ping_max={file}:ping:MAX',
693                         "AREA:ping_max#$HalfBlue",
694                         "AREA:ping_min#$Canvas",
695                         "LINE1:ping_avg#$FullBlue:Ping",
696                         'GPRINT:ping_min:MIN:%4.1lf ms Min,',
697                         'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
698                         'GPRINT:ping_max:MAX:%4.1lf ms Max,',
699                         'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
700                 processes => [
701                         "DEF:running_avg={file}:running:AVERAGE",
702                         "DEF:running_min={file}:running:MIN",
703                         "DEF:running_max={file}:running:MAX",
704                         "DEF:sleeping_avg={file}:sleeping:AVERAGE",
705                         "DEF:sleeping_min={file}:sleeping:MIN",
706                         "DEF:sleeping_max={file}:sleeping:MAX",
707                         "DEF:zombies_avg={file}:zombies:AVERAGE",
708                         "DEF:zombies_min={file}:zombies:MIN",
709                         "DEF:zombies_max={file}:zombies:MAX",
710                         "DEF:stopped_avg={file}:stopped:AVERAGE",
711                         "DEF:stopped_min={file}:stopped:MIN",
712                         "DEF:stopped_max={file}:stopped:MAX",
713                         "DEF:paging_avg={file}:paging:AVERAGE",
714                         "DEF:paging_min={file}:paging:MIN",
715                         "DEF:paging_max={file}:paging:MAX",
716                         "DEF:blocked_avg={file}:blocked:AVERAGE",
717                         "DEF:blocked_min={file}:blocked:MIN",
718                         "DEF:blocked_max={file}:blocked:MAX",
719                         'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
720                         'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
721                         'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
722                         'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
723                         'CDEF:running_acc=sleeping_avg,running_avg,+',
724                         'CDEF:sleeping_acc=sleeping_avg',
725                         "AREA:paging_acc#$HalfYellow",
726                         "AREA:blocked_acc#$HalfCyan",
727                         "AREA:zombies_acc#$HalfRed",
728                         "AREA:stopped_acc#$HalfMagenta",
729                         "AREA:running_acc#$HalfGreen",
730                         "AREA:sleeping_acc#$HalfBlue",
731                         "LINE1:paging_acc#$FullYellow:Paging  ",
732                         'GPRINT:paging_min:MIN:%5.1lf Min,',
733                         'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
734                         'GPRINT:paging_max:MAX:%5.1lf Max,',
735                         'GPRINT:paging_avg:LAST:%5.1lf Last\l',
736                         "LINE1:blocked_acc#$FullCyan:Blocked ",
737                         'GPRINT:blocked_min:MIN:%5.1lf Min,',
738                         'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
739                         'GPRINT:blocked_max:MAX:%5.1lf Max,',
740                         'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
741                         "LINE1:zombies_acc#$FullRed:Zombies ",
742                         'GPRINT:zombies_min:MIN:%5.1lf Min,',
743                         'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
744                         'GPRINT:zombies_max:MAX:%5.1lf Max,',
745                         'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
746                         "LINE1:stopped_acc#$FullMagenta:Stopped ",
747                         'GPRINT:stopped_min:MIN:%5.1lf Min,',
748                         'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
749                         'GPRINT:stopped_max:MAX:%5.1lf Max,',
750                         'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
751                         "LINE1:running_acc#$FullGreen:Running ",
752                         'GPRINT:running_min:MIN:%5.1lf Min,',
753                         'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
754                         'GPRINT:running_max:MAX:%5.1lf Max,',
755                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
756                         "LINE1:sleeping_acc#$FullBlue:Sleeping",
757                         'GPRINT:sleeping_min:MIN:%5.1lf Min,',
758                         'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
759                         'GPRINT:sleeping_max:MAX:%5.1lf Max,',
760                         'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
761                 ],
762                 ps_rss => [
763                         'DEF:avg={file}:byte:AVERAGE',
764                         'DEF:min={file}:byte:MIN',
765                         'DEF:max={file}:byte:MAX',
766                         "AREA:avg#$HalfBlue",
767                         "LINE1:avg#$FullBlue:RSS",
768                         'GPRINT:min:MIN:%5.1lf%s Min,',
769                         'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
770                         'GPRINT:max:MAX:%5.1lf%s Max,',
771                         'GPRINT:avg:LAST:%5.1lf%s Last\l'
772                 ],
773                 ps_cputime => [
774                         'DEF:user_avg_raw={file}:user:AVERAGE',
775                         'DEF:user_min_raw={file}:user:MIN',
776                         'DEF:user_max_raw={file}:user:MAX',
777                         'DEF:syst_avg_raw={file}:syst:AVERAGE',
778                         'DEF:syst_min_raw={file}:syst:MIN',
779                         'DEF:syst_max_raw={file}:syst:MAX',
780                         'CDEF:user_avg=user_avg_raw,1000000,/',
781                         'CDEF:user_min=user_min_raw,1000000,/',
782                         'CDEF:user_max=user_max_raw,1000000,/',
783                         'CDEF:syst_avg=syst_avg_raw,1000000,/',
784                         'CDEF:syst_min=syst_min_raw,1000000,/',
785                         'CDEF:syst_max=syst_max_raw,1000000,/',
786                         'CDEF:user_syst=syst_avg,UN,0,syst_avg,IF,user_avg,+',
787                         "AREA:user_syst#$HalfBlue",
788                         "AREA:syst_avg#$HalfRed",
789                         "LINE1:user_syst#$FullBlue:User  ",
790                         'GPRINT:user_min:MIN:%5.1lf%s Min,',
791                         'GPRINT:user_avg:AVERAGE:%5.1lf%s Avg,',
792                         'GPRINT:user_max:MAX:%5.1lf%s Max,',
793                         'GPRINT:user_avg:LAST:%5.1lf%s Last\l',
794                         "LINE1:syst_avg#$FullRed:System",
795                         'GPRINT:syst_min:MIN:%5.1lf%s Min,',
796                         'GPRINT:syst_avg:AVERAGE:%5.1lf%s Avg,',
797                         'GPRINT:syst_max:MAX:%5.1lf%s Max,',
798                         'GPRINT:syst_avg:LAST:%5.1lf%s Last\l'
799                 ],
800                 ps_count => [
801                         'DEF:procs_avg={file}:processes:AVERAGE',
802                         'DEF:procs_min={file}:processes:MIN',
803                         'DEF:procs_max={file}:processes:MAX',
804                         'DEF:thrds_avg={file}:threads:AVERAGE',
805                         'DEF:thrds_min={file}:threads:MIN',
806                         'DEF:thrds_max={file}:threads:MAX',
807                         "AREA:thrds_avg#$HalfBlue",
808                         "AREA:procs_avg#$HalfRed",
809                         "LINE1:thrds_avg#$FullBlue:Threads  ",
810                         'GPRINT:thrds_min:MIN:%5.1lf Min,',
811                         'GPRINT:thrds_avg:AVERAGE:%5.1lf Avg,',
812                         'GPRINT:thrds_max:MAX:%5.1lf Max,',
813                         'GPRINT:thrds_avg:LAST:%5.1lf Last\l',
814                         "LINE1:procs_avg#$FullRed:Processes",
815                         'GPRINT:procs_min:MIN:%5.1lf Min,',
816                         'GPRINT:procs_avg:AVERAGE:%5.1lf Avg,',
817                         'GPRINT:procs_max:MAX:%5.1lf Max,',
818                         'GPRINT:procs_avg:LAST:%5.1lf Last\l'
819                 ],
820                 ps_pagefaults => [
821                         'DEF:minor_avg={file}:minflt:AVERAGE',
822                         'DEF:minor_min={file}:minflt:MIN',
823                         'DEF:minor_max={file}:minflt:MAX',
824                         'DEF:major_avg={file}:majflt:AVERAGE',
825                         'DEF:major_min={file}:majflt:MIN',
826                         'DEF:major_max={file}:majflt:MAX',
827                         'CDEF:minor_major=major_avg,UN,0,major_avg,IF,minor_avg,+',
828                         "AREA:minor_major#$HalfBlue",
829                         "AREA:major_avg#$HalfRed",
830                         "LINE1:minor_major#$FullBlue:Minor",
831                         'GPRINT:minor_min:MIN:%5.1lf%s Min,',
832                         'GPRINT:minor_avg:AVERAGE:%5.1lf%s Avg,',
833                         'GPRINT:minor_max:MAX:%5.1lf%s Max,',
834                         'GPRINT:minor_avg:LAST:%5.1lf%s Last\l',
835                         "LINE1:major_avg#$FullRed:Major",
836                         'GPRINT:major_min:MIN:%5.1lf%s Min,',
837                         'GPRINT:major_avg:AVERAGE:%5.1lf%s Avg,',
838                         'GPRINT:major_max:MAX:%5.1lf%s Max,',
839                         'GPRINT:major_avg:LAST:%5.1lf%s Last\l'
840                 ],
841                 qtype => [
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                 rcode => [
854                         'DEF:avg={file}:value:AVERAGE',
855                         'DEF:min={file}:value:MIN',
856                         'DEF:max={file}:value:MAX',
857                         "AREA:max#$HalfBlue",
858                         "AREA:min#$Canvas",
859                         "LINE1:avg#$FullBlue:Queries/s",
860                         'GPRINT:min:MIN:%9.3lf Min,',
861                         'GPRINT:avg:AVERAGE:%9.3lf Average,',
862                         'GPRINT:max:MAX:%9.3lf Max,',
863                         'GPRINT:avg:LAST:%9.3lf Last\l'
864                 ],
865                 swap => [
866                         'DEF:used_avg={file}:used:AVERAGE',
867                         'DEF:used_min={file}:used:MIN',
868                         'DEF:used_max={file}:used:MAX',
869                         'DEF:free_avg={file}:free:AVERAGE',
870                         'DEF:free_min={file}:free:MIN',
871                         'DEF:free_max={file}:free:MAX',
872                         'DEF:cach_avg={file}:cached:AVERAGE',
873                         'DEF:cach_min={file}:cached:MIN',
874                         'DEF:cach_max={file}:cached:MAX',
875                         'DEF:resv_avg={file}:resv:AVERAGE',
876                         'DEF:resv_min={file}:resv:MIN',
877                         'DEF:resv_max={file}:resv:MAX',
878                         'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
879                         'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
880                         'CDEF:used_acc=used_avg',
881                         'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
882                         'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
883                         'CDEF:free_acc=cach_acc,free_avg,+',
884                         "AREA:free_acc#$HalfGreen",
885                         "AREA:cach_acc#$HalfBlue",
886                         "AREA:resv_acc#$HalfYellow",
887                         "AREA:used_acc#$HalfRed",
888                         "LINE1:free_acc#$FullGreen:Free    ",
889                         'GPRINT:free_min:MIN:%5.1lf%s Min,',
890                         'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
891                         'GPRINT:free_max:MAX:%5.1lf%s Max,',
892                         'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
893                         "LINE1:cach_acc#$FullBlue:Cached  ",
894                         'GPRINT:cach_min:MIN:%5.1lf%s Min,',
895                         'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
896                         'GPRINT:cach_max:MAX:%5.1lf%s Max,',
897                         'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
898                         "LINE1:resv_acc#$FullYellow:Reserved",
899                         'GPRINT:resv_min:MIN:%5.1lf%s Min,',
900                         'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
901                         'GPRINT:resv_max:MAX:%5.1lf%s Max,',
902                         'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
903                         "LINE1:used_acc#$FullRed:Used    ",
904                         'GPRINT:used_min:MIN:%5.1lf%s Min,',
905                         'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
906                         'GPRINT:used_max:MAX:%5.1lf%s Max,',
907                         'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
908                 ],
909                 temperature => [
910                         'DEF:temp_avg={file}:value:AVERAGE',
911                         'DEF:temp_min={file}:value:MIN',
912                         'DEF:temp_max={file}:value:MAX',
913                         "AREA:temp_max#$HalfRed",
914                         "AREA:temp_min#$Canvas",
915                         "LINE1:temp_avg#$FullRed:Temperature",
916                         'GPRINT:temp_min:MIN:%4.1lf Min,',
917                         'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
918                         'GPRINT:temp_max:MAX:%4.1lf Max,',
919                         'GPRINT:temp_avg:LAST:%4.1lf Last\l'
920                 ],
921                 timeleft => [
922                         'DEF:avg={file}:timeleft:AVERAGE',
923                         'DEF:min={file}:timeleft:MIN',
924                         'DEF:max={file}:timeleft:MAX',
925                         "AREA:max#$HalfBlue",
926                         "AREA:min#$Canvas",
927                         "LINE1:avg#$FullBlue:Time left [min]",
928                         'GPRINT:min:MIN:%5.1lf%s Min,',
929                         'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
930                         'GPRINT:max:MAX:%5.1lf%s Max,',
931                         'GPRINT:avg:LAST:%5.1lf%s Last\l'
932                 ],
933                 time_offset => [ # NTPd
934                         'DEF:s_avg={file}:seconds:AVERAGE',
935                         'DEF:s_min={file}:seconds:MIN',
936                         'DEF:s_max={file}:seconds:MAX',
937                         "AREA:s_max#$HalfBlue",
938                         "AREA:s_min#$Canvas",
939                         "LINE1:s_avg#$FullBlue:{inst}",
940                         'GPRINT:s_min:MIN:%7.3lf%s Min,',
941                         'GPRINT:s_avg:AVERAGE:%7.3lf%s Avg,',
942                         'GPRINT:s_max:MAX:%7.3lf%s Max,',
943                         'GPRINT:s_avg:LAST:%7.3lf%s Last'
944                 ],
945                 traffic => ['DEF:out_min_raw={file}:outgoing:MIN',
946                         'DEF:out_avg_raw={file}:outgoing:AVERAGE',
947                         'DEF:out_max_raw={file}:outgoing:MAX',
948                         'DEF:inc_min_raw={file}:incoming:MIN',
949                         'DEF:inc_avg_raw={file}:incoming:AVERAGE',
950                         'DEF:inc_max_raw={file}:incoming:MAX',
951                         'CDEF:out_min=out_min_raw,8,*',
952                         'CDEF:out_avg=out_avg_raw,8,*',
953                         'CDEF:out_max=out_max_raw,8,*',
954                         'CDEF:inc_min=inc_min_raw,8,*',
955                         'CDEF:inc_avg=inc_avg_raw,8,*',
956                         'CDEF:inc_max=inc_max_raw,8,*',
957                         'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
958                         'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
959                         'CDEF:sample_len_raw=mytime,PREV(mytime),-',
960                         'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
961                         'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
962                         'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
963                         'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
964                         'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
965                         "AREA:out_avg#$HalfGreen",
966                         "AREA:inc_avg#$HalfBlue",
967                         "AREA:overlap#$HalfBlueGreen",
968                         "LINE1:out_avg#$FullGreen:Outgoing",
969                         'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
970                         'GPRINT:out_max:MAX:%5.1lf%s Max,',
971                         'GPRINT:out_avg:LAST:%5.1lf%s Last',
972                         'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
973                         "LINE1:inc_avg#$FullBlue:Incoming",
974                         #'GPRINT:inc_min:MIN:%5.1lf %s Min,',
975                         'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
976                         'GPRINT:inc_max:MAX:%5.1lf%s Max,',
977                         'GPRINT:inc_avg:LAST:%5.1lf%s Last',
978                         'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
979                 ],
980                 cpufreq => [
981                         'DEF:cpufreq_avg={file}:value:AVERAGE',
982                         'DEF:cpufreq_min={file}:value:MIN',
983                         'DEF:cpufreq_max={file}:value:MAX',
984                         "AREA:cpufreq_max#$HalfBlue",
985                         "AREA:cpufreq_min#$Canvas",
986                         "LINE1:cpufreq_avg#$FullBlue:Frequency",
987                         'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
988                         'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
989                         'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
990                         'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l'
991                 ],
992                 multimeter => [
993                             'DEF:multimeter_avg={file}:value:AVERAGE',
994                             'DEF:multimeter_min={file}:value:MIN',
995                             'DEF:multimeter_max={file}:value:MAX',
996                             "AREA:multimeter_max#$HalfBlue",
997                             "AREA:multimeter_min#$Canvas",
998                             "LINE1:multimeter_avg#$FullBlue:Multimeter",
999                             'GPRINT:multimeter_min:MIN:%4.1lf Min,',
1000                             'GPRINT:multimeter_avg:AVERAGE:%4.1lf Average,',
1001                             'GPRINT:multimeter_max:MAX:%4.1lf Max,',
1002                             'GPRINT:multimeter_avg:LAST:%4.1lf Last\l'
1003                 ],
1004                 users => [
1005                             'DEF:users_avg={file}:users:AVERAGE',
1006                             'DEF:users_min={file}:users:MIN',
1007                             'DEF:users_max={file}:users:MAX',
1008                             "AREA:users_max#$HalfBlue",
1009                             "AREA:users_min#$Canvas",
1010                             "LINE1:users_avg#$FullBlue:Users",
1011                             'GPRINT:users_min:MIN:%4.1lf Min,',
1012                             'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
1013                             'GPRINT:users_max:MAX:%4.1lf Max,',
1014                             'GPRINT:users_avg:LAST:%4.1lf Last\l'
1015                 ],
1016                 voltage => [
1017                         'DEF:avg={file}:voltage:AVERAGE',
1018                         'DEF:min={file}:voltage:MIN',
1019                         'DEF:max={file}:voltage:MAX',
1020                         "AREA:max#$HalfBlue",
1021                         "AREA:min#$Canvas",
1022                         "LINE1:avg#$FullBlue:Voltage",
1023                         'GPRINT:min:MIN:%5.1lf%sV Min,',
1024                         'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
1025                         'GPRINT:max:MAX:%5.1lf%sV Max,',
1026                         'GPRINT:avg:LAST:%5.1lf%sV Last\l'
1027                 ],
1028                 vs_threads => [
1029                         "DEF:total_avg={file}:total:AVERAGE",
1030                         "DEF:total_min={file}:total:MIN",
1031                         "DEF:total_max={file}:total:MAX",
1032                         "DEF:running_avg={file}:running:AVERAGE",
1033                         "DEF:running_min={file}:running:MIN",
1034                         "DEF:running_max={file}:running:MAX",
1035                         "DEF:uninterruptible_avg={file}:uninterruptible:AVERAGE",
1036                         "DEF:uninterruptible_min={file}:uninterruptible:MIN",
1037                         "DEF:uninterruptible_max={file}:uninterruptible:MAX",
1038                         "DEF:onhold_avg={file}:onhold:AVERAGE",
1039                         "DEF:onhold_min={file}:onhold:MIN",
1040                         "DEF:onhold_max={file}:onhold:MAX",
1041                         "LINE1:total_avg#$FullYellow:Total   ",
1042                         'GPRINT:total_min:MIN:%5.1lf Min,',
1043                         'GPRINT:total_avg:AVERAGE:%5.1lf Avg.,',
1044                         'GPRINT:total_max:MAX:%5.1lf Max,',
1045                         'GPRINT:total_avg:LAST:%5.1lf Last\l',
1046                         "LINE1:running_avg#$FullRed:Running ",
1047                         'GPRINT:running_min:MIN:%5.1lf Min,',
1048                         'GPRINT:running_avg:AVERAGE:%5.1lf Avg.,',          
1049                         'GPRINT:running_max:MAX:%5.1lf Max,',
1050                         'GPRINT:running_avg:LAST:%5.1lf Last\l',
1051                         "LINE1:uninterruptible_avg#$FullGreen:Unintr  ",
1052                         'GPRINT:uninterruptible_min:MIN:%5.1lf Min,',
1053                         'GPRINT:uninterruptible_avg:AVERAGE:%5.1lf Avg.,',
1054                         'GPRINT:uninterruptible_max:MAX:%5.1lf Max,',
1055                         'GPRINT:uninterruptible_avg:LAST:%5.1lf Last\l',
1056                         "LINE1:onhold_avg#$FullBlue:Onhold  ",
1057                         'GPRINT:onhold_min:MIN:%5.1lf Min,',
1058                         'GPRINT:onhold_avg:AVERAGE:%5.1lf Avg.,',
1059                         'GPRINT:onhold_max:MAX:%5.1lf Max,',
1060                         'GPRINT:onhold_avg:LAST:%5.1lf Last\l'
1061                 ],
1062                 vs_memory => [
1063                         'DEF:vm_avg={file}:vm:AVERAGE',
1064                         'DEF:vm_min={file}:vm:MIN',
1065                         'DEF:vm_max={file}:vm:MAX',
1066                         'DEF:vml_avg={file}:vml:AVERAGE',
1067                         'DEF:vml_min={file}:vml:MIN',
1068                         'DEF:vml_max={file}:vml:MAX',
1069                         'DEF:rss_avg={file}:rss:AVERAGE',
1070                         'DEF:rss_min={file}:rss:MIN',
1071                         'DEF:rss_max={file}:rss:MAX',
1072                         'DEF:anon_avg={file}:anon:AVERAGE',
1073                         'DEF:anon_min={file}:anon:MIN',
1074                         'DEF:anon_max={file}:anon:MAX',
1075                         "LINE1:vm_avg#$FullYellow:VM     ",
1076                         'GPRINT:vm_min:MIN:%5.1lf%s Min,',
1077                         'GPRINT:vm_avg:AVERAGE:%5.1lf%s Avg.,',
1078                         'GPRINT:vm_max:MAX:%5.1lf%s Avg.,',
1079                         'GPRINT:vm_avg:LAST:%5.1lf%s Last\l',
1080                         "LINE1:vml_avg#$FullRed:Locked ",
1081                         'GPRINT:vml_min:MIN:%5.1lf%s Min,',
1082                         'GPRINT:vml_avg:AVERAGE:%5.1lf%s Avg.,',
1083                         'GPRINT:vml_max:MAX:%5.1lf%s Avg.,',
1084                         'GPRINT:vml_avg:LAST:%5.1lf%s Last\l',
1085                         "LINE1:rss_avg#$FullGreen:RSS    ",
1086                         'GPRINT:rss_min:MIN:%5.1lf%s Min,',
1087                         'GPRINT:rss_avg:AVERAGE:%5.1lf%s Avg.,',
1088                         'GPRINT:rss_max:MAX:%5.1lf%s Avg.,',
1089                         'GPRINT:rss_avg:LAST:%5.1lf%s Last\l',
1090                         "LINE1:anon_avg#$FullBlue:Anon.  ",
1091                         'GPRINT:anon_min:MIN:%5.1lf%s Min,',
1092                         'GPRINT:anon_avg:AVERAGE:%5.1lf%s Avg.,',
1093                         'GPRINT:anon_max:MAX:%5.1lf%s Avg.,',
1094                         'GPRINT:anon_avg:LAST:%5.1lf%s Last\l',
1095                 ],
1096                 vs_processes => [
1097                         'DEF:proc_avg={file}:total:AVERAGE',
1098                         'DEF:proc_min={file}:total:MIN',
1099                         'DEF:proc_max={file}:total:MAX',
1100                         "AREA:proc_max#$HalfBlue",
1101                         "AREA:proc_min#$Canvas",
1102                         "LINE1:proc_avg#$FullBlue:Processes",
1103                         'GPRINT:proc_min:MIN:%4.1lf Min,',
1104                         'GPRINT:proc_avg:AVERAGE:%4.1lf Avg.,',
1105                         'GPRINT:proc_max:MAX:%4.1lf Max,',
1106                         'GPRINT:proc_avg:LAST:%4.1lf Last\l'
1107                 ],
1108         };
1109         $GraphDefs->{'disk'} = $GraphDefs->{'partition'};
1110         $GraphDefs->{'if_errors'} = $GraphDefs->{'if_packets'};
1111         $GraphDefs->{'meminfo'} = $GraphDefs->{'memory'};
1112         $GraphDefs->{'sensors'} = $GraphDefs->{'temperature'};
1113
1114         $GraphDefs->{'delay'}           = $GraphDefs->{'time_offset'};
1115         $GraphDefs->{'time_dispersion'} = $GraphDefs->{'time_offset'};
1116 }
1117
1118 our $GraphArgs =
1119 {
1120         apache_bytes => ['-t', 'apache traffic', '-v', 'Bit/s'],
1121         apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
1122         apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
1123         charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
1124         charge_percent => ['-t', '{host} charge', '-v', 'Percent'],
1125         cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
1126         cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
1127         current => ['-t', '{host} current', '-v', 'Ampere'],
1128         #disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'],
1129         delay => ['-t', 'NTPd peer delay ({inst})', '-v', 'Seconds'],
1130         df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'],
1131         disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'],
1132         dns_traffic => ['-t', '{host} DNS traffic', '-v', 'Bit/s'],
1133         fanspeed => ['-t', '{host} fanspeed {inst}', '-v', 'RPM'],
1134         frequency_offset => ['-t', 'NTPd frequency offset ({inst})', '-v', 'Parts per million'],
1135         hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'],
1136         if_errors => ['-t', '{host} {inst} errors', '-v', 'Errors/s'],
1137         if_packets => ['-t', '{host} {inst} packets', '-v', 'Packets/s'],
1138         load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'],
1139         load_percent => ['-t', '{host} load', '-v', 'Percent'],
1140         mails   => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'],
1141         memory => ['-t', '{host} memory usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
1142         mysql_commands => ['-t', 'mysql command {inst}', '-v', 'Issues/s' ],
1143         mysql_handler => ['-t', 'mysql handler {inst}', '-v', 'Issues/s' ],
1144         mysql_qcache => ['-t', 'mysql query cache', '-v', 'Queries/s' ],
1145         mysql_threads => ['-t', 'mysql threads', '-v', 'Threads' ],
1146         nfs3_procedures => ['-t', '{host} NFSv3 {inst} procedures', '-v', 'Procedures/s' ],
1147         opcode => ['-t', 'OpCode {inst}', '-v', 'Queries/s'],
1148         partition => ['-t', '{host} partition {inst} usage', '-v', 'Byte/s'],
1149         ping => ['-t', '{host} ping to {inst}', '-v', 'ms'],
1150         processes => ['-t', '{host} processes', '-v', 'Processes'],
1151         ps_rss => ['-t', '{host} process {inst} RSS', '-v', 'Bytes', '-b', '1024'],
1152         ps_cputime => ['-t', '{host} process {inst} CPU usage', '-v', 'Seconds'],
1153         ps_count => ['-t', '{host} process {inst} count', '-v', 'Threads/Processes'],
1154         ps_pagefaults => ['-t', '{host} process {inst} pagefaults', '-v', 'Pagefaults/s'],
1155         qtype => ['-t', 'QType {inst}', '-v', 'Queries/s'],
1156         rcode => ['-t', 'RCode {inst}', '-v', 'Queries/s'],
1157         sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'],
1158         swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
1159         temperature => ['-t', '{host} temperature {inst}', '-v', '°Celsius'],
1160         timeleft => ['-t', '{host} UPS time left', '-v', 'Time [min]'],
1161         time_offset => ['-t', 'NTPd time offset ({inst})', '-v', 'Seconds'],
1162         time_dispersion => ['-t', 'NTPd time dispersion ({inst})', '-v', 'Seconds'],
1163         traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'],
1164         users => ['-t', '{host} users', '-v', 'Users'],
1165         multimeter => ['-t', '{host} multimeter', '-v', 'Value'],
1166         voltage => ['-t', '{host} voltage {inst}', '-v', 'Volts'],
1167         vs_threads => ['-t', '{host} threads', '-v', 'Threads'],
1168         vs_memory => ['-t', '{host} memory usage', '-v', 'Bytes'],
1169         vs_processes => ['-t', '{host} processes', '-v', 'Processes'],
1170 };
1171
1172 our $GraphMulti =
1173 {
1174         apache_scoreboard => \&output_graph_apache_scoreboard,
1175         cpu     => \&output_graph_cpu,
1176         cpufreq => 1,
1177         disk    => 1,
1178         load    => 0,
1179         mails   => 0,
1180         memory  => 0,
1181         mysql_commands => \&output_graph_mysql_commands,
1182         mysql_handler => \&output_graph_mysql_handler,
1183         partition => 1,
1184         ping    => \&output_graph_ping,
1185         qtype => \&output_graph_named_qtype,
1186         rcode => \&output_graph_named_rcode,
1187         sensors => 1,
1188         traffic => 1,
1189         users => 1,
1190         multimeter => 1
1191 };
1192
1193 our @Info;
1194 if (defined ($ENV{'GATEWAY_INTERFACE'}))
1195 {
1196         @Info = ($ENV{'PATH_INFO'} || '') =~ m#([\w\-\.]+)#g;
1197 }
1198 else
1199 {
1200         @Info = @ARGV;
1201 }
1202
1203 parse_pathinfo (@Info);
1204
1205 if ($TimeSpan)
1206 {
1207         output_graph ();
1208 }
1209 else
1210 {
1211         output_page ();
1212 }
1213
1214 exit (0);
1215
1216 sub output_graph_cpu
1217 {
1218         my @inst = @_;
1219         my @ret = ();
1220
1221         die if (@inst < 2);
1222
1223         for (@inst)
1224         {
1225                 push (@ret,
1226                         "DEF:user_avg_$_=$AbsDir/cpu-$_.rrd:user:AVERAGE",
1227                         "DEF:user_min_$_=$AbsDir/cpu-$_.rrd:user:MIN",
1228                         "DEF:user_max_$_=$AbsDir/cpu-$_.rrd:user:MAX",
1229                         "DEF:nice_avg_$_=$AbsDir/cpu-$_.rrd:nice:AVERAGE",
1230                         "DEF:nice_min_$_=$AbsDir/cpu-$_.rrd:nice:MIN",
1231                         "DEF:nice_max_$_=$AbsDir/cpu-$_.rrd:nice:MAX",
1232                         "DEF:syst_avg_$_=$AbsDir/cpu-$_.rrd:syst:AVERAGE",
1233                         "DEF:syst_min_$_=$AbsDir/cpu-$_.rrd:syst:MIN",
1234                         "DEF:syst_max_$_=$AbsDir/cpu-$_.rrd:syst:MAX",
1235                         "DEF:wait_avg_$_=$AbsDir/cpu-$_.rrd:wait:AVERAGE",
1236                         "DEF:wait_min_$_=$AbsDir/cpu-$_.rrd:wait:MIN",
1237                         "DEF:wait_max_$_=$AbsDir/cpu-$_.rrd:wait:MAX");
1238         }
1239
1240         for (qw(user nice syst wait))
1241         {
1242                 my $def = $_;
1243                 my $cdef;
1244
1245                 my $default_value = ($def eq 'user' or $def eq 'syst') ? 'UNKN' : '0';
1246
1247                 for (qw(avg min max))
1248                 {
1249                         my $cf = $_;
1250
1251                         for (@inst)
1252                         {
1253                                 push (@ret, "CDEF:${def}_${cf}_notnull_${_}=${def}_${cf}_${_},UN,0,${def}_${cf}_${_},IF");
1254                                 push (@ret, "CDEF:${def}_${cf}_defined_${_}=${def}_${cf}_${_},UN,0,1,IF");
1255                         }
1256
1257                         $cdef = "CDEF:${def}_${cf}_num=" . join (',', map { "${def}_${cf}_defined_${_}" } (@inst));
1258                         $cdef .= ',+' x (scalar (@inst) - 1);
1259                         push (@ret, $cdef);
1260
1261                         $cdef = "CDEF:${def}_${cf}=${def}_${cf}_num," . join (',', map { "${def}_${cf}_notnull_${_}" } (@inst));
1262                         $cdef .= ',+' x (scalar (@inst) - 1);
1263                         $cdef .= ",${def}_${cf}_num,${def}_${cf}_num,1,IF,/,$default_value,IF";
1264                         push (@ret, $cdef);
1265                         push (@ret, "CDEF:${def}_${cf}_notnull=${def}_${cf},UN,0,${def}_${cf},IF");
1266                 }
1267         }
1268
1269         push (@ret,
1270                 "CDEF:nice_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,nice_avg_notnull,+,+,+",
1271                 "CDEF:user_acc=syst_avg_notnull,wait_avg_notnull,user_avg_notnull,+,+",
1272                 "CDEF:wait_acc=syst_avg_notnull,wait_avg_notnull,+",
1273                 "CDEF:syst_acc=syst_avg_notnull");
1274
1275         push (@ret, grep { $_ !~ m/^C?DEF/ } (@{$GraphDefs->{'cpu'}}));
1276
1277         return (@ret);
1278 }
1279
1280 sub output_graph_apache_scoreboard
1281 {
1282         my @inst = @_;
1283         my @ret = ();
1284
1285         die if (@inst < 2);
1286
1287         my @colors = get_n_colors (scalar (@inst));
1288
1289         for (my $i = 0; $i < scalar (@inst); $i++)
1290         {
1291                 my $inst = $inst[$i];
1292                 push (@ret,
1293                         "DEF:avg_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:AVERAGE",
1294                         "DEF:min_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MIN",
1295                         "DEF:max_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MAX");
1296         }
1297
1298         for (my $i = 0; $i < scalar (@inst); $i++)
1299         {
1300                 my $inst = $inst[$i];
1301                 my $color = $colors[$i];
1302
1303                 if (length ($inst) > 15)
1304                 {
1305                         $inst = substr ($inst, 0, 12) . '...';
1306                 }
1307                 else
1308                 {
1309                         $inst = sprintf ('%-15s', $inst);
1310                 }
1311
1312                 push (@ret,
1313                         "LINE1:avg_$i#$color:$inst",
1314                         "GPRINT:min_$i:MIN:%6.2lf Min,",
1315                         "GPRINT:avg_$i:AVERAGE:%6.2lf Avg,",
1316                         "GPRINT:max_$i:MAX:%6.2lf Max,",
1317                         "GPRINT:avg_$i:LAST:%6.2lf Last\\l");
1318         }
1319
1320         return (@ret);
1321 }
1322
1323 sub output_graph_ping
1324 {
1325         my @inst = @_;
1326         my @ret = ();
1327
1328         die if (@inst < 2);
1329
1330         my @colors = get_n_colors (scalar (@inst));
1331
1332         for (my $i = 0; $i < scalar (@inst); $i++)
1333         {
1334                 my $inst = $inst[$i];
1335                 push (@ret,
1336                         "DEF:avg_$i=$AbsDir/ping-$inst.rrd:ping:AVERAGE",
1337                         "DEF:min_$i=$AbsDir/ping-$inst.rrd:ping:MIN",
1338                         "DEF:max_$i=$AbsDir/ping-$inst.rrd:ping:MAX");
1339         }
1340
1341         for (my $i = 0; $i < scalar (@inst); $i++)
1342         {
1343                 my $inst = $inst[$i];
1344                 my $color = $colors[$i];
1345
1346                 if (length ($inst) > 15)
1347                 {
1348                         $inst = substr ($inst, 0, 12) . '...';
1349                 }
1350                 else
1351                 {
1352                         $inst = sprintf ('%-15s', $inst);
1353                 }
1354
1355                 push (@ret,
1356                         "LINE1:avg_$i#$color:$inst",
1357                         "GPRINT:min_$i:MIN:%4.1lf ms Min,",
1358                         "GPRINT:avg_$i:AVERAGE:%4.1lf ms Avg,",
1359                         "GPRINT:max_$i:MAX:%4.1lf ms Max,",
1360                         "GPRINT:avg_$i:LAST:%4.1lf ms Last\\l");
1361         }
1362
1363         return (@ret);
1364 }
1365
1366 sub output_graph_mysql_commands
1367 {
1368         my @inst = @_;
1369         my @ret = ();
1370
1371         die if (@inst < 2);
1372
1373         my @colors = get_n_colors (scalar (@inst));
1374
1375         for (my $i = 0; $i < scalar (@inst); $i++)
1376         {
1377                 my $inst = $inst[$i];
1378                 push (@ret,
1379                         "DEF:avg_$i=$AbsDir/mysql_commands-$inst.rrd:value:AVERAGE",
1380                         "DEF:min_$i=$AbsDir/mysql_commands-$inst.rrd:value:MIN",
1381                         "DEF:max_$i=$AbsDir/mysql_commands-$inst.rrd:value:MAX");
1382         }
1383
1384         for (my $i = 0; $i < scalar (@inst); $i++)
1385         {
1386                 my $inst = $inst[$i];
1387                 my $color = $colors[$i];
1388
1389                 if (length ($inst) > 18)
1390                 {
1391                         $inst = substr ($inst, 0, 15) . '...';
1392                 }
1393                 else
1394                 {
1395                         $inst = sprintf ('%-18s', $inst);
1396                 }
1397
1398                 push (@ret,
1399                         "LINE1:avg_$i#$color:$inst",
1400                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1401                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1402                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1403                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1404         }
1405
1406         return (@ret);
1407 }
1408
1409 sub output_graph_mysql_handler
1410 {
1411         my @inst = @_;
1412         my @ret = ();
1413
1414         die if (@inst < 2);
1415
1416         my @colors = get_n_colors (scalar (@inst));
1417
1418         for (my $i = 0; $i < scalar (@inst); $i++)
1419         {
1420                 my $inst = $inst[$i];
1421                 push (@ret,
1422                         "DEF:avg_$i=$AbsDir/mysql_handler-$inst.rrd:value:AVERAGE",
1423                         "DEF:min_$i=$AbsDir/mysql_handler-$inst.rrd:value:MIN",
1424                         "DEF:max_$i=$AbsDir/mysql_handler-$inst.rrd:value:MAX");
1425         }
1426
1427         for (my $i = 0; $i < scalar (@inst); $i++)
1428         {
1429                 my $inst = $inst[$i];
1430                 my $color = $colors[$i];
1431
1432                 if (length ($inst) > 18)
1433                 {
1434                         $inst = substr ($inst, 0, 15) . '...';
1435                 }
1436                 else
1437                 {
1438                         $inst = sprintf ('%-18s', $inst);
1439                 }
1440
1441                 push (@ret,
1442                         "LINE1:avg_$i#$color:$inst",
1443                         "GPRINT:min_$i:MIN:%6.1lf Min,",
1444                         "GPRINT:avg_$i:AVERAGE:%6.1lf Avg,",
1445                         "GPRINT:max_$i:MAX:%6.1lf Max,",
1446                         "GPRINT:avg_$i:LAST:%6.1lf Last\\l");
1447         }
1448
1449         return (@ret);
1450 }
1451
1452 sub output_graph_named_qtype
1453 {
1454         my @inst = @_;
1455         my @ret = ();
1456
1457         die if (@inst < 2);
1458
1459         my @colors = get_n_colors (scalar (@inst));
1460
1461         for (my $i = 0; $i < scalar (@inst); $i++)
1462         {
1463                 my $inst = $inst[$i];
1464                 push (@ret,
1465                         "DEF:avg_$i=$AbsDir/qtype-$inst.rrd:value:AVERAGE",
1466                         "DEF:min_$i=$AbsDir/qtype-$inst.rrd:value:MIN",
1467                         "DEF:max_$i=$AbsDir/qtype-$inst.rrd:value:MAX");
1468         }
1469
1470         for (my $i = 0; $i < scalar (@inst); $i++)
1471         {
1472                 my $inst = $inst[$i];
1473                 my $color = $colors[$i];
1474                 my $type = ($i == 0) ? 'AREA' : 'STACK';
1475
1476                 if (length ($inst) > 5)
1477                 {
1478                         $inst = substr ($inst, 0, 5);
1479                 }
1480                 else
1481                 {
1482                         $inst = sprintf ('%-5s', $inst);
1483                 }
1484
1485                 push (@ret,
1486                         "$type:avg_$i#$color:$inst",
1487                         "GPRINT:min_$i:MIN:%9.3lf Min,",
1488                         "GPRINT:avg_$i:AVERAGE:%9.3lf Avg,",
1489                         "GPRINT:max_$i:MAX:%9.3lf Max,",
1490                         "GPRINT:avg_$i:LAST:%9.3lf Last\\l");
1491         }
1492
1493         return (@ret);
1494 }
1495
1496 sub output_graph_named_rcode
1497 {
1498         my @inst = @_;
1499         my @ret = ();
1500
1501         die if (@inst < 2);
1502
1503         my @colors = get_n_colors (scalar (@inst));
1504
1505         for (my $i = 0; $i < scalar (@inst); $i++)
1506         {
1507                 my $inst = $inst[$i];
1508                 push (@ret,
1509                         "DEF:avg_$i=$AbsDir/rcode-$inst.rrd:value:AVERAGE",
1510                         "DEF:min_$i=$AbsDir/rcode-$inst.rrd:value:MIN",
1511                         "DEF:max_$i=$AbsDir/rcode-$inst.rrd:value:MAX");
1512         }
1513
1514         for (my $i = 0; $i < scalar (@inst); $i++)
1515         {
1516                 my $inst = $inst[$i];
1517                 my $color = $colors[$i];
1518                 my $type = ($i == 0) ? 'AREA' : 'STACK';
1519
1520                 if (length ($inst) > 8)
1521                 {
1522                         $inst = substr ($inst, 0, 6) . '..';
1523                 }
1524                 else
1525                 {
1526                         $inst = sprintf ('%-8s', $inst);
1527                 }
1528
1529                 push (@ret,
1530                         "$type:avg_$i#$color:$inst",
1531                         "GPRINT:min_$i:MIN:%9.3lf Min,",
1532                         "GPRINT:avg_$i:AVERAGE:%9.3lf Avg,",
1533                         "GPRINT:max_$i:MAX:%9.3lf Max,",
1534                         "GPRINT:avg_$i:LAST:%9.3lf Last\\l");
1535         }
1536
1537         return (@ret);
1538 }
1539 sub output_graph
1540 {
1541         die unless (defined ($GraphDefs->{$Type}));
1542
1543         my $host;
1544         my @cmd = ();
1545         my $file = $AbsDir . '/';
1546         my $files = get_all_files ($AbsDir);
1547
1548         #
1549         # get hostname
1550         #
1551         if ($RelDir =~ m#([^/]+)$#)
1552         {
1553                 $host = $1;
1554         }
1555         else
1556         {
1557                 $host = $Config->{'HostName'};
1558         }
1559
1560         #
1561         # get timespan
1562         #
1563         if ($TimeSpan =~ m/(\d+)/)
1564         {
1565                 $TimeSpan = -1 * int ($1);
1566         }
1567         else
1568         {
1569                 my %t = (hour => -3600, day => -86400, week => -604800, month => -2678400, year => -31622400);
1570                 die unless (defined ($t{$TimeSpan}));
1571                 $TimeSpan = $t{$TimeSpan};
1572         }
1573
1574         if (scalar (@{$files->{$Type}}) == 1)
1575         {
1576                 $Inst = $files->{$Type}[0];
1577         }
1578
1579         #push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan, '-w', 800, '-h', 150);
1580         push (@cmd, '-', '-a', 'PNG', '-s', $TimeSpan);
1581         push (@cmd, @{$GraphArgs->{$Type}}) if (defined ($GraphArgs->{$Type}));
1582
1583         for (qw(Back ShadeA ShadeB Font Canvas Grid MGrid Frame Arrow))
1584         {
1585                 push (@cmd, '-c', uc ($_) . '#' . $Config->{'Colors'}{$_});
1586         }
1587
1588         if ((length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE'))
1589         {
1590                 push (@cmd, $GraphMulti->{$Type}->(@{$files->{$Type}}));
1591         }
1592         else
1593         {
1594                 if (length ("$Inst"))
1595                 {
1596                         $file .= "$Type-$Inst.rrd";
1597                 }
1598                 else
1599                 {
1600                         $file .= "$Type.rrd";
1601                 }
1602
1603                 die ("File not found: $file") unless (-e $file);
1604
1605                 push (@cmd, @{$GraphDefs->{$Type}});
1606         }
1607
1608         for (@cmd)
1609         {
1610                 $_ =~ s/{file}/$file/g;
1611                 $_ =~ s/{host}/$host/g;
1612                 $_ =~ s/{inst}/$Inst/g;
1613                 $_ =~ s/{type}/$Type/g;
1614         }
1615
1616         $| = 1;
1617
1618         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1619 Content-Type: image/png
1620 Cache-Control: no-cache
1621
1622 HEADER
1623
1624         if (1)
1625         {
1626                 my $fh;
1627                 open ($fh, ">/tmp/collection.log") or die ("open: $!");
1628                 flock ($fh, LOCK_EX) or die ("flock: $!");
1629
1630                 print $fh join ("\n\t", @cmd) . "\n";
1631
1632                 close ($fh);
1633         }
1634
1635         RRDs::graph (@cmd);
1636
1637         die ('RRDs::error: ' . RRDs::error ()) if (RRDs::error ());
1638 }
1639
1640 sub output_page
1641 {
1642         my $files = get_all_files ($AbsDir);
1643         my $dirs  = get_all_dirs  ($AbsDir);
1644
1645         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1646 Content-Type: text/html
1647 Cache-Control: no-cache
1648
1649 <html>
1650         <head>
1651                 <title>Collection: $RelDir</title>
1652                 <style type="text/css">
1653                         img { border: none; display: block; }
1654                 </style>
1655         </head>
1656
1657         <body>
1658 HEADER
1659
1660         my $MySelf = defined ($ENV{'GATEWAY_INTERFACE'}) ? $ENV{'SCRIPT_NAME'} : $0;
1661
1662         if ((length ($Type) != 0) and (length ($Inst) == 0) and (ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1663         {
1664                 print qq(\t\t<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1665
1666                 print "\t\t<ul>\n";
1667                 for (@{$files->{$Type}})
1668                 {
1669                         print qq(\t\t\t<li><a href="$MySelf$RelDir/$Type/$_">$_</a></li>\n);
1670                 }
1671                 print <<HTML;
1672                 </ul>
1673
1674                 <h3>Hourly</h3>
1675                 <div><img src="$MySelf$RelDir/$Type/hour" /></div>
1676                 <h3>Daily</h3>
1677                 <div><img src="$MySelf$RelDir/$Type/day" /></div>
1678                 <h3>Weekly</h3>
1679                 <div><img src="$MySelf$RelDir/$Type/week" /></div>
1680                 <h3>Monthly</h3>
1681                 <div><img src="$MySelf$RelDir/$Type/month" /></div>
1682                 <h3>Yearly</h3>
1683                 <div><img src="$MySelf$RelDir/$Type/year" /></div>
1684 HTML
1685         }
1686         elsif (length ($Type) != 0)
1687         {
1688                 my $ext = length ($Inst) ? "$Type/$Inst" : $Type;
1689
1690                 if ((ref ($GraphMulti->{$Type}) eq 'CODE') and (scalar (@{$files->{$Type}}) > 1))
1691                 {
1692                         print qq(<div><a href="$MySelf$RelDir/$Type">Go up</a></div>\n);
1693                 }
1694                 else
1695                 {
1696                         print qq(<div><a href="$MySelf$RelDir">Go up</a></div>\n);
1697                 }
1698
1699                 print <<HTML;
1700                 <h3>Hourly</h3>
1701                 <div><img src="$MySelf$RelDir/$ext/hour" /></div>
1702                 <h3>Daily</h3>
1703                 <div><img src="$MySelf$RelDir/$ext/day" /></div>
1704                 <h3>Weekly</h3>
1705                 <div><img src="$MySelf$RelDir/$ext/week" /></div>
1706                 <h3>Monthly</h3>
1707                 <div><img src="$MySelf$RelDir/$ext/month" /></div>
1708                 <h3>Yearly</h3>
1709                 <div><img src="$MySelf$RelDir/$ext/year" /></div>
1710 HTML
1711         }
1712         else
1713         {
1714                 if ($RelDir)
1715                 {
1716                         my ($up) = $RelDir =~ m#(.*)/[^/]+$#;
1717                         print qq(\t\t<div><a href="$MySelf$up">Go up</a></div>\n);
1718                 }
1719
1720                 if (@$dirs)
1721                 {
1722                         print "<ul>\n";
1723                         for (@$dirs)
1724                         {
1725                                 print qq(<li>$AbsDir/<a href="$MySelf$RelDir/$_">$_</a></li>\n);
1726                         }
1727                         print "</ul>\n";
1728                 }
1729
1730                 for (sort (keys %$files))
1731                 {
1732                         my $type = $_;
1733
1734                         if (ref ($GraphMulti->{$type}) eq 'CODE')
1735                         {
1736                                 print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1737                                 qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1738                                 next;
1739                         }
1740
1741                         for (@{$files->{$type}})
1742                         {
1743                                 my $inst = "$_";
1744
1745                                 if (length ($inst))
1746                                 {
1747                                         print qq(\t\t<a href="$MySelf$RelDir/$type/$inst" />),
1748                                         qq(<img src="$MySelf$RelDir/$type/$inst/day" /></a>\n);
1749                                 }
1750                                 else
1751                                 {
1752                                         print qq(\t\t<a href="$MySelf$RelDir/$type" />),
1753                                         qq(<img src="$MySelf$RelDir/$type/day" /></a>\n);
1754                                 }
1755                         }
1756                 }
1757         }
1758
1759         print STDOUT <<FOOTER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1760         </body>
1761 </html>
1762 FOOTER
1763 }
1764
1765 sub output_xml
1766 {
1767         my $files = get_all_files ();
1768
1769         print STDOUT <<HEADER if (defined ($ENV{'GATEWAY_INTERFACE'}));
1770 Content-Type: text/xml
1771 Cache-Control: no-cache
1772
1773 HEADER
1774         print STDOUT pl2xml ($files);
1775 }
1776
1777 sub read_config
1778 {
1779         my $file = @_ ? shift : '/etc/collection.conf';
1780         my $conf;
1781         my $fh;
1782
1783 #       if (open ($fh, "< $file"))
1784 #       {
1785 #               my $xml;
1786 #               local $/ = undef;
1787 #               $xml = <$fh>;
1788 #
1789 #               eval
1790 #               {
1791 #                       $conf = xml2pl ($xml);
1792 #               };
1793 #               close ($fh);
1794 #       }
1795
1796         if (!$conf)
1797         {
1798                 return ({
1799                                 Colors =>
1800                                 {
1801                                         Back    => 'FFFFFF',
1802                                         ShadeA  => 'FFFFFF',
1803                                         ShadeB  => 'FFFFFF',
1804                                         Font    => '000000',
1805                                         Canvas  => 'F5F5F5',
1806                                         Grid    => 'D0D0D0',
1807                                         MGrid   => 'A0A0A0',
1808                                         Frame   => '646464',
1809                                         Arrow   => 'FF0000',
1810
1811                                         FullRed         => 'FF0000',
1812                                         FullBlue        => '0000FF',
1813                                         FullGreen       => '00E000',
1814                                         FullYellow      => 'F0A000',
1815                                         FullCyan        => '00A0FF',
1816                                         FullMagenta     => 'A000FF',
1817                                         Alpha           => 0.25,
1818                                         HalfRed         => 'F8B8B8',
1819                                         HalfBlue        => 'B8B8F8',
1820                                         HalfGreen       => 'B8F0B8',
1821                                         HalfYellow      => 'F4F4B8'
1822                                 },
1823                                 Directory => '/var/lib/collectd',
1824                                 HostName  => (defined ($ENV{'SERVER_NAME'}) ? $ENV{'SERVER_NAME'} : 'localhost')
1825                         });
1826         }
1827         else
1828         {
1829                 return ($conf);
1830         }
1831 }
1832
1833 sub parse_pathinfo
1834 {
1835         my @info = @_;
1836
1837         $AbsDir = $Config->{'Directory'};
1838         $RelDir = '';
1839
1840         while (@info and -d $AbsDir . '/' . $info[0])
1841         {
1842                 my $new = shift (@info);
1843                 next if ($new =~ m/^\./);
1844
1845                 $AbsDir .= '/' . $new;
1846                 $RelDir .= '/' . $new;
1847         }
1848
1849         $Type = '';
1850         $Inst = '';
1851         $TimeSpan = '';
1852
1853         confess ("parse_pathinfo: too many elements in pathinfo") if (scalar (@info) > 3);
1854         return unless (@info);
1855
1856         $Type = shift (@info);
1857         return unless (@info);
1858
1859         if ($info[-1] =~ m/^(hour|day|week|month|year)$/i)
1860         {
1861                 $TimeSpan = pop (@info);
1862         }
1863
1864         $Inst = shift (@info) if (@info);
1865
1866         confess ("unrecognized elements in pathinfo") if (@info);
1867 }
1868
1869 sub get_all_files
1870 {
1871         my $dir = @_ ? shift : $Config->{'Directory'};
1872         my $hash = {};
1873         my $dh;
1874
1875         if (opendir ($dh, $dir))
1876         {
1877                 while (my $thing = readdir ($dh))
1878                 {
1879                         next if ($thing =~ m/^\./);
1880
1881                         my $type;
1882                         my $inst;
1883
1884                         if ($thing =~ m/^(\w+)-([\w\-\.]+)\.rrd$/)
1885                         {
1886                                 $type = $1;
1887                                 $inst = $2;
1888                         }
1889                         elsif ($thing =~ m/^(\w+)\.rrd$/)
1890                         {
1891                                 $type = $1;
1892                                 $inst = '';
1893                         }
1894                         else
1895                         {
1896                                 next;
1897                         }
1898
1899                         # Only load RRD files we can actually display..
1900                         next unless (defined ($GraphDefs->{$type}));
1901
1902                         $hash->{$type} = [] unless (defined ($hash->{$type}));
1903                         push (@{$hash->{$type}}, $inst);
1904                 }
1905
1906                 closedir ($dh);
1907         }
1908
1909         return ($hash);
1910 }
1911
1912 sub get_all_dirs
1913 {
1914         my $dir = @_ ? shift : $Config->{'Directory'};
1915         my @ret = ();
1916         my $dh;
1917
1918         if (opendir ($dh, $dir))
1919         {
1920                 while (my $thing = readdir ($dh))
1921                 {
1922                         next if ($thing =~ m/^\./);
1923
1924                         next if (!-d "$dir/$thing");
1925
1926                         push (@ret, $thing);
1927                 }
1928
1929                 closedir ($dh);
1930         }
1931
1932         return (@ret) if (wantarray ());
1933         return (\@ret);
1934 }
1935
1936 sub color_hex2rgb
1937 {
1938         my $color = shift;
1939
1940         my ($red, $green, $blue) = map { ord (pack ("H2", $_)) } ($color =~ m/([A-Fa-f0-9]{2})/g);
1941         #print STDERR "$color -> rgb($red,$green,$blue)\n";
1942
1943         return ($red, $green, $blue);
1944 }
1945
1946 sub color_rgb2hex
1947 {
1948         croak unless (scalar (@_) == 3);
1949         
1950         my ($red, $green, $blue) = @_;
1951
1952         my $ret = sprintf ("%02X%02X%02X", $red, $green, $blue);
1953         #print STDERR "rgb($red,$green,$blue) -> $ret\n";
1954
1955         return ($ret);
1956 }
1957
1958 sub color_calculate_transparent
1959 {
1960         my $alpha = shift;
1961         my $canvas = [color_hex2rgb (shift)];
1962         my @colors = map { [color_hex2rgb ($_)] } (@_);
1963
1964         if (($alpha < 0.0) or ($alpha > 1.0))
1965         {
1966                 $alpha = 1.0;
1967         }
1968
1969         if ($alpha == 0.0)
1970         {
1971                 return (color_rgb2hex (@$canvas));
1972         }
1973         if ($alpha == 1.0)
1974         {
1975                 return (color_rgb2hex (@{$colors[-1]}));
1976         }
1977
1978         my $ret = _color_calculate_transparent ($alpha, $canvas, @colors);
1979
1980         return (color_rgb2hex (@$ret));
1981 }
1982
1983 sub _color_calculate_transparent
1984 {
1985         my $alpha = shift;
1986         my $canvas = shift;
1987         my $color = shift;
1988         my @colors = @_ ? shift : ();
1989         my $ret = [0, 0, 0];
1990
1991         for (my $i = 0; $i < 3; $i++)
1992         {
1993                 $ret->[$i] = ($alpha * $color->[$i]) + ((1 - $alpha) * $canvas->[$i]);
1994         }
1995
1996         return (_color_calculate_transparent ($alpha, $ret, @colors)) if (@colors);
1997         return ($ret);
1998 }
1999
2000 sub get_n_colors
2001 {
2002         my $num = shift;
2003         my @ret = ();
2004
2005         for (my $i = 0; $i < $num; $i++)
2006         {
2007                 my $pos = 6 * $i / $num;
2008                 my $n = int ($pos);
2009                 my $p = $pos - $n;
2010                 my $q = 1 - $p;
2011
2012                 my $red   = 0;
2013                 my $green = 0;
2014                 my $blue  = 0;
2015
2016                 if ($n == 0)
2017                 {
2018                         $red  = 255;
2019                         $blue = 255 * $p;
2020                 }
2021                 elsif ($n == 1)
2022                 {
2023                         $red  = 255 * $q;
2024                         $blue = 255;
2025                 }
2026                 elsif ($n == 2)
2027                 {
2028                         $green = 255 * $p;
2029                         $blue  = 255;
2030                 }
2031                 elsif ($n == 3)
2032                 {
2033                         $green = 255;
2034                         $blue  = 255 * $q;
2035                 }
2036                 elsif ($n == 4)
2037                 {
2038                         $red   = 255 * $p;
2039                         $green = 255;
2040                 }
2041                 elsif ($n == 5)
2042                 {
2043                         $red   = 255;
2044                         $green = 255 * $q;
2045                 }
2046                 else { die; }
2047
2048                 push (@ret, sprintf ("%02x%02x%02x", $red, $green, $blue));
2049         }
2050
2051         return (@ret);
2052 }