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