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