Code

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