java plugin: Add support for `notification' callbacks.
[collectd.git] / contrib / collection.cgi
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Carp (qw(cluck confess));
7 use CGI (':cgi');
8 use CGI::Carp ('fatalsToBrowser');
9 use HTML::Entities ('encode_entities');
10 use URI::Escape ('uri_escape');
11 use RRDs ();
12 use Data::Dumper ();
13
14 our $Config = "/etc/collection.conf";
15 our @DataDirs = ();
16 our $LibDir;
17
18 our $ValidTimespan =
19 {
20   hour => 3600,
21   day => 86400,
22   week => 7 * 86400,
23   month => 31 * 86400,
24   year => 366 * 86400
25 };
26
27 our @RRDDefaultArgs = ('-w', '400');
28
29 our $Args = {};
30
31 our $GraphDefs;
32 our $MetaGraphDefs = {};
33 load_graph_definitions ();
34
35 for (qw(action host plugin plugin_instance type type_instance timespan))
36 {
37         $Args->{$_} = param ($_);
38 }
39
40 exit (main ());
41
42 sub read_config
43 {
44         my $fh;
45         open ($fh, "< $Config") or confess ("open ($Config): $!");
46         while (my $line = <$fh>)
47         {
48                 chomp ($line);
49                 next if (!$line);
50                 next if ($line =~ m/^\s*#/);
51                 next if ($line =~ m/^\s*$/);
52
53                 my $key;
54                 my $value;
55
56                 if ($line =~ m/^([A-Za-z]+):\s*"((?:[^"\\]+|\\.)*)"$/)
57                 {
58                         $key = lc ($1); $value = $2;
59                         $value =~ s/\\(.)/$1/g;
60                 }
61                 elsif ($line =~ m/([A-Za-z]+):\s*([0-9]+)$/)
62                 {
63                         $key = lc ($1); $value = 0 + $2;
64                 }
65                 else
66                 {
67                         print STDERR "Cannot parse line: $line\n";
68                         next;
69                 }
70
71                 if ($key eq 'datadir')
72                 {
73                         $value =~ s#/*$##;
74                         push (@DataDirs, $value);
75                 }
76                 elsif ($key eq 'libdir')
77                 {
78                         $value =~ s#/*$##;
79                         $LibDir = $value;
80                 }
81                 else
82                 {
83                         print STDERR "Unknown key: $key\n";
84                 }
85         }
86         close ($fh);
87 } # read_config
88
89 sub validate_args
90 {
91         if ($Args->{'action'} && ($Args->{'action'} =~ m/^(overview|show_host|show_plugin|show_type|show_graph)$/))
92         {
93                 $Args->{'action'} = $1;
94         }
95         else
96         {
97                 $Args->{'action'} = 'overview';
98         }
99
100         if ($Args->{'host'} && ($Args->{'host'} =~ m#/#))
101         {
102                 delete ($Args->{'host'});
103         }
104
105         if ($Args->{'plugin'} && ($Args->{'plugin'} =~ m#/#))
106         {
107                 delete ($Args->{'plugin'});
108         }
109
110         if ($Args->{'type'} && ($Args->{'type'} =~ m#/#))
111         {
112                 delete ($Args->{'type'});
113         }
114
115         if (!$Args->{'plugin'} || ($Args->{'plugin_instance'}
116                 && ($Args->{'plugin_instance'} =~ m#/#)))
117         {
118                 delete ($Args->{'plugin_instance'});
119         }
120
121         if (!$Args->{'type'} || ($Args->{'type_instance'}
122                 && ($Args->{'type_instance'} =~ m#/#)))
123         {
124                 delete ($Args->{'type_instance'});
125         }
126
127         if (defined ($Args->{'timespan'})
128           && ($Args->{'timespan'} =~ m/^(hour|day|week|month|year)$/))
129         {
130           $Args->{'timespan'} = $1;
131         }
132         else
133         {
134           $Args->{'timespan'} = 'day';
135         }
136 } # validate_args
137
138 {
139   my $hosts;
140   sub _find_hosts
141   {
142     if (defined ($hosts))
143     {
144       return (keys %$hosts);
145     }
146
147     $hosts = {};
148
149     for (my $i = 0; $i < @DataDirs; $i++)
150     {
151       my @tmp;
152       my $dh;
153
154       opendir ($dh, $DataDirs[$i]) or next;
155       @tmp = grep { ($_ !~ m/^\./) && (-d $DataDirs[$i] . '/' . $_) } (readdir ($dh));
156       closedir ($dh);
157
158       $hosts->{$_} = 1 for (@tmp);
159     } # for (@DataDirs)
160
161     return (keys %$hosts);
162   } # _find_hosts
163 }
164
165 sub _get_param_host
166 {
167   my %all_hosts = map { $_ => 1 } (_find_hosts ());
168   my @selected_hosts = ();
169   for (param ('host'))
170   {
171     if (defined ($all_hosts{$_}))
172     {
173       push (@selected_hosts, "$_");
174     }
175   }
176   return (@selected_hosts);
177 } # _get_param_host
178
179 sub _get_param_timespan
180 {
181   my $timespan = param ('timespan');
182
183   $timespan ||= 'day';
184   $timespan = lc ($timespan);
185
186   if (!defined ($ValidTimespan->{$timespan}))
187   {
188     $timespan = 'day';
189   }
190
191   return ($timespan);
192 } # _get_param_timespan
193
194 sub _find_plugins
195 {
196   my $host = shift;
197   my %plugins = ();
198
199   for (my $i = 0; $i < @DataDirs; $i++)
200   {
201     my $dir = $DataDirs[$i] . "/$host";
202     my @tmp;
203     my $dh;
204
205     opendir ($dh, $dir) or next;
206     @tmp = grep { ($_ !~ m/^\./) && (-d "$dir/$_") } (readdir ($dh));
207     closedir ($dh);
208
209     for (@tmp)
210     {
211       my ($plugin, $instance) = split (m/-/, $_, 2);
212       $plugins{$plugin} = [] if (!exists $plugins{$plugin});
213       push (@{$plugins{$plugin}}, $instance);
214     }
215   } # for (@DataDirs)
216
217   return (%plugins);
218 } # _find_plugins
219
220 sub _find_types
221 {
222   my $host = shift;
223   my $plugin = shift;
224   my $plugin_instance = shift;
225   my %types = ();
226
227   for (my $i = 0; $i < @DataDirs; $i++)
228   {
229     my $dir = $DataDirs[$i] . "/$host/$plugin" . (defined ($plugin_instance) ? "-$plugin_instance" : '');
230     my @tmp;
231     my $dh;
232
233     opendir ($dh, $dir) or next;
234     @tmp = grep { ($_ !~ m/^\./) && ($_ =~ m/\.rrd$/i) && (-f "$dir/$_") } (readdir ($dh));
235     closedir ($dh);
236
237     for (@tmp)
238     {
239       my $name = "$_";
240       $name =~ s/\.rrd$//i;
241       my ($type, $instance) = split (m/-/, $name, 2);
242       $types{$type} = [] if (!$types{$type});
243       push (@{$types{$type}}, $instance) if (defined ($instance));
244     }
245   } # for (@DataDirs)
246
247   return (%types);
248 } # _find_types
249
250 sub _find_files_for_host
251 {
252   my $host = shift;
253   my $ret = {};
254
255   my %plugins = _find_plugins ($host);
256   for (keys %plugins)
257   {
258     my $plugin = $_;
259     my $plugin_instances = $plugins{$plugin};
260
261     if (!$plugin_instances || !@$plugin_instances)
262     {
263       $plugin_instances = ['-'];
264     }
265
266     $ret->{$plugin} = {};
267
268     for (@$plugin_instances)
269     {
270       my $plugin_instance = defined ($_) ? $_ : '-';
271       my %types = _find_types ($host, $plugin,
272         ($plugin_instance ne '-')
273         ? $plugin_instance
274         : undef);
275
276       $ret->{$plugin}{$plugin_instance} = {};
277
278       for (keys %types)
279       {
280         my $type = $_;
281         my $type_instances = $types{$type};
282
283         $ret->{$plugin}{$plugin_instance}{$type} = {};
284
285         for (@$type_instances)
286         {
287           $ret->{$plugin}{$plugin_instance}{$type}{$_} = 1;
288         }
289
290         if (!@$type_instances)
291         {
292           $ret->{$plugin}{$plugin_instance}{$type}{'-'} = 1;
293         }
294       } # for (keys %types)
295     } # for (@$plugin_instances)
296   } # for (keys %plugins)
297
298   return ($ret);
299 } # _find_files_for_host
300
301 sub _find_files_for_hosts
302 {
303   my @hosts = @_;
304   my $all_plugins = {};
305
306   for (my $i = 0; $i < @hosts; $i++)
307   {
308     my $tmp = _find_files_for_host ($hosts[$i]);
309     _files_union ($all_plugins, $tmp);
310   }
311
312   return ($all_plugins);
313 } # _find_files_for_hosts
314
315 sub _files_union
316 {
317   my $dest = shift;
318   my $src = shift;
319
320   for (keys %$src)
321   {
322     my $plugin = $_;
323     $dest->{$plugin} ||= {};
324
325     for (keys %{$src->{$plugin}})
326     {
327       my $pinst = $_;
328       $dest->{$plugin}{$pinst} ||= {};
329
330       for (keys %{$src->{$plugin}{$pinst}})
331       {
332         my $type = $_;
333         $dest->{$plugin}{$pinst}{$type} ||= {};
334
335         for (keys %{$src->{$plugin}{$pinst}{$type}})
336         {
337           my $tinst = $_;
338           $dest->{$plugin}{$pinst}{$type}{$tinst} = 1;
339         }
340       }
341     }
342   }
343 } # _files_union
344
345 sub _files_plugin_inst_count
346 {
347   my $src = shift;
348   my $i = 0;
349
350   for (keys %$src)
351   {
352     if (exists ($MetaGraphDefs->{$_}))
353     {
354       $i++;
355     }
356     else
357     {
358       $i = $i + keys %{$src->{$_}};
359     }
360   }
361   return ($i);
362 } # _files_plugin_count
363
364 sub list_hosts
365 {
366   my @hosts = _find_hosts ();
367   @hosts = sort (@hosts);
368
369   print "<ul>\n";
370   for (my $i = 0; $i < @hosts; $i++)
371   {
372     my $host_html = encode_entities ($hosts[$i]);
373     my $host_url = uri_escape ($hosts[$i]);
374
375     print qq(  <li><a href="${\script_name ()}?action=show_host;host=$host_url">$host_html</a></li>\n);
376   }
377   print "</ul>\n";
378 } # list_hosts
379
380 sub _string_to_color
381 {
382   my $color = shift;
383   if ($color =~ m/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/)
384   {
385     return ([hex ($1) / 255.0, hex ($2) / 255.0, hex ($3) / 255.0]);
386   }
387   return;
388 } # _string_to_color
389
390 sub _color_to_string
391 {
392   confess ("Wrong number of arguments") if (@_ != 1);
393   return (sprintf ('%02hx%02hx%02hx', map { int (255.0 * $_) } @{$_[0]}));
394 } # _color_to_string
395
396 sub _get_random_color
397 {
398   my ($r, $g, $b) = (rand (), rand ());
399   my $min = 0.0;
400   my $max = 1.0;
401
402   if (($r + $g) < 1.0)
403   {
404     $min = 1.0 - ($r + $g);
405   }
406   else
407   {
408     $max = 2.0 - ($r + $g);
409   }
410
411   $b = $min + (rand () * ($max - $min));
412
413   return ([$r, $g, $b]);
414 } # _get_random_color
415
416 sub _get_n_colors
417 {
418         my $instances = shift;
419         my $num = scalar @$instances;
420         my $ret = {};
421
422         for (my $i = 0; $i < $num; $i++)
423         {
424                 my $pos = 6 * $i / $num;
425                 my $n = int ($pos);
426                 my $p = $pos - $n;
427                 my $q = 1 - $p;
428
429                 my $red   = 0;
430                 my $green = 0;
431                 my $blue  = 0;
432
433                 my $color;
434
435                 if ($n == 0)
436                 {
437                         $red  = 255;
438                         $blue = 255 * $p;
439                 }
440                 elsif ($n == 1)
441                 {
442                         $red  = 255 * $q;
443                         $blue = 255;
444                 }
445                 elsif ($n == 2)
446                 {
447                         $green = 255 * $p;
448                         $blue  = 255;
449                 }
450                 elsif ($n == 3)
451                 {
452                         $green = 255;
453                         $blue  = 255 * $q;
454                 }
455                 elsif ($n == 4)
456                 {
457                         $red   = 255 * $p;
458                         $green = 255;
459                 }
460                 elsif ($n == 5)
461                 {
462                         $red   = 255;
463                         $green = 255 * $q;
464                 }
465                 else { die; }
466
467                 $color = sprintf ("%02x%02x%02x", $red, $green, $blue);
468                 $ret->{$instances->[$i]} = $color;
469         }
470
471         return ($ret);
472 } # _get_n_colors
473
474 sub _get_faded_color
475 {
476   my $fg = shift;
477   my $bg;
478   my %opts = @_;
479   my $ret = [undef, undef, undef];
480
481   $opts{'background'} ||= [1.0, 1.0, 1.0];
482   $opts{'alpha'} ||= 0.25;
483
484   if (!ref ($opts{'background'}))
485   {
486     $opts{'background'} = _string_to_color ($opts{'background'})
487       or confess ("Cannot parse background color " . $opts{'background'});
488   }
489   $bg = $opts{'background'};
490
491   for (my $i = 0; $i < 3; $i++)
492   {
493     $ret->[$i] = ($opts{'alpha'} * $fg->[$i])
494        + ((1.0 - $opts{'alpha'}) * $bg->[$i]);
495   }
496
497   return ($ret);
498 } # _get_faded_color
499
500 sub _custom_sort_arrayref
501 {
502   my $array_ref = shift;
503   my $array_sort = shift;
504
505   my %elements = map { $_ => 1 } (@$array_ref);
506   splice (@$array_ref, 0);
507
508   for (@$array_sort)
509   {
510     next if (!exists ($elements{$_}));
511     push (@$array_ref, $_);
512     delete ($elements{$_});
513   }
514   push (@$array_ref, sort (keys %elements));
515 } # _custom_sort_arrayref
516
517 sub action_show_host
518 {
519   my @hosts = _get_param_host ();
520   @hosts = sort (@hosts);
521
522   my $timespan = _get_param_timespan ();
523   my $all_plugins = _find_files_for_hosts (@hosts);
524
525   my $url_prefix = script_name () . '?action=show_plugin'
526   . join ('', map { ';host=' . uri_escape ($_) } (@hosts))
527   . ';timespan=' . uri_escape ($timespan);
528
529   print qq(    <div><a href="${\script_name ()}?action=overview">Back to list of hosts</a></div>\n);
530
531   print "    <p>Available plugins:</p>\n"
532   . "    <ul>\n";
533   for (sort (keys %$all_plugins))
534   {
535     my $plugin = $_;
536     my $plugin_html = encode_entities ($plugin);
537     my $url_plugin = $url_prefix . ';plugin=' . uri_escape ($plugin);
538     print qq(      <li><a href="$url_plugin">$plugin_html</a></li>\n);
539   }
540   print "   </ul>\n";
541 } # action_show_host
542
543 sub action_show_plugin
544 {
545   my @hosts = _get_param_host ();
546   my $plugin = shift;
547   my $plugin_instance = shift;
548   my $timespan = _get_param_timespan ();
549
550   my $hosts_url = join (';', map { 'host=' . uri_escape ($_) } (@hosts));
551   my $url_prefix = script_name () . "?$hosts_url";
552
553   my $all_plugins = {};
554   my $plugins_per_host = {};
555   my $selected_plugins = {};
556
557   for (my $i = 0; $i < @hosts; $i++)
558   {
559     $plugins_per_host->{$hosts[$i]} = _find_files_for_host ($hosts[$i]);
560     _files_union ($all_plugins, $plugins_per_host->{$hosts[$i]});
561   }
562
563   for (param ('plugin'))
564   {
565     if (defined ($all_plugins->{$_}))
566     {
567       $selected_plugins->{$_} = 1;
568     }
569   }
570
571   print qq(    <div><a href="${\script_name ()}?action=show_host;$hosts_url">Back to list of plugins</a></div>\n);
572
573   # Print table header
574   print <<HTML;
575     <table class="graphs">
576       <tr>
577         <th>Plugins</th>
578 HTML
579   for (@hosts)
580   {
581     print "\t<th>", encode_entities ($_), "</th>\n";
582   }
583   print "      </tr>\n";
584
585   for (sort (keys %$selected_plugins))
586   {
587     my $plugin = $_;
588     my $plugin_html = encode_entities ($plugin);
589     my $plugin_url = "$url_prefix;plugin=" . uri_escape ($plugin);
590     my $all_pinst = $all_plugins->{$plugin};
591
592     for (sort (keys %$all_pinst))
593     {
594       my $pinst = $_;
595       my $pinst_html = '';
596       my $pinst_url = $plugin_url;
597
598       if ($pinst ne '-')
599       {
600         $pinst_html = encode_entities ($pinst);
601         $pinst_url .= ';plugin_instance=' . uri_escape ($pinst);
602       }
603
604       my $files_printed = 0;
605       my $files_num = _files_plugin_inst_count ($all_pinst->{$pinst});
606       if ($files_num < 1)
607       {
608         next;
609       }
610       my $rowspan = ($files_num == 1) ? '' : qq( rowspan="$files_num");
611
612       for (sort (keys %{$all_plugins->{$plugin}{$pinst}}))
613       {
614         my $type = $_;
615         my $type_html = encode_entities ($type);
616         my $type_url = "$pinst_url;type=" . uri_escape ($type);
617
618         if ($files_printed == 0)
619         {
620           my $title = $plugin_html;
621           if ($pinst ne '-')
622           {
623             $title .= " ($pinst_html)";
624           }
625           print "      <tr>\n";
626           print "\t<td$rowspan>$title</td>\n";
627         }
628
629         if (exists ($MetaGraphDefs->{$type}))
630         {
631           my $graph_url = script_name () . '?action=show_graph'
632           . ';plugin=' . uri_escape ($plugin)
633           . ';type=' . uri_escape ($type)
634           . ';timespan=' . uri_escape ($timespan);
635           if ($pinst ne '-')
636           {
637             $graph_url .= ';plugin_instance=' . uri_escape ($pinst);
638           }
639
640           if ($files_printed != 0)
641           {
642             print "      <tr>\n";
643           }
644
645           for (@hosts)
646           {
647             my $host = $_;
648             my $host_graph_url = $graph_url . ';host=' . uri_escape ($host);
649
650             print "\t<td>";
651             if (exists $plugins_per_host->{$host}{$plugin}{$pinst}{$type})
652             {
653               print qq(<img src="$host_graph_url" />);
654               #print encode_entities (qq(<img src="${\script_name ()}?action=show_graph;host=$host_esc;$param_plugin;$param_type;timespan=$timespan" />));
655             }
656             print "</td>\n";
657           } # for (my $k = 0; $k < @hosts; $k++)
658
659           print "      </tr>\n";
660
661           $files_printed++;
662           next; # pinst
663         } # if (exists ($MetaGraphDefs->{$type}))
664
665         for (sort (keys %{$all_plugins->{$plugin}{$pinst}{$type}}))
666         {
667           my $tinst = $_;
668           my $tinst_esc = encode_entities ($tinst);
669           my $graph_url = script_name () . '?action=show_graph'
670           . ';plugin=' . uri_escape ($plugin)
671           . ';type=' . uri_escape ($type)
672           . ';timespan=' . uri_escape ($timespan);
673           if ($pinst ne '-')
674           {
675             $graph_url .= ';plugin_instance=' . uri_escape ($pinst);
676           }
677           if ($tinst ne '-')
678           {
679             $graph_url .= ';type_instance=' . uri_escape ($tinst);
680           }
681
682           if ($files_printed != 0)
683           {
684             print "      <tr>\n";
685           }
686
687           for (my $k = 0; $k < @hosts; $k++)
688           {
689             my $host = $hosts[$k];
690             my $host_graph_url = $graph_url . ';host=' . uri_escape ($host);
691
692             print "\t<td>";
693             if ($plugins_per_host->{$host}{$plugin}{$pinst}{$type}{$tinst})
694             {
695               print qq(<img src="$host_graph_url" />);
696               #print encode_entities (qq(<img src="${\script_name ()}?action=show_graph;host=$host_esc;$param_plugin;$param_type;timespan=$timespan" />));
697             }
698             print "</td>\n";
699           } # for (my $k = 0; $k < @hosts; $k++)
700
701           print "      </tr>\n";
702
703           $files_printed++;
704         } # for ($tinst)
705       } # for ($type)
706     } # for ($pinst)
707   } # for ($plugin)
708   print "   </table>\n";
709 } # action_show_plugin
710
711 sub action_show_type
712 {
713   my $host = shift;
714   my $plugin = shift;
715   my $plugin_instance = shift;
716   my $type = shift;
717   my $type_instance = shift;
718
719   my $host_url = uri_escape ($host);
720   my $plugin_url = uri_escape ($plugin);
721   my $plugin_html = encode_entities ($plugin);
722   my $plugin_instance_url = defined ($plugin_instance) ? uri_escape ($plugin_instance) : undef;
723   my $type_url = uri_escape ($type);
724   my $type_instance_url = defined ($type_instance) ? uri_escape ($type_instance) : undef;
725
726   my $url_prefix = script_name () . "?action=show_plugin;host=$host_url;plugin=$plugin_url";
727   $url_prefix .= ";plugin_instance=$plugin_instance_url" if (defined ($plugin_instance));
728
729   print qq(    <div><a href="$url_prefix">Back to plugin &quot;$plugin_html&quot;</a></div>\n);
730
731   $url_prefix = script_name () . "?action=show_graph;host=$host_url;plugin=$plugin_url";
732   $url_prefix .= ";plugin_instance=$plugin_instance_url" if (defined ($plugin_instance));
733   $url_prefix .= ";type=$type_url";
734   $url_prefix .= ";type_instance=$type_instance_url" if (defined ($type_instance));
735
736   for (qw(hour day week month year))
737   {
738     my $timespan = $_;
739
740     print qq#  <div><img src="$url_prefix;timespan=$timespan" /></div>\n#;
741   }
742 } # action_show_type
743
744 sub action_show_graph
745 {
746   my $host = shift;
747   my $plugin = shift;
748   my $plugin_instance = shift;
749   my $type = shift;
750   my $type_instance = shift;
751   my @rrd_args;
752   my $title;
753   
754   my %times = (hour => -3600, day => -86400, week => 7 * -86400, month => 31 * -86400, year => 366 * -86400);
755   my $start_time = $times{$Args->{'timespan'}} || -86400;
756
757   #print STDERR Data::Dumper->Dump ([$Args], ['Args']);
758
759   # FIXME
760   if (exists ($MetaGraphDefs->{$type}))
761   {
762     my %types = _find_types ($host, $plugin, $plugin_instance);
763     return $MetaGraphDefs->{$type}->($host, $plugin, $plugin_instance, $type, $types{$type});
764   }
765
766   return if (!defined ($GraphDefs->{$type}));
767   @rrd_args = @{$GraphDefs->{$type}};
768
769   $title = "$host/$plugin" . (defined ($plugin_instance) ? "-$plugin_instance" : '')
770   . "/$type" . (defined ($type_instance) ? "-$type_instance" : '');
771
772   for (my $i = 0; $i < @DataDirs; $i++)
773   {
774     my $file = $DataDirs[$i] . "/$title.rrd";
775     next if (!-f $file);
776
777     $file =~ s/:/\\:/g;
778     s/{file}/$file/ for (@rrd_args);
779
780     RRDs::graph ('-', '-a', 'PNG', '-s', $start_time, '-t', $title, @RRDDefaultArgs, @rrd_args);
781     if (my $err = RRDs::error ())
782     {
783       die ("RRDs::graph: $err");
784     }
785   }
786 } # action_show_graph
787
788 sub print_selector
789 {
790   my @hosts = _find_hosts ();
791   @hosts = sort (@hosts);
792
793   my %selected_hosts = map { $_ => 1 } (_get_param_host ());
794   my $timespan_selected = _get_param_timespan ();
795
796   print <<HTML;
797     <form action="${\script_name ()}" method="get">
798       <fieldset>
799         <legend>Selector</legend>
800         <select name="host" multiple="multiple" size="10">
801 HTML
802   for (my $i = 0; $i < @hosts; $i++)
803   {
804     my $host = encode_entities ($hosts[$i]);
805     my $selected = defined ($selected_hosts{$hosts[$i]}) ? ' selected="selected"' : '';
806     print qq(\t  <option value="$host"$selected>$host</option>\n);
807   }
808   print "\t</select>\n";
809
810   if (keys %selected_hosts)
811   {
812     my $all_plugins = _find_files_for_hosts (keys %selected_hosts);
813     my %selected_plugins = map { $_ => 1 } (param ('plugin'));
814
815     print qq(\t<select name="plugin" multiple="multiple" size="10">\n);
816     for (sort (keys %$all_plugins))
817     {
818       my $plugin = $_;
819       my $plugin_html = encode_entities ($plugin);
820       my $selected = (defined ($selected_plugins{$plugin})
821         ? ' selected="selected"' : '');
822       print qq(\t  <option value="$plugin_html"$selected>$plugin</option>\n);
823     }
824     print "</select>\n";
825   } # if (keys %selected_hosts)
826
827   print qq(\t<select name="timespan">\n);
828   for (qw(Hour Day Week Month Year))
829   {
830     my $timespan_uc = $_;
831     my $timespan_lc = lc ($_);
832     my $selected = ($timespan_selected eq $timespan_lc)
833       ? ' selected="selected"' : '';
834     print qq(\t  <option value="$timespan_lc"$selected>$timespan_uc</option>\n);
835   }
836   print <<HTML;
837         </select>
838         <input type="submit" name="button" value="Ok" />
839       </fieldset>
840     </form>
841 HTML
842 }
843
844 sub print_header
845 {
846   print <<HEAD;
847 Content-Type: application/xhtml+xml; charset=utf-8
848 Cache-Control: no-cache
849
850 <?xml version="1.0" encoding="utf-8"?>
851 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
852   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
853
854 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
855   <head>
856     <title>collection.cgi, Version 2</title>
857     <style type="text/css">
858       img
859       {
860         border: none;
861       }
862       table.graphs
863       {
864         border-collapse: collapse;
865       }
866       table.graphs td,
867       table.graphs th
868       {
869         border: 1px solid black;
870         empty-cells: hide;
871       }
872     </style>
873   </head>
874
875   <body>
876 HEAD
877   print_selector ();
878 } # print_header
879
880 sub print_footer
881 {
882   print <<FOOT;
883   </body>
884 </html>
885 FOOT
886 } # print_footer
887
888 sub main
889 {
890         read_config ();
891         validate_args ();
892
893         if (defined ($Args->{'host'})
894           && defined ($Args->{'plugin'})
895           && defined ($Args->{'type'})
896           && ($Args->{'action'} eq 'show_graph'))
897         {
898           $| = 1;
899           print STDOUT header (-Content_Type => 'image/png');
900           action_show_graph ($Args->{'host'},
901             $Args->{'plugin'}, $Args->{'plugin_instance'},
902             $Args->{'type'}, $Args->{'type_instance'});
903           return (0);
904         }
905
906         print_header ();
907
908         if (!$Args->{'host'})
909         {
910           list_hosts ();
911         }
912         elsif (!$Args->{'plugin'})
913         {
914           action_show_host ($Args->{'host'});
915         }
916         elsif (!$Args->{'type'})
917         {
918           action_show_plugin ($Args->{'plugin'}, $Args->{'plugin_instance'});
919         }
920         else
921         {
922           action_show_type ($Args->{'host'},
923             $Args->{'plugin'}, $Args->{'plugin_instance'},
924             $Args->{'type'}, $Args->{'type_instance'});
925         }
926
927         print_footer ();
928
929         return (0);
930 }
931
932 sub load_graph_definitions
933 {
934   my $Canvas = 'FFFFFF';
935
936   my $FullRed    = 'FF0000';
937   my $FullGreen  = '00E000';
938   my $FullBlue   = '0000FF';
939   my $FullYellow = 'F0A000';
940   my $FullCyan   = '00A0FF';
941   my $FullMagenta= 'A000FF';
942
943   my $HalfRed    = 'F7B7B7';
944   my $HalfGreen  = 'B7EFB7';
945   my $HalfBlue   = 'B7B7F7';
946   my $HalfYellow = 'F3DFB7';
947   my $HalfCyan   = 'B7DFF7';
948   my $HalfMagenta= 'DFB7F7';
949
950   my $HalfBlueGreen = '89B3C9';
951
952   $GraphDefs =
953   {
954     apache_bytes => ['DEF:min_raw={file}:count:MIN',
955     'DEF:avg_raw={file}:count:AVERAGE',
956     'DEF:max_raw={file}:count:MAX',
957     'CDEF:min=min_raw,8,*',
958     'CDEF:avg=avg_raw,8,*',
959     'CDEF:max=max_raw,8,*',
960     'CDEF:mytime=avg_raw,TIME,TIME,IF',
961     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
962     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
963     'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
964     'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
965     "AREA:avg#$HalfBlue",
966     "LINE1:avg#$FullBlue:Bit/s",
967     'GPRINT:min:MIN:%5.1lf%s Min,',
968     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
969     'GPRINT:max:MAX:%5.1lf%s Max,',
970     'GPRINT:avg:LAST:%5.1lf%s Last',
971     'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
972     ],
973     apache_requests => ['DEF:min={file}:count:MIN',
974     'DEF:avg={file}:count:AVERAGE',
975     'DEF:max={file}:count:MAX',
976     "AREA:max#$HalfBlue",
977     "AREA:min#$Canvas",
978     "LINE1:avg#$FullBlue:Requests/s",
979     'GPRINT:min:MIN:%6.2lf Min,',
980     'GPRINT:avg:AVERAGE:%6.2lf Avg,',
981     'GPRINT:max:MAX:%6.2lf Max,',
982     'GPRINT:avg:LAST:%6.2lf Last'
983     ],
984     apache_scoreboard => ['DEF:min={file}:count:MIN',
985     'DEF:avg={file}:count:AVERAGE',
986     'DEF:max={file}:count:MAX',
987     "AREA:max#$HalfBlue",
988     "AREA:min#$Canvas",
989     "LINE1:avg#$FullBlue:Processes",
990     'GPRINT:min:MIN:%6.2lf Min,',
991     'GPRINT:avg:AVERAGE:%6.2lf Avg,',
992     'GPRINT:max:MAX:%6.2lf Max,',
993     'GPRINT:avg:LAST:%6.2lf Last'
994     ],
995     bitrate => ['-v', 'Bits/s',
996     'DEF:avg={file}:value:AVERAGE',
997     'DEF:min={file}:value:MIN',
998     'DEF:max={file}:value:MAX',
999     "AREA:max#$HalfBlue",
1000     "AREA:min#$Canvas",
1001     "LINE1:avg#$FullBlue:Bits/s",
1002     'GPRINT:min:MIN:%5.1lf%s Min,',
1003     'GPRINT:avg:AVERAGE:%5.1lf%s Average,',
1004     'GPRINT:max:MAX:%5.1lf%s Max,',
1005     'GPRINT:avg:LAST:%5.1lf%s Last\l'
1006     ],
1007     charge => ['-v', 'Ah',
1008     'DEF:avg={file}:value:AVERAGE',
1009     'DEF:min={file}:value:MIN',
1010     'DEF:max={file}:value:MAX',
1011     "AREA:max#$HalfBlue",
1012     "AREA:min#$Canvas",
1013     "LINE1:avg#$FullBlue:Charge",
1014     'GPRINT:min:MIN:%5.1lf%sAh Min,',
1015     'GPRINT:avg:AVERAGE:%5.1lf%sAh Avg,',
1016     'GPRINT:max:MAX:%5.1lf%sAh Max,',
1017     'GPRINT:avg:LAST:%5.1lf%sAh Last\l'
1018     ],
1019     connections => ['-v', 'Connections',
1020     'DEF:avg={file}:value:AVERAGE',
1021     'DEF:min={file}:value:MIN',
1022     'DEF:max={file}:value:MAX',
1023     "AREA:max#$HalfBlue",
1024     "AREA:min#$Canvas",
1025     "LINE1:avg#$FullBlue:Connections",
1026     'GPRINT:min:MIN:%4.1lf Min,',
1027     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1028     'GPRINT:max:MAX:%4.1lf Max,',
1029     'GPRINT:avg:LAST:%4.1lf Last\l'
1030     ],
1031     cpu => ['-v', 'CPU load',
1032     'DEF:avg={file}:value:AVERAGE',
1033     'DEF:min={file}:value:MIN',
1034     'DEF:max={file}:value:MAX',
1035     "AREA:max#$HalfBlue",
1036     "AREA:min#$Canvas",
1037     "LINE1:avg#$FullBlue:Percent",
1038     'GPRINT:min:MIN:%6.2lf%% Min,',
1039     'GPRINT:avg:AVERAGE:%6.2lf%% Avg,',
1040     'GPRINT:max:MAX:%6.2lf%% Max,',
1041     'GPRINT:avg:LAST:%6.2lf%% Last\l'
1042     ],
1043     current => ['-v', 'Ampere',
1044     'DEF:avg={file}:value:AVERAGE',
1045     'DEF:min={file}:value:MIN',
1046     'DEF:max={file}:value:MAX',
1047     "AREA:max#$HalfBlue",
1048     "AREA:min#$Canvas",
1049     "LINE1:avg#$FullBlue:Current",
1050     'GPRINT:min:MIN:%5.1lf%sA Min,',
1051     'GPRINT:avg:AVERAGE:%5.1lf%sA Avg,',
1052     'GPRINT:max:MAX:%5.1lf%sA Max,',
1053     'GPRINT:avg:LAST:%5.1lf%sA Last\l'
1054     ],
1055     df => ['-v', 'Percent', '-l', '0',
1056     'DEF:free_avg={file}:free:AVERAGE',
1057     'DEF:free_min={file}:free:MIN',
1058     'DEF:free_max={file}:free:MAX',
1059     'DEF:used_avg={file}:used:AVERAGE',
1060     'DEF:used_min={file}:used:MIN',
1061     'DEF:used_max={file}:used:MAX',
1062     'CDEF:total=free_avg,used_avg,+',
1063     'CDEF:free_pct=100,free_avg,*,total,/',
1064     'CDEF:used_pct=100,used_avg,*,total,/',
1065     'CDEF:free_acc=free_pct,used_pct,+',
1066     'CDEF:used_acc=used_pct',
1067     "AREA:free_acc#$HalfGreen",
1068     "AREA:used_acc#$HalfRed",
1069     "LINE1:free_acc#$FullGreen:Free",
1070     'GPRINT:free_min:MIN:%5.1lf%sB Min,',
1071     'GPRINT:free_avg:AVERAGE:%5.1lf%sB Avg,',
1072     'GPRINT:free_max:MAX:%5.1lf%sB Max,',
1073     'GPRINT:free_avg:LAST:%5.1lf%sB Last\l',
1074     "LINE1:used_acc#$FullRed:Used",
1075     'GPRINT:used_min:MIN:%5.1lf%sB Min,',
1076     'GPRINT:used_avg:AVERAGE:%5.1lf%sB Avg,',
1077     'GPRINT:used_max:MAX:%5.1lf%sB Max,',
1078     'GPRINT:used_avg:LAST:%5.1lf%sB Last\l'
1079     ],
1080     disk => [
1081     'DEF:rtime_avg={file}:rtime:AVERAGE',
1082     'DEF:rtime_min={file}:rtime:MIN',
1083     'DEF:rtime_max={file}:rtime:MAX',
1084     'DEF:wtime_avg={file}:wtime:AVERAGE',
1085     'DEF:wtime_min={file}:wtime:MIN',
1086     'DEF:wtime_max={file}:wtime:MAX',
1087     'CDEF:rtime_avg_ms=rtime_avg,1000,/',
1088     'CDEF:rtime_min_ms=rtime_min,1000,/',
1089     'CDEF:rtime_max_ms=rtime_max,1000,/',
1090     'CDEF:wtime_avg_ms=wtime_avg,1000,/',
1091     'CDEF:wtime_min_ms=wtime_min,1000,/',
1092     'CDEF:wtime_max_ms=wtime_max,1000,/',
1093     'CDEF:total_avg_ms=rtime_avg_ms,wtime_avg_ms,+',
1094     'CDEF:total_min_ms=rtime_min_ms,wtime_min_ms,+',
1095     'CDEF:total_max_ms=rtime_max_ms,wtime_max_ms,+',
1096     "AREA:total_max_ms#$HalfRed",
1097     "AREA:total_min_ms#$Canvas",
1098     "LINE1:wtime_avg_ms#$FullGreen:Write",
1099     'GPRINT:wtime_min_ms:MIN:%5.1lf%s Min,',
1100     'GPRINT:wtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
1101     'GPRINT:wtime_max_ms:MAX:%5.1lf%s Max,',
1102     'GPRINT:wtime_avg_ms:LAST:%5.1lf%s Last\n',
1103     "LINE1:rtime_avg_ms#$FullBlue:Read ",
1104     'GPRINT:rtime_min_ms:MIN:%5.1lf%s Min,',
1105     'GPRINT:rtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
1106     'GPRINT:rtime_max_ms:MAX:%5.1lf%s Max,',
1107     'GPRINT:rtime_avg_ms:LAST:%5.1lf%s Last\n',
1108     "LINE1:total_avg_ms#$FullRed:Total",
1109     'GPRINT:total_min_ms:MIN:%5.1lf%s Min,',
1110     'GPRINT:total_avg_ms:AVERAGE:%5.1lf%s Avg,',
1111     'GPRINT:total_max_ms:MAX:%5.1lf%s Max,',
1112     'GPRINT:total_avg_ms:LAST:%5.1lf%s Last'
1113     ],
1114     disk_octets => ['-v', 'Bytes/s',
1115     'DEF:out_min={file}:write:MIN',
1116     'DEF:out_avg={file}:write:AVERAGE',
1117     'DEF:out_max={file}:write:MAX',
1118     'DEF:inc_min={file}:read:MIN',
1119     'DEF:inc_avg={file}:read:AVERAGE',
1120     'DEF:inc_max={file}:read:MAX',
1121     'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
1122     'CDEF:mytime=out_avg,TIME,TIME,IF',
1123     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1124     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1125     'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
1126     'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
1127     'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
1128     'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
1129     "AREA:out_avg#$HalfGreen",
1130     "AREA:inc_avg#$HalfBlue",
1131     "AREA:overlap#$HalfBlueGreen",
1132     "LINE1:out_avg#$FullGreen:Written",
1133     'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
1134     'GPRINT:out_max:MAX:%5.1lf%s Max,',
1135     'GPRINT:out_avg:LAST:%5.1lf%s Last',
1136     'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
1137     "LINE1:inc_avg#$FullBlue:Read   ",
1138     'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
1139     'GPRINT:inc_max:MAX:%5.1lf%s Max,',
1140     'GPRINT:inc_avg:LAST:%5.1lf%s Last',
1141     'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
1142     ],
1143     disk_merged => ['-v', 'Merged Ops/s',
1144     'DEF:out_min={file}:write:MIN',
1145     'DEF:out_avg={file}:write:AVERAGE',
1146     'DEF:out_max={file}:write:MAX',
1147     'DEF:inc_min={file}:read:MIN',
1148     'DEF:inc_avg={file}:read:AVERAGE',
1149     'DEF:inc_max={file}:read:MAX',
1150     'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
1151     "AREA:out_avg#$HalfGreen",
1152     "AREA:inc_avg#$HalfBlue",
1153     "AREA:overlap#$HalfBlueGreen",
1154     "LINE1:out_avg#$FullGreen:Written",
1155     'GPRINT:out_avg:AVERAGE:%6.2lf Avg,',
1156     'GPRINT:out_max:MAX:%6.2lf Max,',
1157     'GPRINT:out_avg:LAST:%6.2lf Last\l',
1158     "LINE1:inc_avg#$FullBlue:Read   ",
1159     'GPRINT:inc_avg:AVERAGE:%6.2lf Avg,',
1160     'GPRINT:inc_max:MAX:%6.2lf Max,',
1161     'GPRINT:inc_avg:LAST:%6.2lf Last\l'
1162     ],
1163     disk_ops => ['-v', 'Ops/s',
1164     'DEF:out_min={file}:write:MIN',
1165     'DEF:out_avg={file}:write:AVERAGE',
1166     'DEF:out_max={file}:write:MAX',
1167     'DEF:inc_min={file}:read:MIN',
1168     'DEF:inc_avg={file}:read:AVERAGE',
1169     'DEF:inc_max={file}:read:MAX',
1170     'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
1171     "AREA:out_avg#$HalfGreen",
1172     "AREA:inc_avg#$HalfBlue",
1173     "AREA:overlap#$HalfBlueGreen",
1174     "LINE1:out_avg#$FullGreen:Written",
1175     'GPRINT:out_avg:AVERAGE:%6.2lf Avg,',
1176     'GPRINT:out_max:MAX:%6.2lf Max,',
1177     'GPRINT:out_avg:LAST:%6.2lf Last\l',
1178     "LINE1:inc_avg#$FullBlue:Read   ",
1179     'GPRINT:inc_avg:AVERAGE:%6.2lf Avg,',
1180     'GPRINT:inc_max:MAX:%6.2lf Max,',
1181     'GPRINT:inc_avg:LAST:%6.2lf Last\l'
1182     ],
1183     disk_time => ['-v', 'Seconds/s',
1184     'DEF:out_min_raw={file}:write:MIN',
1185     'DEF:out_avg_raw={file}:write:AVERAGE',
1186     'DEF:out_max_raw={file}:write:MAX',
1187     'DEF:inc_min_raw={file}:read:MIN',
1188     'DEF:inc_avg_raw={file}:read:AVERAGE',
1189     'DEF:inc_max_raw={file}:read:MAX',
1190     'CDEF:out_min=out_min_raw,1000,/',
1191     'CDEF:out_avg=out_avg_raw,1000,/',
1192     'CDEF:out_max=out_max_raw,1000,/',
1193     'CDEF:inc_min=inc_min_raw,1000,/',
1194     'CDEF:inc_avg=inc_avg_raw,1000,/',
1195     'CDEF:inc_max=inc_max_raw,1000,/',
1196     'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
1197     "AREA:out_avg#$HalfGreen",
1198     "AREA:inc_avg#$HalfBlue",
1199     "AREA:overlap#$HalfBlueGreen",
1200     "LINE1:out_avg#$FullGreen:Written",
1201     'GPRINT:out_avg:AVERAGE:%5.1lf%ss Avg,',
1202     'GPRINT:out_max:MAX:%5.1lf%ss Max,',
1203     'GPRINT:out_avg:LAST:%5.1lf%ss Last\l',
1204     "LINE1:inc_avg#$FullBlue:Read   ",
1205     'GPRINT:inc_avg:AVERAGE:%5.1lf%ss Avg,',
1206     'GPRINT:inc_max:MAX:%5.1lf%ss Max,',
1207     'GPRINT:inc_avg:LAST:%5.1lf%ss Last\l'
1208     ],
1209     dns_octets => ['DEF:rsp_min_raw={file}:responses:MIN',
1210     'DEF:rsp_avg_raw={file}:responses:AVERAGE',
1211     'DEF:rsp_max_raw={file}:responses:MAX',
1212     'DEF:qry_min_raw={file}:queries:MIN',
1213     'DEF:qry_avg_raw={file}:queries:AVERAGE',
1214     'DEF:qry_max_raw={file}:queries:MAX',
1215     'CDEF:rsp_min=rsp_min_raw,8,*',
1216     'CDEF:rsp_avg=rsp_avg_raw,8,*',
1217     'CDEF:rsp_max=rsp_max_raw,8,*',
1218     'CDEF:qry_min=qry_min_raw,8,*',
1219     'CDEF:qry_avg=qry_avg_raw,8,*',
1220     'CDEF:qry_max=qry_max_raw,8,*',
1221     'CDEF:overlap=rsp_avg,qry_avg,GT,qry_avg,rsp_avg,IF',
1222     'CDEF:mytime=rsp_avg_raw,TIME,TIME,IF',
1223     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1224     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1225     'CDEF:rsp_avg_sample=rsp_avg_raw,UN,0,rsp_avg_raw,IF,sample_len,*',
1226     'CDEF:rsp_avg_sum=PREV,UN,0,PREV,IF,rsp_avg_sample,+',
1227     'CDEF:qry_avg_sample=qry_avg_raw,UN,0,qry_avg_raw,IF,sample_len,*',
1228     'CDEF:qry_avg_sum=PREV,UN,0,PREV,IF,qry_avg_sample,+',
1229     "AREA:rsp_avg#$HalfGreen",
1230     "AREA:qry_avg#$HalfBlue",
1231     "AREA:overlap#$HalfBlueGreen",
1232     "LINE1:rsp_avg#$FullGreen:Responses",
1233     'GPRINT:rsp_avg:AVERAGE:%5.1lf%s Avg,',
1234     'GPRINT:rsp_max:MAX:%5.1lf%s Max,',
1235     'GPRINT:rsp_avg:LAST:%5.1lf%s Last',
1236     'GPRINT:rsp_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
1237     "LINE1:qry_avg#$FullBlue:Queries  ",
1238     #'GPRINT:qry_min:MIN:%5.1lf %s Min,',
1239     'GPRINT:qry_avg:AVERAGE:%5.1lf%s Avg,',
1240     'GPRINT:qry_max:MAX:%5.1lf%s Max,',
1241     'GPRINT:qry_avg:LAST:%5.1lf%s Last',
1242     'GPRINT:qry_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
1243     ],
1244     dns_opcode => [
1245     'DEF:avg={file}:value:AVERAGE',
1246     'DEF:min={file}:value:MIN',
1247     'DEF:max={file}:value:MAX',
1248     "AREA:max#$HalfBlue",
1249     "AREA:min#$Canvas",
1250     "LINE1:avg#$FullBlue:Queries/s",
1251     'GPRINT:min:MIN:%9.3lf Min,',
1252     'GPRINT:avg:AVERAGE:%9.3lf Average,',
1253     'GPRINT:max:MAX:%9.3lf Max,',
1254     'GPRINT:avg:LAST:%9.3lf Last\l'
1255     ],
1256     email_count => ['-v', 'Mails',
1257     'DEF:avg={file}:value:AVERAGE',
1258     'DEF:min={file}:value:MIN',
1259     'DEF:max={file}:value:MAX',
1260     "AREA:max#$HalfMagenta",
1261     "AREA:min#$Canvas",
1262     "LINE1:avg#$FullMagenta:Count ",
1263     'GPRINT:min:MIN:%4.1lf Min,',
1264     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1265     'GPRINT:max:MAX:%4.1lf Max,',
1266     'GPRINT:avg:LAST:%4.1lf Last\l'
1267     ],
1268     email_size => ['-v', 'Bytes',
1269     'DEF:avg={file}:value:AVERAGE',
1270     'DEF:min={file}:value:MIN',
1271     'DEF:max={file}:value:MAX',
1272     "AREA:max#$HalfMagenta",
1273     "AREA:min#$Canvas",
1274     "LINE1:avg#$FullMagenta:Count ",
1275     'GPRINT:min:MIN:%4.1lf Min,',
1276     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1277     'GPRINT:max:MAX:%4.1lf Max,',
1278     'GPRINT:avg:LAST:%4.1lf Last\l'
1279     ],
1280     spam_score => ['-v', 'Score',
1281     'DEF:avg={file}:value:AVERAGE',
1282     'DEF:min={file}:value:MIN',
1283     'DEF:max={file}:value:MAX',
1284     "AREA:max#$HalfBlue",
1285     "AREA:min#$Canvas",
1286     "LINE1:avg#$FullBlue:Score ",
1287     'GPRINT:min:MIN:%4.1lf Min,',
1288     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1289     'GPRINT:max:MAX:%4.1lf Max,',
1290     'GPRINT:avg:LAST:%4.1lf Last\l'
1291     ],
1292     spam_check => [
1293     'DEF:avg={file}:hits:AVERAGE',
1294     'DEF:min={file}:hits:MIN',
1295     'DEF:max={file}:hits:MAX',
1296     "AREA:max#$HalfMagenta",
1297     "AREA:min#$Canvas",
1298     "LINE1:avg#$FullMagenta:Count ",
1299     'GPRINT:min:MIN:%4.1lf Min,',
1300     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1301     'GPRINT:max:MAX:%4.1lf Max,',
1302     'GPRINT:avg:LAST:%4.1lf Last\l'
1303     ],
1304     entropy => ['-v', 'Bits',
1305     'DEF:avg={file}:entropy:AVERAGE',
1306     'DEF:min={file}:entropy:MIN',
1307     'DEF:max={file}:entropy:MAX',
1308     "AREA:max#$HalfBlue",
1309     "AREA:min#$Canvas",
1310     "LINE1:avg#$FullBlue:Bits",
1311     'GPRINT:min:MIN:%4.0lfbit Min,',
1312     'GPRINT:avg:AVERAGE:%4.0lfbit Avg,',
1313     'GPRINT:max:MAX:%4.0lfbit Max,',
1314     'GPRINT:avg:LAST:%4.0lfbit Last\l'
1315     ],
1316     fanspeed => ['-v', 'RPM',
1317     'DEF:avg={file}:value:AVERAGE',
1318     'DEF:min={file}:value:MIN',
1319     'DEF:max={file}:value:MAX',
1320     "AREA:max#$HalfMagenta",
1321     "AREA:min#$Canvas",
1322     "LINE1:avg#$FullMagenta:RPM",
1323     'GPRINT:min:MIN:%4.1lf Min,',
1324     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1325     'GPRINT:max:MAX:%4.1lf Max,',
1326     'GPRINT:avg:LAST:%4.1lf Last\l'
1327     ],
1328     frequency => ['-v', 'Hertz',
1329     'DEF:avg={file}:frequency:AVERAGE',
1330     'DEF:min={file}:frequency:MIN',
1331     'DEF:max={file}:frequency:MAX',
1332     "AREA:max#$HalfBlue",
1333     "AREA:min#$Canvas",
1334     "LINE1:avg#$FullBlue:Frequency [Hz]",
1335     'GPRINT:min:MIN:%4.1lf Min,',
1336     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1337     'GPRINT:max:MAX:%4.1lf Max,',
1338     'GPRINT:avg:LAST:%4.1lf Last\l'
1339     ],
1340     frequency_offset => [ # NTPd
1341     'DEF:ppm_avg={file}:ppm:AVERAGE',
1342     'DEF:ppm_min={file}:ppm:MIN',
1343     'DEF:ppm_max={file}:ppm:MAX',
1344     "AREA:ppm_max#$HalfBlue",
1345     "AREA:ppm_min#$Canvas",
1346     "LINE1:ppm_avg#$FullBlue:{inst}",
1347     'GPRINT:ppm_min:MIN:%5.2lf Min,',
1348     'GPRINT:ppm_avg:AVERAGE:%5.2lf Avg,',
1349     'GPRINT:ppm_max:MAX:%5.2lf Max,',
1350     'GPRINT:ppm_avg:LAST:%5.2lf Last'
1351     ],
1352     gauge => ['-v', 'Exec value',
1353     'DEF:temp_avg={file}:value:AVERAGE',
1354     'DEF:temp_min={file}:value:MIN',
1355     'DEF:temp_max={file}:value:MAX',
1356     "AREA:temp_max#$HalfBlue",
1357     "AREA:temp_min#$Canvas",
1358     "LINE1:temp_avg#$FullBlue:Exec value",
1359     'GPRINT:temp_min:MIN:%6.2lf Min,',
1360     'GPRINT:temp_avg:AVERAGE:%6.2lf Avg,',
1361     'GPRINT:temp_max:MAX:%6.2lf Max,',
1362     'GPRINT:temp_avg:LAST:%6.2lf Last\l'
1363     ],
1364     hddtemp => [
1365     'DEF:temp_avg={file}:value:AVERAGE',
1366     'DEF:temp_min={file}:value:MIN',
1367     'DEF:temp_max={file}:value:MAX',
1368     "AREA:temp_max#$HalfRed",
1369     "AREA:temp_min#$Canvas",
1370     "LINE1:temp_avg#$FullRed:Temperature",
1371     'GPRINT:temp_min:MIN:%4.1lf Min,',
1372     'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
1373     'GPRINT:temp_max:MAX:%4.1lf Max,',
1374     'GPRINT:temp_avg:LAST:%4.1lf Last\l'
1375     ],
1376     humidity => ['-v', 'Percent',
1377     'DEF:temp_avg={file}:value:AVERAGE',
1378     'DEF:temp_min={file}:value:MIN',
1379     'DEF:temp_max={file}:value:MAX',
1380     "AREA:temp_max#$HalfGreen",
1381     "AREA:temp_min#$Canvas",
1382     "LINE1:temp_avg#$FullGreen:Temperature",
1383     'GPRINT:temp_min:MIN:%4.1lf%% Min,',
1384     'GPRINT:temp_avg:AVERAGE:%4.1lf%% Avg,',
1385     'GPRINT:temp_max:MAX:%4.1lf%% Max,',
1386     'GPRINT:temp_avg:LAST:%4.1lf%% Last\l'
1387     ],
1388     if_errors => ['-v', 'Errors/s',
1389     'DEF:tx_min={file}:tx:MIN',
1390     'DEF:tx_avg={file}:tx:AVERAGE',
1391     'DEF:tx_max={file}:tx:MAX',
1392     'DEF:rx_min={file}:rx:MIN',
1393     'DEF:rx_avg={file}:rx:AVERAGE',
1394     'DEF:rx_max={file}:rx:MAX',
1395     'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
1396     'CDEF:mytime=tx_avg,TIME,TIME,IF',
1397     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1398     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1399     'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
1400     'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
1401     'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
1402     'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
1403     "AREA:tx_avg#$HalfGreen",
1404     "AREA:rx_avg#$HalfBlue",
1405     "AREA:overlap#$HalfBlueGreen",
1406     "LINE1:tx_avg#$FullGreen:TX",
1407     'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
1408     'GPRINT:tx_max:MAX:%5.1lf%s Max,',
1409     'GPRINT:tx_avg:LAST:%5.1lf%s Last',
1410     'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
1411     "LINE1:rx_avg#$FullBlue:RX",
1412     #'GPRINT:rx_min:MIN:%5.1lf %s Min,',
1413     'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
1414     'GPRINT:rx_max:MAX:%5.1lf%s Max,',
1415     'GPRINT:rx_avg:LAST:%5.1lf%s Last',
1416     'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l'
1417     ],
1418     if_collisions => ['-v', 'Collisions/s',
1419     'DEF:min_raw={file}:value:MIN',
1420     'DEF:avg_raw={file}:value:AVERAGE',
1421     'DEF:max_raw={file}:value:MAX',
1422     'CDEF:min=min_raw,8,*',
1423     'CDEF:avg=avg_raw,8,*',
1424     'CDEF:max=max_raw,8,*',
1425     "AREA:max#$HalfBlue",
1426     "AREA:min#$Canvas",
1427     "LINE1:avg#$FullBlue:Collisions/s",
1428     'GPRINT:min:MIN:%5.1lf %s Min,',
1429     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
1430     'GPRINT:max:MAX:%5.1lf%s Max,',
1431     'GPRINT:avg:LAST:%5.1lf%s Last\l'
1432     ],
1433     if_dropped => ['-v', 'Packets/s',
1434     'DEF:tx_min={file}:tx:MIN',
1435     'DEF:tx_avg={file}:tx:AVERAGE',
1436     'DEF:tx_max={file}:tx:MAX',
1437     'DEF:rx_min={file}:rx:MIN',
1438     'DEF:rx_avg={file}:rx:AVERAGE',
1439     'DEF:rx_max={file}:rx:MAX',
1440     'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
1441     'CDEF:mytime=tx_avg,TIME,TIME,IF',
1442     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1443     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1444     'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
1445     'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
1446     'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
1447     'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
1448     "AREA:tx_avg#$HalfGreen",
1449     "AREA:rx_avg#$HalfBlue",
1450     "AREA:overlap#$HalfBlueGreen",
1451     "LINE1:tx_avg#$FullGreen:TX",
1452     'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
1453     'GPRINT:tx_max:MAX:%5.1lf%s Max,',
1454     'GPRINT:tx_avg:LAST:%5.1lf%s Last',
1455     'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
1456     "LINE1:rx_avg#$FullBlue:RX",
1457     #'GPRINT:rx_min:MIN:%5.1lf %s Min,',
1458     'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
1459     'GPRINT:rx_max:MAX:%5.1lf%s Max,',
1460     'GPRINT:rx_avg:LAST:%5.1lf%s Last',
1461     'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l'
1462     ],
1463     if_packets => ['-v', 'Packets/s',
1464     'DEF:tx_min={file}:tx:MIN',
1465     'DEF:tx_avg={file}:tx:AVERAGE',
1466     'DEF:tx_max={file}:tx:MAX',
1467     'DEF:rx_min={file}:rx:MIN',
1468     'DEF:rx_avg={file}:rx:AVERAGE',
1469     'DEF:rx_max={file}:rx:MAX',
1470     'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
1471     'CDEF:mytime=tx_avg,TIME,TIME,IF',
1472     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1473     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1474     'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
1475     'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
1476     'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
1477     'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
1478     "AREA:tx_avg#$HalfGreen",
1479     "AREA:rx_avg#$HalfBlue",
1480     "AREA:overlap#$HalfBlueGreen",
1481     "LINE1:tx_avg#$FullGreen:TX",
1482     'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
1483     'GPRINT:tx_max:MAX:%5.1lf%s Max,',
1484     'GPRINT:tx_avg:LAST:%5.1lf%s Last',
1485     'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
1486     "LINE1:rx_avg#$FullBlue:RX",
1487     #'GPRINT:rx_min:MIN:%5.1lf %s Min,',
1488     'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
1489     'GPRINT:rx_max:MAX:%5.1lf%s Max,',
1490     'GPRINT:rx_avg:LAST:%5.1lf%s Last',
1491     'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l'
1492     ],
1493     if_rx_errors => ['-v', 'Errors/s',
1494     'DEF:min={file}:value:MIN',
1495     'DEF:avg={file}:value:AVERAGE',
1496     'DEF:max={file}:value:MAX',
1497     'CDEF:mytime=avg,TIME,TIME,IF',
1498     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1499     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1500     'CDEF:avg_sample=avg,UN,0,avg,IF,sample_len,*',
1501     'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
1502     "AREA:avg#$HalfBlue",
1503     "LINE1:avg#$FullBlue:Errors/s",
1504     'GPRINT:avg:AVERAGE:%3.1lf%s Avg,',
1505     'GPRINT:max:MAX:%3.1lf%s Max,',
1506     'GPRINT:avg:LAST:%3.1lf%s Last',
1507     'GPRINT:avg_sum:LAST:(ca. %2.0lf%s Total)\l'
1508     ],
1509     ipt_bytes => ['-v', 'Bits/s',
1510     'DEF:min_raw={file}:value:MIN',
1511     'DEF:avg_raw={file}:value:AVERAGE',
1512     'DEF:max_raw={file}:value:MAX',
1513     'CDEF:min=min_raw,8,*',
1514     'CDEF:avg=avg_raw,8,*',
1515     'CDEF:max=max_raw,8,*',
1516     'CDEF:mytime=avg_raw,TIME,TIME,IF',
1517     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1518     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1519     'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
1520     'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
1521     "AREA:max#$HalfBlue",
1522     "AREA:min#$Canvas",
1523     "LINE1:avg#$FullBlue:Bits/s",
1524     #'GPRINT:min:MIN:%5.1lf %s Min,',
1525     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
1526     'GPRINT:max:MAX:%5.1lf%s Max,',
1527     'GPRINT:avg:LAST:%5.1lf%s Last',
1528     'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
1529     ],
1530     ipt_packets => ['-v', 'Packets/s',
1531     'DEF:min_raw={file}:value:MIN',
1532     'DEF:avg_raw={file}:value:AVERAGE',
1533     'DEF:max_raw={file}:value:MAX',
1534     'CDEF:min=min_raw,8,*',
1535     'CDEF:avg=avg_raw,8,*',
1536     'CDEF:max=max_raw,8,*',
1537     "AREA:max#$HalfBlue",
1538     "AREA:min#$Canvas",
1539     "LINE1:avg#$FullBlue:Packets/s",
1540     'GPRINT:min:MIN:%5.1lf %s Min,',
1541     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
1542     'GPRINT:max:MAX:%5.1lf%s Max,',
1543     'GPRINT:avg:LAST:%5.1lf%s Last\l'
1544     ],
1545     irq => ['-v', 'Issues/s',
1546     'DEF:avg={file}:value:AVERAGE',
1547     'DEF:min={file}:value:MIN',
1548     'DEF:max={file}:value:MAX',
1549     "AREA:max#$HalfBlue",
1550     "AREA:min#$Canvas",
1551     "LINE1:avg#$FullBlue:Issues/s",
1552     'GPRINT:min:MIN:%6.2lf Min,',
1553     'GPRINT:avg:AVERAGE:%6.2lf Avg,',
1554     'GPRINT:max:MAX:%6.2lf Max,',
1555     'GPRINT:avg:LAST:%6.2lf Last\l'
1556     ],
1557     load => ['-v', 'System load',
1558     'DEF:s_avg={file}:shortterm:AVERAGE',
1559     'DEF:s_min={file}:shortterm:MIN',
1560     'DEF:s_max={file}:shortterm:MAX',
1561     'DEF:m_avg={file}:midterm:AVERAGE',
1562     'DEF:m_min={file}:midterm:MIN',
1563     'DEF:m_max={file}:midterm:MAX',
1564     'DEF:l_avg={file}:longterm:AVERAGE',
1565     'DEF:l_min={file}:longterm:MIN',
1566     'DEF:l_max={file}:longterm:MAX',
1567     "AREA:s_max#$HalfGreen",
1568     "AREA:s_min#$Canvas",
1569     "LINE1:s_avg#$FullGreen: 1m average",
1570     'GPRINT:s_min:MIN:%4.2lf Min,',
1571     'GPRINT:s_avg:AVERAGE:%4.2lf Avg,',
1572     'GPRINT:s_max:MAX:%4.2lf Max,',
1573     'GPRINT:s_avg:LAST:%4.2lf Last\n',
1574     "LINE1:m_avg#$FullBlue: 5m average",
1575     'GPRINT:m_min:MIN:%4.2lf Min,',
1576     'GPRINT:m_avg:AVERAGE:%4.2lf Avg,',
1577     'GPRINT:m_max:MAX:%4.2lf Max,',
1578     'GPRINT:m_avg:LAST:%4.2lf Last\n',
1579     "LINE1:l_avg#$FullRed:15m average",
1580     'GPRINT:l_min:MIN:%4.2lf Min,',
1581     'GPRINT:l_avg:AVERAGE:%4.2lf Avg,',
1582     'GPRINT:l_max:MAX:%4.2lf Max,',
1583     'GPRINT:l_avg:LAST:%4.2lf Last'
1584     ],
1585     load_percent => [
1586     'DEF:avg={file}:percent:AVERAGE',
1587     'DEF:min={file}:percent:MIN',
1588     'DEF:max={file}:percent:MAX',
1589     "AREA:max#$HalfBlue",
1590     "AREA:min#$Canvas",
1591     "LINE1:avg#$FullBlue:Load",
1592     'GPRINT:min:MIN:%5.1lf%s%% Min,',
1593     'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
1594     'GPRINT:max:MAX:%5.1lf%s%% Max,',
1595     'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
1596     ],
1597     mails => ['DEF:rawgood={file}:good:AVERAGE',
1598     'DEF:rawspam={file}:spam:AVERAGE',
1599     'CDEF:good=rawgood,UN,0,rawgood,IF',
1600     'CDEF:spam=rawspam,UN,0,rawspam,IF',
1601     'CDEF:negspam=spam,-1,*',
1602     "AREA:good#$HalfGreen",
1603     "LINE1:good#$FullGreen:Good mails",
1604     'GPRINT:good:AVERAGE:%4.1lf Avg,',
1605     'GPRINT:good:MAX:%4.1lf Max,',
1606     'GPRINT:good:LAST:%4.1lf Last\n',
1607     "AREA:negspam#$HalfRed",
1608     "LINE1:negspam#$FullRed:Spam mails",
1609     'GPRINT:spam:AVERAGE:%4.1lf Avg,',
1610     'GPRINT:spam:MAX:%4.1lf Max,',
1611     'GPRINT:spam:LAST:%4.1lf Last',
1612     'HRULE:0#000000'
1613     ],
1614     memcached_command => ['-v', 'Commands',
1615     'DEF:avg={file}:value:AVERAGE',
1616     'DEF:min={file}:value:MIN',
1617     'DEF:max={file}:value:MAX',
1618     "AREA:max#$HalfBlue",
1619     "AREA:min#$Canvas",
1620     "LINE1:avg#$FullBlue:Commands",
1621     'GPRINT:min:MIN:%5.1lf%s Min,',
1622     'GPRINT:avg:AVERAGE:%5.1lf Avg,',
1623     'GPRINT:max:MAX:%5.1lf Max,',
1624     'GPRINT:avg:LAST:%5.1lf Last\l'
1625     ],
1626     memcached_connections => ['-v', 'Connections',
1627     'DEF:avg={file}:value:AVERAGE',
1628     'DEF:min={file}:value:MIN',
1629     'DEF:max={file}:value:MAX',
1630     "AREA:max#$HalfBlue",
1631     "AREA:min#$Canvas",
1632     "LINE1:avg#$FullBlue:Connections",
1633     'GPRINT:min:MIN:%4.1lf Min,',
1634     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1635     'GPRINT:max:MAX:%4.1lf Max,',
1636     'GPRINT:avg:LAST:%4.1lf Last\l'
1637     ],
1638     memcached_items => ['-v', 'Items',
1639     'DEF:avg={file}:value:AVERAGE',
1640     'DEF:min={file}:value:MIN',
1641     'DEF:max={file}:value:MAX',
1642     "AREA:max#$HalfBlue",
1643     "AREA:min#$Canvas",
1644     "LINE1:avg#$FullBlue:Items",
1645     'GPRINT:min:MIN:%4.1lf Min,',
1646     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1647     'GPRINT:max:MAX:%4.1lf Max,',
1648     'GPRINT:avg:LAST:%4.1lf Last\l'
1649     ],
1650     memcached_octets => ['-v', 'Bits/s',
1651     'DEF:out_min={file}:tx:MIN',
1652     'DEF:out_avg={file}:tx:AVERAGE',
1653     'DEF:out_max={file}:tx:MAX',
1654     'DEF:inc_min={file}:rx:MIN',
1655     'DEF:inc_avg={file}:rx:AVERAGE',
1656     'DEF:inc_max={file}:rx:MAX',
1657     'CDEF:mytime=out_avg,TIME,TIME,IF',
1658     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1659     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1660     'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
1661     'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
1662     'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
1663     'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
1664     'CDEF:out_bit_min=out_min,8,*',
1665     'CDEF:out_bit_avg=out_avg,8,*',
1666     'CDEF:out_bit_max=out_max,8,*',
1667     'CDEF:inc_bit_min=inc_min,8,*',
1668     'CDEF:inc_bit_avg=inc_avg,8,*',
1669     'CDEF:inc_bit_max=inc_max,8,*',
1670     'CDEF:overlap=out_bit_avg,inc_bit_avg,GT,inc_bit_avg,out_bit_avg,IF',
1671     "AREA:out_bit_avg#$HalfGreen",
1672     "AREA:inc_bit_avg#$HalfBlue",
1673     "AREA:overlap#$HalfBlueGreen",
1674     "LINE1:out_bit_avg#$FullGreen:Written",
1675     'GPRINT:out_bit_avg:AVERAGE:%5.1lf%s Avg,',
1676     'GPRINT:out_bit_max:MAX:%5.1lf%s Max,',
1677     'GPRINT:out_bit_avg:LAST:%5.1lf%s Last',
1678     'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
1679     "LINE1:inc_bit_avg#$FullBlue:Read   ",
1680     'GPRINT:inc_bit_avg:AVERAGE:%5.1lf%s Avg,',
1681     'GPRINT:inc_bit_max:MAX:%5.1lf%s Max,',
1682     'GPRINT:inc_bit_avg:LAST:%5.1lf%s Last',
1683     'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
1684     ],
1685     memcached_ops => ['-v', 'Ops',
1686     'DEF:avg={file}:value:AVERAGE',
1687     'DEF:min={file}:value:MIN',
1688     'DEF:max={file}:value:MAX',
1689     "AREA:max#$HalfBlue",
1690     "AREA:min#$Canvas",
1691     "LINE1:avg#$FullBlue:Ops",
1692     'GPRINT:min:MIN:%4.1lf Min,',
1693     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
1694     'GPRINT:max:MAX:%4.1lf Max,',
1695     'GPRINT:avg:LAST:%4.1lf Last\l'
1696     ],
1697     memory => ['-b', '1024', '-v', 'Bytes',
1698     'DEF:avg={file}:value:AVERAGE',
1699     'DEF:min={file}:value:MIN',
1700     'DEF:max={file}:value:MAX',
1701     "AREA:max#$HalfBlue",
1702     "AREA:min#$Canvas",
1703     "LINE1:avg#$FullBlue:Memory",
1704     'GPRINT:min:MIN:%5.1lf%sbyte Min,',
1705     'GPRINT:avg:AVERAGE:%5.1lf%sbyte Avg,',
1706     'GPRINT:max:MAX:%5.1lf%sbyte Max,',
1707     'GPRINT:avg:LAST:%5.1lf%sbyte Last\l'
1708     ],
1709     old_memory => [
1710     'DEF:used_avg={file}:used:AVERAGE',
1711     'DEF:free_avg={file}:free:AVERAGE',
1712     'DEF:buffers_avg={file}:buffers:AVERAGE',
1713     'DEF:cached_avg={file}:cached:AVERAGE',
1714     'DEF:used_min={file}:used:MIN',
1715     'DEF:free_min={file}:free:MIN',
1716     'DEF:buffers_min={file}:buffers:MIN',
1717     'DEF:cached_min={file}:cached:MIN',
1718     'DEF:used_max={file}:used:MAX',
1719     'DEF:free_max={file}:free:MAX',
1720     'DEF:buffers_max={file}:buffers:MAX',
1721     'DEF:cached_max={file}:cached:MAX',
1722     'CDEF:cached_avg_nn=cached_avg,UN,0,cached_avg,IF',
1723     'CDEF:buffers_avg_nn=buffers_avg,UN,0,buffers_avg,IF',
1724     'CDEF:free_cached_buffers_used=free_avg,cached_avg_nn,+,buffers_avg_nn,+,used_avg,+',
1725     'CDEF:cached_buffers_used=cached_avg,buffers_avg_nn,+,used_avg,+',
1726     'CDEF:buffers_used=buffers_avg,used_avg,+',
1727     "AREA:free_cached_buffers_used#$HalfGreen",
1728     "AREA:cached_buffers_used#$HalfBlue",
1729     "AREA:buffers_used#$HalfYellow",
1730     "AREA:used_avg#$HalfRed",
1731     "LINE1:free_cached_buffers_used#$FullGreen:Free        ",
1732     'GPRINT:free_min:MIN:%5.1lf%s Min,',
1733     'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
1734     'GPRINT:free_max:MAX:%5.1lf%s Max,',
1735     'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
1736     "LINE1:cached_buffers_used#$FullBlue:Page cache  ",
1737     'GPRINT:cached_min:MIN:%5.1lf%s Min,',
1738     'GPRINT:cached_avg:AVERAGE:%5.1lf%s Avg,',
1739     'GPRINT:cached_max:MAX:%5.1lf%s Max,',
1740     'GPRINT:cached_avg:LAST:%5.1lf%s Last\n',
1741     "LINE1:buffers_used#$FullYellow:Buffer cache",
1742     'GPRINT:buffers_min:MIN:%5.1lf%s Min,',
1743     'GPRINT:buffers_avg:AVERAGE:%5.1lf%s Avg,',
1744     'GPRINT:buffers_max:MAX:%5.1lf%s Max,',
1745     'GPRINT:buffers_avg:LAST:%5.1lf%s Last\n',
1746     "LINE1:used_avg#$FullRed:Used        ",
1747     'GPRINT:used_min:MIN:%5.1lf%s Min,',
1748     'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
1749     'GPRINT:used_max:MAX:%5.1lf%s Max,',
1750     'GPRINT:used_avg:LAST:%5.1lf%s Last'
1751     ],
1752     mysql_commands => ['-v', 'Issues/s',
1753     "DEF:val_avg={file}:value:AVERAGE",
1754     "DEF:val_min={file}:value:MIN",
1755     "DEF:val_max={file}:value:MAX",
1756     "AREA:val_max#$HalfBlue",
1757     "AREA:val_min#$Canvas",
1758     "LINE1:val_avg#$FullBlue:Issues/s",
1759     'GPRINT:val_min:MIN:%5.2lf Min,',
1760     'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
1761     'GPRINT:val_max:MAX:%5.2lf Max,',
1762     'GPRINT:val_avg:LAST:%5.2lf Last'
1763     ],
1764     mysql_handler => ['-v', 'Issues/s',
1765     "DEF:val_avg={file}:value:AVERAGE",
1766     "DEF:val_min={file}:value:MIN",
1767     "DEF:val_max={file}:value:MAX",
1768     "AREA:val_max#$HalfBlue",
1769     "AREA:val_min#$Canvas",
1770     "LINE1:val_avg#$FullBlue:Issues/s",
1771     'GPRINT:val_min:MIN:%5.2lf Min,',
1772     'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
1773     'GPRINT:val_max:MAX:%5.2lf Max,',
1774     'GPRINT:val_avg:LAST:%5.2lf Last'
1775     ],
1776     mysql_octets => ['-v', 'Bits/s',
1777     'DEF:out_min={file}:tx:MIN',
1778     'DEF:out_avg={file}:tx:AVERAGE',
1779     'DEF:out_max={file}:tx:MAX',
1780     'DEF:inc_min={file}:rx:MIN',
1781     'DEF:inc_avg={file}:rx:AVERAGE',
1782     'DEF:inc_max={file}:rx:MAX',
1783     'CDEF:mytime=out_avg,TIME,TIME,IF',
1784     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
1785     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
1786     'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
1787     'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
1788     'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
1789     'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
1790     'CDEF:out_bit_min=out_min,8,*',
1791     'CDEF:out_bit_avg=out_avg,8,*',
1792     'CDEF:out_bit_max=out_max,8,*',
1793     'CDEF:inc_bit_min=inc_min,8,*',
1794     'CDEF:inc_bit_avg=inc_avg,8,*',
1795     'CDEF:inc_bit_max=inc_max,8,*',
1796     'CDEF:overlap=out_bit_avg,inc_bit_avg,GT,inc_bit_avg,out_bit_avg,IF',
1797     "AREA:out_bit_avg#$HalfGreen",
1798     "AREA:inc_bit_avg#$HalfBlue",
1799     "AREA:overlap#$HalfBlueGreen",
1800     "LINE1:out_bit_avg#$FullGreen:Written",
1801     'GPRINT:out_bit_avg:AVERAGE:%5.1lf%s Avg,',
1802     'GPRINT:out_bit_max:MAX:%5.1lf%s Max,',
1803     'GPRINT:out_bit_avg:LAST:%5.1lf%s Last',
1804     'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
1805     "LINE1:inc_bit_avg#$FullBlue:Read   ",
1806     'GPRINT:inc_bit_avg:AVERAGE:%5.1lf%s Avg,',
1807     'GPRINT:inc_bit_max:MAX:%5.1lf%s Max,',
1808     'GPRINT:inc_bit_avg:LAST:%5.1lf%s Last',
1809     'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
1810     ],
1811     mysql_qcache => ['-v', 'Queries/s',
1812     "DEF:hits_min={file}:hits:MIN",
1813     "DEF:hits_avg={file}:hits:AVERAGE",
1814     "DEF:hits_max={file}:hits:MAX",
1815     "DEF:inserts_min={file}:inserts:MIN",
1816     "DEF:inserts_avg={file}:inserts:AVERAGE",
1817     "DEF:inserts_max={file}:inserts:MAX",
1818     "DEF:not_cached_min={file}:not_cached:MIN",
1819     "DEF:not_cached_avg={file}:not_cached:AVERAGE",
1820     "DEF:not_cached_max={file}:not_cached:MAX",
1821     "DEF:lowmem_prunes_min={file}:lowmem_prunes:MIN",
1822     "DEF:lowmem_prunes_avg={file}:lowmem_prunes:AVERAGE",
1823     "DEF:lowmem_prunes_max={file}:lowmem_prunes:MAX",
1824     "DEF:queries_min={file}:queries_in_cache:MIN",
1825     "DEF:queries_avg={file}:queries_in_cache:AVERAGE",
1826     "DEF:queries_max={file}:queries_in_cache:MAX",
1827     "CDEF:unknown=queries_avg,UNKN,+",
1828     "CDEF:not_cached_agg=hits_avg,inserts_avg,+,not_cached_avg,+",
1829     "CDEF:inserts_agg=hits_avg,inserts_avg,+",
1830     "CDEF:hits_agg=hits_avg",
1831     "AREA:not_cached_agg#$HalfYellow",
1832     "AREA:inserts_agg#$HalfBlue",
1833     "AREA:hits_agg#$HalfGreen",
1834     "LINE1:not_cached_agg#$FullYellow:Not Cached      ",
1835     'GPRINT:not_cached_min:MIN:%5.2lf Min,',
1836     'GPRINT:not_cached_avg:AVERAGE:%5.2lf Avg,',
1837     'GPRINT:not_cached_max:MAX:%5.2lf Max,',
1838     'GPRINT:not_cached_avg:LAST:%5.2lf Last\l',
1839     "LINE1:inserts_agg#$FullBlue:Inserts         ",
1840     'GPRINT:inserts_min:MIN:%5.2lf Min,',
1841     'GPRINT:inserts_avg:AVERAGE:%5.2lf Avg,',
1842     'GPRINT:inserts_max:MAX:%5.2lf Max,',
1843     'GPRINT:inserts_avg:LAST:%5.2lf Last\l',
1844     "LINE1:hits_agg#$FullGreen:Hits            ",
1845     'GPRINT:hits_min:MIN:%5.2lf Min,',
1846     'GPRINT:hits_avg:AVERAGE:%5.2lf Avg,',
1847     'GPRINT:hits_max:MAX:%5.2lf Max,',
1848     'GPRINT:hits_avg:LAST:%5.2lf Last\l',
1849     "LINE1:lowmem_prunes_avg#$FullRed:Lowmem Prunes   ",
1850     'GPRINT:lowmem_prunes_min:MIN:%5.2lf Min,',
1851     'GPRINT:lowmem_prunes_avg:AVERAGE:%5.2lf Avg,',
1852     'GPRINT:lowmem_prunes_max:MAX:%5.2lf Max,',
1853     'GPRINT:lowmem_prunes_avg:LAST:%5.2lf Last\l',
1854     "LINE1:unknown#$Canvas:Queries in cache",
1855     'GPRINT:queries_min:MIN:%5.0lf Min,',
1856     'GPRINT:queries_avg:AVERAGE:%5.0lf Avg,',
1857     'GPRINT:queries_max:MAX:%5.0lf Max,',
1858     'GPRINT:queries_avg:LAST:%5.0lf Last\l'
1859     ],
1860     mysql_threads => ['-v', 'Threads',
1861     "DEF:running_min={file}:running:MIN",
1862     "DEF:running_avg={file}:running:AVERAGE",
1863     "DEF:running_max={file}:running:MAX",
1864     "DEF:connected_min={file}:connected:MIN",
1865     "DEF:connected_avg={file}:connected:AVERAGE",
1866     "DEF:connected_max={file}:connected:MAX",
1867     "DEF:cached_min={file}:cached:MIN",
1868     "DEF:cached_avg={file}:cached:AVERAGE",
1869     "DEF:cached_max={file}:cached:MAX",
1870     "DEF:created_min={file}:created:MIN",
1871     "DEF:created_avg={file}:created:AVERAGE",
1872     "DEF:created_max={file}:created:MAX",
1873     "CDEF:unknown=created_avg,UNKN,+",
1874     "CDEF:cached_agg=connected_avg,cached_avg,+",
1875     "AREA:cached_agg#$HalfGreen",
1876     "AREA:connected_avg#$HalfBlue",
1877     "AREA:running_avg#$HalfRed",
1878     "LINE1:cached_agg#$FullGreen:Cached   ",
1879     'GPRINT:cached_min:MIN:%5.1lf Min,',
1880     'GPRINT:cached_avg:AVERAGE:%5.1lf Avg,',
1881     'GPRINT:cached_max:MAX:%5.1lf Max,',
1882     'GPRINT:cached_avg:LAST:%5.1lf Last\l',
1883     "LINE1:connected_avg#$FullBlue:Connected",
1884     'GPRINT:connected_min:MIN:%5.1lf Min,',
1885     'GPRINT:connected_avg:AVERAGE:%5.1lf Avg,',
1886     'GPRINT:connected_max:MAX:%5.1lf Max,',
1887     'GPRINT:connected_avg:LAST:%5.1lf Last\l',
1888     "LINE1:running_avg#$FullRed:Running  ",
1889     'GPRINT:running_min:MIN:%5.1lf Min,',
1890     'GPRINT:running_avg:AVERAGE:%5.1lf Avg,',
1891     'GPRINT:running_max:MAX:%5.1lf Max,',
1892     'GPRINT:running_avg:LAST:%5.1lf Last\l',
1893     "LINE1:unknown#$Canvas:Created  ",
1894     'GPRINT:created_min:MIN:%5.0lf Min,',
1895     'GPRINT:created_avg:AVERAGE:%5.0lf Avg,',
1896     'GPRINT:created_max:MAX:%5.0lf Max,',
1897     'GPRINT:created_avg:LAST:%5.0lf Last\l'
1898     ],
1899     nfs_procedure => ['-v', 'Issues/s',
1900     'DEF:avg={file}:value:AVERAGE',
1901     'DEF:min={file}:value:MIN',
1902     'DEF:max={file}:value:MAX',
1903     "AREA:max#$HalfBlue",
1904     "AREA:min#$Canvas",
1905     "LINE1:avg#$FullBlue:Issues/s",
1906     'GPRINT:min:MIN:%6.2lf Min,',
1907     'GPRINT:avg:AVERAGE:%6.2lf Avg,',
1908     'GPRINT:max:MAX:%6.2lf Max,',
1909     'GPRINT:avg:LAST:%6.2lf Last\l'
1910     ],
1911     nfs3_procedures => [
1912     "DEF:null_avg={file}:null:AVERAGE",
1913     "DEF:getattr_avg={file}:getattr:AVERAGE",
1914     "DEF:setattr_avg={file}:setattr:AVERAGE",
1915     "DEF:lookup_avg={file}:lookup:AVERAGE",
1916     "DEF:access_avg={file}:access:AVERAGE",
1917     "DEF:readlink_avg={file}:readlink:AVERAGE",
1918     "DEF:read_avg={file}:read:AVERAGE",
1919     "DEF:write_avg={file}:write:AVERAGE",
1920     "DEF:create_avg={file}:create:AVERAGE",
1921     "DEF:mkdir_avg={file}:mkdir:AVERAGE",
1922     "DEF:symlink_avg={file}:symlink:AVERAGE",
1923     "DEF:mknod_avg={file}:mknod:AVERAGE",
1924     "DEF:remove_avg={file}:remove:AVERAGE",
1925     "DEF:rmdir_avg={file}:rmdir:AVERAGE",
1926     "DEF:rename_avg={file}:rename:AVERAGE",
1927     "DEF:link_avg={file}:link:AVERAGE",
1928     "DEF:readdir_avg={file}:readdir:AVERAGE",
1929     "DEF:readdirplus_avg={file}:readdirplus:AVERAGE",
1930     "DEF:fsstat_avg={file}:fsstat:AVERAGE",
1931     "DEF:fsinfo_avg={file}:fsinfo:AVERAGE",
1932     "DEF:pathconf_avg={file}:pathconf:AVERAGE",
1933     "DEF:commit_avg={file}:commit:AVERAGE",
1934     "DEF:null_max={file}:null:MAX",
1935     "DEF:getattr_max={file}:getattr:MAX",
1936     "DEF:setattr_max={file}:setattr:MAX",
1937     "DEF:lookup_max={file}:lookup:MAX",
1938     "DEF:access_max={file}:access:MAX",
1939     "DEF:readlink_max={file}:readlink:MAX",
1940     "DEF:read_max={file}:read:MAX",
1941     "DEF:write_max={file}:write:MAX",
1942     "DEF:create_max={file}:create:MAX",
1943     "DEF:mkdir_max={file}:mkdir:MAX",
1944     "DEF:symlink_max={file}:symlink:MAX",
1945     "DEF:mknod_max={file}:mknod:MAX",
1946     "DEF:remove_max={file}:remove:MAX",
1947     "DEF:rmdir_max={file}:rmdir:MAX",
1948     "DEF:rename_max={file}:rename:MAX",
1949     "DEF:link_max={file}:link:MAX",
1950     "DEF:readdir_max={file}:readdir:MAX",
1951     "DEF:readdirplus_max={file}:readdirplus:MAX",
1952     "DEF:fsstat_max={file}:fsstat:MAX",
1953     "DEF:fsinfo_max={file}:fsinfo:MAX",
1954     "DEF:pathconf_max={file}:pathconf:MAX",
1955     "DEF:commit_max={file}:commit:MAX",
1956     "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
1957     "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,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
1958     "CDEF:stack_read=read_avg",
1959     "CDEF:stack_getattr=stack_read,getattr_avg,+",
1960     "CDEF:stack_access=stack_getattr,access_avg,+",
1961     "CDEF:stack_lookup=stack_access,lookup_avg,+",
1962     "CDEF:stack_write=stack_lookup,write_avg,+",
1963     "CDEF:stack_commit=stack_write,commit_avg,+",
1964     "CDEF:stack_setattr=stack_commit,setattr_avg,+",
1965     "CDEF:stack_other=stack_setattr,other_avg,+",
1966     "AREA:stack_other#$HalfRed",
1967     "AREA:stack_setattr#$HalfGreen",
1968     "AREA:stack_commit#$HalfYellow",
1969     "AREA:stack_write#$HalfGreen",
1970     "AREA:stack_lookup#$HalfBlue",
1971     "AREA:stack_access#$HalfMagenta",
1972     "AREA:stack_getattr#$HalfCyan",
1973     "AREA:stack_read#$HalfBlue",
1974     "LINE1:stack_other#$FullRed:Other  ",
1975     'GPRINT:other_max:MAX:%5.1lf Max,',
1976     'GPRINT:other_avg:AVERAGE:%5.1lf Avg,',
1977     'GPRINT:other_avg:LAST:%5.1lf Last\l',
1978     "LINE1:stack_setattr#$FullGreen:setattr",
1979     'GPRINT:setattr_max:MAX:%5.1lf Max,',
1980     'GPRINT:setattr_avg:AVERAGE:%5.1lf Avg,',
1981     'GPRINT:setattr_avg:LAST:%5.1lf Last\l',
1982     "LINE1:stack_commit#$FullYellow:commit ",
1983     'GPRINT:commit_max:MAX:%5.1lf Max,',
1984     'GPRINT:commit_avg:AVERAGE:%5.1lf Avg,',
1985     'GPRINT:commit_avg:LAST:%5.1lf Last\l',
1986     "LINE1:stack_write#$FullGreen:write  ",
1987     'GPRINT:write_max:MAX:%5.1lf Max,',
1988     'GPRINT:write_avg:AVERAGE:%5.1lf Avg,',
1989     'GPRINT:write_avg:LAST:%5.1lf Last\l',
1990     "LINE1:stack_lookup#$FullBlue:lookup ",
1991     'GPRINT:lookup_max:MAX:%5.1lf Max,',
1992     'GPRINT:lookup_avg:AVERAGE:%5.1lf Avg,',
1993     'GPRINT:lookup_avg:LAST:%5.1lf Last\l',
1994     "LINE1:stack_access#$FullMagenta:access ",
1995     'GPRINT:access_max:MAX:%5.1lf Max,',
1996     'GPRINT:access_avg:AVERAGE:%5.1lf Avg,',
1997     'GPRINT:access_avg:LAST:%5.1lf Last\l',
1998     "LINE1:stack_getattr#$FullCyan:getattr",
1999     'GPRINT:getattr_max:MAX:%5.1lf Max,',
2000     'GPRINT:getattr_avg:AVERAGE:%5.1lf Avg,',
2001     'GPRINT:getattr_avg:LAST:%5.1lf Last\l',
2002     "LINE1:stack_read#$FullBlue:read   ",
2003     'GPRINT:read_max:MAX:%5.1lf Max,',
2004     'GPRINT:read_avg:AVERAGE:%5.1lf Avg,',
2005     'GPRINT:read_avg:LAST:%5.1lf Last\l'
2006     ],
2007     partition => [
2008     "DEF:rbyte_avg={file}:rbytes:AVERAGE",
2009     "DEF:rbyte_min={file}:rbytes:MIN",
2010     "DEF:rbyte_max={file}:rbytes:MAX",
2011     "DEF:wbyte_avg={file}:wbytes:AVERAGE",
2012     "DEF:wbyte_min={file}:wbytes:MIN",
2013     "DEF:wbyte_max={file}:wbytes:MAX",
2014     'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
2015     "AREA:wbyte_avg#$HalfGreen",
2016     "AREA:rbyte_avg#$HalfBlue",
2017     "AREA:overlap#$HalfBlueGreen",
2018     "LINE1:wbyte_avg#$FullGreen:Write",
2019     'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
2020     'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
2021     'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
2022     'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
2023     "LINE1:rbyte_avg#$FullBlue:Read ",
2024     'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
2025     'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
2026     'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
2027     'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l'
2028     ],
2029     percent => ['-v', 'Percent',
2030     'DEF:avg={file}:percent:AVERAGE',
2031     'DEF:min={file}:percent:MIN',
2032     'DEF:max={file}:percent:MAX',
2033     "AREA:max#$HalfBlue",
2034     "AREA:min#$Canvas",
2035     "LINE1:avg#$FullBlue:Percent",
2036     'GPRINT:min:MIN:%5.1lf%% Min,',
2037     'GPRINT:avg:AVERAGE:%5.1lf%% Avg,',
2038     'GPRINT:max:MAX:%5.1lf%% Max,',
2039     'GPRINT:avg:LAST:%5.1lf%% Last\l'
2040     ],
2041     ping => ['DEF:ping_avg={file}:ping:AVERAGE',
2042     'DEF:ping_min={file}:ping:MIN',
2043     'DEF:ping_max={file}:ping:MAX',
2044     "AREA:ping_max#$HalfBlue",
2045     "AREA:ping_min#$Canvas",
2046     "LINE1:ping_avg#$FullBlue:Ping",
2047     'GPRINT:ping_min:MIN:%4.1lf ms Min,',
2048     'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
2049     'GPRINT:ping_max:MAX:%4.1lf ms Max,',
2050     'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
2051     pg_blks => ['DEF:pg_blks_avg={file}:value:AVERAGE',
2052     'DEF:pg_blks_min={file}:value:MIN',
2053     'DEF:pg_blks_max={file}:value:MAX',
2054     "AREA:pg_blks_max#$HalfBlue",
2055     "AREA:pg_blks_min#$Canvas",
2056     "LINE1:pg_blks_avg#$FullBlue:Blocks",
2057     'GPRINT:pg_blks_min:MIN:%4.1lf%s Min,',
2058     'GPRINT:pg_blks_avg:AVERAGE:%4.1lf%s Avg,',
2059     'GPRINT:pg_blks_max:MAX:%4.1lf%s Max,',
2060     'GPRINT:pg_blks_avg:LAST:%4.1lf%s Last'],
2061     pg_db_size => ['DEF:pg_db_size_avg={file}:value:AVERAGE',
2062     'DEF:pg_db_size_min={file}:value:MIN',
2063     'DEF:pg_db_size_max={file}:value:MAX',
2064     "AREA:pg_db_size_max#$HalfBlue",
2065     "AREA:pg_db_size_min#$Canvas",
2066     "LINE1:pg_db_size_avg#$FullBlue:Bytes",
2067     'GPRINT:pg_db_size_min:MIN:%4.1lf%s Min,',
2068     'GPRINT:pg_db_size_avg:AVERAGE:%4.1lf%s Avg,',
2069     'GPRINT:pg_db_size_max:MAX:%4.1lf%s Max,',
2070     'GPRINT:pg_db_size_avg:LAST:%4.1lf%s Last'],
2071     pg_n_tup_c => ['DEF:pg_n_tup_avg={file}:value:AVERAGE',
2072     'DEF:pg_n_tup_min={file}:value:MIN',
2073     'DEF:pg_n_tup_max={file}:value:MAX',
2074     "AREA:pg_n_tup_max#$HalfBlue",
2075     "AREA:pg_n_tup_min#$Canvas",
2076     "LINE1:pg_n_tup_avg#$FullBlue:Tuples",
2077     'GPRINT:pg_n_tup_min:MIN:%4.1lf%s Min,',
2078     'GPRINT:pg_n_tup_avg:AVERAGE:%4.1lf%s Avg,',
2079     'GPRINT:pg_n_tup_max:MAX:%4.1lf%s Max,',
2080     'GPRINT:pg_n_tup_avg:LAST:%4.1lf%s Last'],
2081     pg_n_tup_g => ['DEF:pg_n_tup_avg={file}:value:AVERAGE',
2082     'DEF:pg_n_tup_min={file}:value:MIN',
2083     'DEF:pg_n_tup_max={file}:value:MAX',
2084     "AREA:pg_n_tup_max#$HalfBlue",
2085     "AREA:pg_n_tup_min#$Canvas",
2086     "LINE1:pg_n_tup_avg#$FullBlue:Tuples",
2087     'GPRINT:pg_n_tup_min:MIN:%4.1lf%s Min,',
2088     'GPRINT:pg_n_tup_avg:AVERAGE:%4.1lf%s Avg,',
2089     'GPRINT:pg_n_tup_max:MAX:%4.1lf%s Max,',
2090     'GPRINT:pg_n_tup_avg:LAST:%4.1lf%s Last'],
2091     pg_numbackends => ['DEF:pg_numbackends_avg={file}:value:AVERAGE',
2092     'DEF:pg_numbackends_min={file}:value:MIN',
2093     'DEF:pg_numbackends_max={file}:value:MAX',
2094     "AREA:pg_numbackends_max#$HalfBlue",
2095     "AREA:pg_numbackends_min#$Canvas",
2096     "LINE1:pg_numbackends_avg#$FullBlue:Backends",
2097     'GPRINT:pg_numbackends_min:MIN:%4.1lf%s Min,',
2098     'GPRINT:pg_numbackends_avg:AVERAGE:%4.1lf%s Avg,',
2099     'GPRINT:pg_numbackends_max:MAX:%4.1lf%s Max,',
2100     'GPRINT:pg_numbackends_avg:LAST:%4.1lf%s Last'],
2101     pg_scan => ['DEF:pg_scan_avg={file}:value:AVERAGE',
2102     'DEF:pg_scan_min={file}:value:MIN',
2103     'DEF:pg_scan_max={file}:value:MAX',
2104     "AREA:pg_scan_max#$HalfBlue",
2105     "AREA:pg_scan_min#$Canvas",
2106     "LINE1:pg_scan_avg#$FullBlue:Scans",
2107     'GPRINT:pg_scan_min:MIN:%4.1lf%s Min,',
2108     'GPRINT:pg_scan_avg:AVERAGE:%4.1lf%s Avg,',
2109     'GPRINT:pg_scan_max:MAX:%4.1lf%s Max,',
2110     'GPRINT:pg_scan_avg:LAST:%4.1lf%s Last'],
2111     pg_xact => ['DEF:pg_xact_avg={file}:value:AVERAGE',
2112     'DEF:pg_xact_min={file}:value:MIN',
2113     'DEF:pg_xact_max={file}:value:MAX',
2114     "AREA:pg_xact_max#$HalfBlue",
2115     "AREA:pg_xact_min#$Canvas",
2116     "LINE1:pg_xact_avg#$FullBlue:Transactions",
2117     'GPRINT:pg_xact_min:MIN:%4.1lf%s Min,',
2118     'GPRINT:pg_xact_avg:AVERAGE:%4.1lf%s Avg,',
2119     'GPRINT:pg_xact_max:MAX:%4.1lf%s Max,',
2120     'GPRINT:pg_xact_avg:LAST:%4.1lf%s Last'],
2121     power => ['-v', 'Watt',
2122     'DEF:avg={file}:value:AVERAGE',
2123     'DEF:min={file}:value:MIN',
2124     'DEF:max={file}:value:MAX',
2125     "AREA:max#$HalfBlue",
2126     "AREA:min#$Canvas",
2127     "LINE1:avg#$FullBlue:Watt",
2128     'GPRINT:min:MIN:%5.1lf%sW Min,',
2129     'GPRINT:avg:AVERAGE:%5.1lf%sW Avg,',
2130     'GPRINT:max:MAX:%5.1lf%sW Max,',
2131     'GPRINT:avg:LAST:%5.1lf%sW Last\l'
2132     ],
2133     processes => [
2134     "DEF:running_avg={file}:running:AVERAGE",
2135     "DEF:running_min={file}:running:MIN",
2136     "DEF:running_max={file}:running:MAX",
2137     "DEF:sleeping_avg={file}:sleeping:AVERAGE",
2138     "DEF:sleeping_min={file}:sleeping:MIN",
2139     "DEF:sleeping_max={file}:sleeping:MAX",
2140     "DEF:zombies_avg={file}:zombies:AVERAGE",
2141     "DEF:zombies_min={file}:zombies:MIN",
2142     "DEF:zombies_max={file}:zombies:MAX",
2143     "DEF:stopped_avg={file}:stopped:AVERAGE",
2144     "DEF:stopped_min={file}:stopped:MIN",
2145     "DEF:stopped_max={file}:stopped:MAX",
2146     "DEF:paging_avg={file}:paging:AVERAGE",
2147     "DEF:paging_min={file}:paging:MIN",
2148     "DEF:paging_max={file}:paging:MAX",
2149     "DEF:blocked_avg={file}:blocked:AVERAGE",
2150     "DEF:blocked_min={file}:blocked:MIN",
2151     "DEF:blocked_max={file}:blocked:MAX",
2152     'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
2153     'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
2154     'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
2155     'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
2156     'CDEF:running_acc=sleeping_avg,running_avg,+',
2157     'CDEF:sleeping_acc=sleeping_avg',
2158     "AREA:paging_acc#$HalfYellow",
2159     "AREA:blocked_acc#$HalfCyan",
2160     "AREA:zombies_acc#$HalfRed",
2161     "AREA:stopped_acc#$HalfMagenta",
2162     "AREA:running_acc#$HalfGreen",
2163     "AREA:sleeping_acc#$HalfBlue",
2164     "LINE1:paging_acc#$FullYellow:Paging  ",
2165     'GPRINT:paging_min:MIN:%5.1lf Min,',
2166     'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
2167     'GPRINT:paging_max:MAX:%5.1lf Max,',
2168     'GPRINT:paging_avg:LAST:%5.1lf Last\l',
2169     "LINE1:blocked_acc#$FullCyan:Blocked ",
2170     'GPRINT:blocked_min:MIN:%5.1lf Min,',
2171     'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
2172     'GPRINT:blocked_max:MAX:%5.1lf Max,',
2173     'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
2174     "LINE1:zombies_acc#$FullRed:Zombies ",
2175     'GPRINT:zombies_min:MIN:%5.1lf Min,',
2176     'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
2177     'GPRINT:zombies_max:MAX:%5.1lf Max,',
2178     'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
2179     "LINE1:stopped_acc#$FullMagenta:Stopped ",
2180     'GPRINT:stopped_min:MIN:%5.1lf Min,',
2181     'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
2182     'GPRINT:stopped_max:MAX:%5.1lf Max,',
2183     'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
2184     "LINE1:running_acc#$FullGreen:Running ",
2185     'GPRINT:running_min:MIN:%5.1lf Min,',
2186     'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
2187     'GPRINT:running_max:MAX:%5.1lf Max,',
2188     'GPRINT:running_avg:LAST:%5.1lf Last\l',
2189     "LINE1:sleeping_acc#$FullBlue:Sleeping",
2190     'GPRINT:sleeping_min:MIN:%5.1lf Min,',
2191     'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
2192     'GPRINT:sleeping_max:MAX:%5.1lf Max,',
2193     'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
2194     ],
2195     ps_count => ['-v', 'Processes',
2196     'DEF:procs_avg={file}:processes:AVERAGE',
2197     'DEF:procs_min={file}:processes:MIN',
2198     'DEF:procs_max={file}:processes:MAX',
2199     'DEF:thrds_avg={file}:threads:AVERAGE',
2200     'DEF:thrds_min={file}:threads:MIN',
2201     'DEF:thrds_max={file}:threads:MAX',
2202     "AREA:thrds_avg#$HalfBlue",
2203     "AREA:procs_avg#$HalfRed",
2204     "LINE1:thrds_avg#$FullBlue:Threads  ",
2205     'GPRINT:thrds_min:MIN:%5.1lf Min,',
2206     'GPRINT:thrds_avg:AVERAGE:%5.1lf Avg,',
2207     'GPRINT:thrds_max:MAX:%5.1lf Max,',
2208     'GPRINT:thrds_avg:LAST:%5.1lf Last\l',
2209     "LINE1:procs_avg#$FullRed:Processes",
2210     'GPRINT:procs_min:MIN:%5.1lf Min,',
2211     'GPRINT:procs_avg:AVERAGE:%5.1lf Avg,',
2212     'GPRINT:procs_max:MAX:%5.1lf Max,',
2213     'GPRINT:procs_avg:LAST:%5.1lf Last\l'
2214     ],
2215     ps_cputime => ['-v', 'Jiffies',
2216     'DEF:user_avg_raw={file}:user:AVERAGE',
2217     'DEF:user_min_raw={file}:user:MIN',
2218     'DEF:user_max_raw={file}:user:MAX',
2219     'DEF:syst_avg_raw={file}:syst:AVERAGE',
2220     'DEF:syst_min_raw={file}:syst:MIN',
2221     'DEF:syst_max_raw={file}:syst:MAX',
2222     'CDEF:user_avg=user_avg_raw,1000000,/',
2223     'CDEF:user_min=user_min_raw,1000000,/',
2224     'CDEF:user_max=user_max_raw,1000000,/',
2225     'CDEF:syst_avg=syst_avg_raw,1000000,/',
2226     'CDEF:syst_min=syst_min_raw,1000000,/',
2227     'CDEF:syst_max=syst_max_raw,1000000,/',
2228     'CDEF:user_syst=syst_avg,UN,0,syst_avg,IF,user_avg,+',
2229     "AREA:user_syst#$HalfBlue",
2230     "AREA:syst_avg#$HalfRed",
2231     "LINE1:user_syst#$FullBlue:User  ",
2232     'GPRINT:user_min:MIN:%5.1lf%s Min,',
2233     'GPRINT:user_avg:AVERAGE:%5.1lf%s Avg,',
2234     'GPRINT:user_max:MAX:%5.1lf%s Max,',
2235     'GPRINT:user_avg:LAST:%5.1lf%s Last\l',
2236     "LINE1:syst_avg#$FullRed:System",
2237     'GPRINT:syst_min:MIN:%5.1lf%s Min,',
2238     'GPRINT:syst_avg:AVERAGE:%5.1lf%s Avg,',
2239     'GPRINT:syst_max:MAX:%5.1lf%s Max,',
2240     'GPRINT:syst_avg:LAST:%5.1lf%s Last\l'
2241     ],
2242     ps_pagefaults => ['-v', 'Pagefaults/s',
2243     'DEF:minor_avg={file}:minflt:AVERAGE',
2244     'DEF:minor_min={file}:minflt:MIN',
2245     'DEF:minor_max={file}:minflt:MAX',
2246     'DEF:major_avg={file}:majflt:AVERAGE',
2247     'DEF:major_min={file}:majflt:MIN',
2248     'DEF:major_max={file}:majflt:MAX',
2249     'CDEF:minor_major=major_avg,UN,0,major_avg,IF,minor_avg,+',
2250     "AREA:minor_major#$HalfBlue",
2251     "AREA:major_avg#$HalfRed",
2252     "LINE1:minor_major#$FullBlue:Minor",
2253     'GPRINT:minor_min:MIN:%5.1lf%s Min,',
2254     'GPRINT:minor_avg:AVERAGE:%5.1lf%s Avg,',
2255     'GPRINT:minor_max:MAX:%5.1lf%s Max,',
2256     'GPRINT:minor_avg:LAST:%5.1lf%s Last\l',
2257     "LINE1:major_avg#$FullRed:Major",
2258     'GPRINT:major_min:MIN:%5.1lf%s Min,',
2259     'GPRINT:major_avg:AVERAGE:%5.1lf%s Avg,',
2260     'GPRINT:major_max:MAX:%5.1lf%s Max,',
2261     'GPRINT:major_avg:LAST:%5.1lf%s Last\l'
2262     ],
2263     ps_rss => ['-v', 'Bytes',
2264     'DEF:avg={file}:value:AVERAGE',
2265     'DEF:min={file}:value:MIN',
2266     'DEF:max={file}:value:MAX',
2267     "AREA:avg#$HalfBlue",
2268     "LINE1:avg#$FullBlue:RSS",
2269     'GPRINT:min:MIN:%5.1lf%s Min,',
2270     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
2271     'GPRINT:max:MAX:%5.1lf%s Max,',
2272     'GPRINT:avg:LAST:%5.1lf%s Last\l'
2273     ],
2274     ps_state => ['-v', 'Processes',
2275     'DEF:avg={file}:value:AVERAGE',
2276     'DEF:min={file}:value:MIN',
2277     'DEF:max={file}:value:MAX',
2278     "AREA:max#$HalfBlue",
2279     "AREA:min#$Canvas",
2280     "LINE1:avg#$FullBlue:Processes",
2281     'GPRINT:min:MIN:%6.2lf Min,',
2282     'GPRINT:avg:AVERAGE:%6.2lf Avg,',
2283     'GPRINT:max:MAX:%6.2lf Max,',
2284     'GPRINT:avg:LAST:%6.2lf Last\l'
2285     ],
2286     signal_noise => ['-v', 'dBm',
2287     'DEF:avg={file}:value:AVERAGE',
2288     'DEF:min={file}:value:MIN',
2289     'DEF:max={file}:value:MAX',
2290     "AREA:max#$HalfBlue",
2291     "AREA:min#$Canvas",
2292     "LINE1:avg#$FullBlue:Noise",
2293     'GPRINT:min:MIN:%5.1lf%sdBm Min,',
2294     'GPRINT:avg:AVERAGE:%5.1lf%sdBm Avg,',
2295     'GPRINT:max:MAX:%5.1lf%sdBm Max,',
2296     'GPRINT:avg:LAST:%5.1lf%sdBm Last\l'
2297     ],
2298     signal_power => ['-v', 'dBm',
2299     'DEF:avg={file}:value:AVERAGE',
2300     'DEF:min={file}:value:MIN',
2301     'DEF:max={file}:value:MAX',
2302     "AREA:max#$HalfBlue",
2303     "AREA:min#$Canvas",
2304     "LINE1:avg#$FullBlue:Power",
2305     'GPRINT:min:MIN:%5.1lf%sdBm Min,',
2306     'GPRINT:avg:AVERAGE:%5.1lf%sdBm Avg,',
2307     'GPRINT:max:MAX:%5.1lf%sdBm Max,',
2308     'GPRINT:avg:LAST:%5.1lf%sdBm Last\l'
2309     ],
2310     signal_quality => ['-v', '%',
2311     'DEF:avg={file}:value:AVERAGE',
2312     'DEF:min={file}:value:MIN',
2313     'DEF:max={file}:value:MAX',
2314     "AREA:max#$HalfBlue",
2315     "AREA:min#$Canvas",
2316     "LINE1:avg#$FullBlue:Quality",
2317     'GPRINT:min:MIN:%5.1lf%s%% Min,',
2318     'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
2319     'GPRINT:max:MAX:%5.1lf%s%% Max,',
2320     'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
2321     ],
2322     swap => ['-v', 'Bytes', '-b', '1024',
2323     'DEF:avg={file}:value:AVERAGE',
2324     'DEF:min={file}:value:MIN',
2325     'DEF:max={file}:value:MAX',
2326     "AREA:max#$HalfBlue",
2327     "AREA:min#$Canvas",
2328     "LINE1:avg#$FullBlue:Bytes",
2329     'GPRINT:min:MIN:%6.2lf%sByte Min,',
2330     'GPRINT:avg:AVERAGE:%6.2lf%sByte Avg,',
2331     'GPRINT:max:MAX:%6.2lf%sByte Max,',
2332     'GPRINT:avg:LAST:%6.2lf%sByte Last\l'
2333     ],
2334     old_swap => [
2335     'DEF:used_avg={file}:used:AVERAGE',
2336     'DEF:used_min={file}:used:MIN',
2337     'DEF:used_max={file}:used:MAX',
2338     'DEF:free_avg={file}:free:AVERAGE',
2339     'DEF:free_min={file}:free:MIN',
2340     'DEF:free_max={file}:free:MAX',
2341     'DEF:cach_avg={file}:cached:AVERAGE',
2342     'DEF:cach_min={file}:cached:MIN',
2343     'DEF:cach_max={file}:cached:MAX',
2344     'DEF:resv_avg={file}:resv:AVERAGE',
2345     'DEF:resv_min={file}:resv:MIN',
2346     'DEF:resv_max={file}:resv:MAX',
2347     'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
2348     'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
2349     'CDEF:used_acc=used_avg',
2350     'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
2351     'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
2352     'CDEF:free_acc=cach_acc,free_avg,+',
2353     "AREA:free_acc#$HalfGreen",
2354     "AREA:cach_acc#$HalfBlue",
2355     "AREA:resv_acc#$HalfYellow",
2356     "AREA:used_acc#$HalfRed",
2357     "LINE1:free_acc#$FullGreen:Free    ",
2358     'GPRINT:free_min:MIN:%5.1lf%s Min,',
2359     'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
2360     'GPRINT:free_max:MAX:%5.1lf%s Max,',
2361     'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
2362     "LINE1:cach_acc#$FullBlue:Cached  ",
2363     'GPRINT:cach_min:MIN:%5.1lf%s Min,',
2364     'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
2365     'GPRINT:cach_max:MAX:%5.1lf%s Max,',
2366     'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
2367     "LINE1:resv_acc#$FullYellow:Reserved",
2368     'GPRINT:resv_min:MIN:%5.1lf%s Min,',
2369     'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
2370     'GPRINT:resv_max:MAX:%5.1lf%s Max,',
2371     'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
2372     "LINE1:used_acc#$FullRed:Used    ",
2373     'GPRINT:used_min:MIN:%5.1lf%s Min,',
2374     'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
2375     'GPRINT:used_max:MAX:%5.1lf%s Max,',
2376     'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
2377     ],
2378     tcp_connections => ['-v', 'Connections',
2379     'DEF:avg={file}:value:AVERAGE',
2380     'DEF:min={file}:value:MIN',
2381     'DEF:max={file}:value:MAX',
2382     "AREA:max#$HalfBlue",
2383     "AREA:min#$Canvas",
2384     "LINE1:avg#$FullBlue:Connections",
2385     'GPRINT:min:MIN:%4.1lf Min,',
2386     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
2387     'GPRINT:max:MAX:%4.1lf Max,',
2388     'GPRINT:avg:LAST:%4.1lf Last\l'
2389     ],
2390     temperature => ['-v', 'Celsius',
2391     'DEF:temp_avg={file}:value:AVERAGE',
2392     'DEF:temp_min={file}:value:MIN',
2393     'DEF:temp_max={file}:value:MAX',
2394     'CDEF:average=temp_avg,0.2,*,PREV,UN,temp_avg,PREV,IF,0.8,*,+',
2395     "AREA:temp_max#$HalfRed",
2396     "AREA:temp_min#$Canvas",
2397     "LINE1:temp_avg#$FullRed:Temperature",
2398     'GPRINT:temp_min:MIN:%4.1lf Min,',
2399     'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
2400     'GPRINT:temp_max:MAX:%4.1lf Max,',
2401     'GPRINT:temp_avg:LAST:%4.1lf Last\l'
2402     ],
2403     timeleft => ['-v', 'Minutes',
2404     'DEF:avg={file}:timeleft:AVERAGE',
2405     'DEF:min={file}:timeleft:MIN',
2406     'DEF:max={file}:timeleft:MAX',
2407     "AREA:max#$HalfBlue",
2408     "AREA:min#$Canvas",
2409     "LINE1:avg#$FullBlue:Time left [min]",
2410     'GPRINT:min:MIN:%5.1lf%s Min,',
2411     'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
2412     'GPRINT:max:MAX:%5.1lf%s Max,',
2413     'GPRINT:avg:LAST:%5.1lf%s Last\l'
2414     ],
2415     time_offset => [ # NTPd
2416     'DEF:s_avg={file}:seconds:AVERAGE',
2417     'DEF:s_min={file}:seconds:MIN',
2418     'DEF:s_max={file}:seconds:MAX',
2419     "AREA:s_max#$HalfBlue",
2420     "AREA:s_min#$Canvas",
2421     "LINE1:s_avg#$FullBlue:{inst}",
2422     'GPRINT:s_min:MIN:%7.3lf%s Min,',
2423     'GPRINT:s_avg:AVERAGE:%7.3lf%s Avg,',
2424     'GPRINT:s_max:MAX:%7.3lf%s Max,',
2425     'GPRINT:s_avg:LAST:%7.3lf%s Last'
2426     ],
2427     if_octets => ['-v', 'Bits/s', '-l', '0',
2428     'DEF:out_min_raw={file}:tx:MIN',
2429     'DEF:out_avg_raw={file}:tx:AVERAGE',
2430     'DEF:out_max_raw={file}:tx:MAX',
2431     'DEF:inc_min_raw={file}:rx:MIN',
2432     'DEF:inc_avg_raw={file}:rx:AVERAGE',
2433     'DEF:inc_max_raw={file}:rx:MAX',
2434     'CDEF:out_min=out_min_raw,8,*',
2435     'CDEF:out_avg=out_avg_raw,8,*',
2436     'CDEF:out_max=out_max_raw,8,*',
2437     'CDEF:inc_min=inc_min_raw,8,*',
2438     'CDEF:inc_avg=inc_avg_raw,8,*',
2439     'CDEF:inc_max=inc_max_raw,8,*',
2440     'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
2441     'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
2442     'CDEF:sample_len_raw=mytime,PREV(mytime),-',
2443     'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
2444     'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
2445     'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
2446     'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
2447     'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
2448     "AREA:out_avg#$HalfGreen",
2449     "AREA:inc_avg#$HalfBlue",
2450     "AREA:overlap#$HalfBlueGreen",
2451     "LINE1:out_avg#$FullGreen:Outgoing",
2452     'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
2453     'GPRINT:out_max:MAX:%5.1lf%s Max,',
2454     'GPRINT:out_avg:LAST:%5.1lf%s Last',
2455     'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
2456     "LINE1:inc_avg#$FullBlue:Incoming",
2457     #'GPRINT:inc_min:MIN:%5.1lf %s Min,',
2458     'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
2459     'GPRINT:inc_max:MAX:%5.1lf%s Max,',
2460     'GPRINT:inc_avg:LAST:%5.1lf%s Last',
2461     'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
2462     ],
2463     cpufreq => [
2464     'DEF:cpufreq_avg={file}:value:AVERAGE',
2465     'DEF:cpufreq_min={file}:value:MIN',
2466     'DEF:cpufreq_max={file}:value:MAX',
2467     "AREA:cpufreq_max#$HalfBlue",
2468     "AREA:cpufreq_min#$Canvas",
2469     "LINE1:cpufreq_avg#$FullBlue:Frequency",
2470     'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
2471     'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
2472     'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
2473     'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l'
2474     ],
2475     multimeter => [
2476     'DEF:multimeter_avg={file}:value:AVERAGE',
2477     'DEF:multimeter_min={file}:value:MIN',
2478     'DEF:multimeter_max={file}:value:MAX',
2479     "AREA:multimeter_max#$HalfBlue",
2480     "AREA:multimeter_min#$Canvas",
2481     "LINE1:multimeter_avg#$FullBlue:Multimeter",
2482     'GPRINT:multimeter_min:MIN:%4.1lf Min,',
2483     'GPRINT:multimeter_avg:AVERAGE:%4.1lf Average,',
2484     'GPRINT:multimeter_max:MAX:%4.1lf Max,',
2485     'GPRINT:multimeter_avg:LAST:%4.1lf Last\l'
2486     ],
2487     users => ['-v', 'Users',
2488     'DEF:users_avg={file}:users:AVERAGE',
2489     'DEF:users_min={file}:users:MIN',
2490     'DEF:users_max={file}:users:MAX',
2491     "AREA:users_max#$HalfBlue",
2492     "AREA:users_min#$Canvas",
2493     "LINE1:users_avg#$FullBlue:Users",
2494     'GPRINT:users_min:MIN:%4.1lf Min,',
2495     'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
2496     'GPRINT:users_max:MAX:%4.1lf Max,',
2497     'GPRINT:users_avg:LAST:%4.1lf Last\l'
2498     ],
2499     voltage => ['-v', 'Voltage',
2500     'DEF:avg={file}:value:AVERAGE',
2501     'DEF:min={file}:value:MIN',
2502     'DEF:max={file}:value:MAX',
2503     "AREA:max#$HalfBlue",
2504     "AREA:min#$Canvas",
2505     "LINE1:avg#$FullBlue:Voltage",
2506     'GPRINT:min:MIN:%5.1lf%sV Min,',
2507     'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
2508     'GPRINT:max:MAX:%5.1lf%sV Max,',
2509     'GPRINT:avg:LAST:%5.1lf%sV Last\l'
2510     ],
2511     vs_threads => [
2512     "DEF:avg={file}:value:AVERAGE",
2513     "DEF:min={file}:value:MIN",
2514     "DEF:max={file}:value:MAX",
2515     "AREA:max#$HalfBlue",
2516     "AREA:min#$Canvas",
2517     "LINE1:avg#$FullBlue:Threads",
2518     'GPRINT:min:MIN:%5.1lf Min,',
2519     'GPRINT:avg:AVERAGE:%5.1lf Avg.,',
2520     'GPRINT:max:MAX:%5.1lf Max,',
2521     'GPRINT:avg:LAST:%5.1lf Last\l',
2522     ],
2523     vs_memory => ['-b', '1024', '-v', 'Bytes',
2524     "DEF:avg={file}:value:AVERAGE",
2525     "DEF:min={file}:value:MIN",
2526     "DEF:max={file}:value:MAX",
2527     "AREA:max#$HalfBlue",
2528     "AREA:min#$Canvas",
2529     "LINE1:avg#$FullBlue:",
2530     'GPRINT:min:MIN:%5.1lf%sbytes Min,',
2531     'GPRINT:avg:AVERAGE:%5.1lf%sbytes Avg.,',
2532     'GPRINT:max:MAX:%5.1lf%sbytes Max,',
2533     'GPRINT:avg:LAST:%5.1lf%sbytes Last\l',
2534     ],
2535     vs_processes => [
2536     "DEF:avg={file}:value:AVERAGE",
2537     "DEF:min={file}:value:MIN",
2538     "DEF:max={file}:value:MAX",
2539     "AREA:max#$HalfBlue",
2540     "AREA:min#$Canvas",
2541     "LINE1:avg#$FullBlue:Processes",
2542     'GPRINT:min:MIN:%5.1lf Min,',
2543     'GPRINT:avg:AVERAGE:%5.1lf Avg.,',
2544     'GPRINT:max:MAX:%5.1lf Max,',
2545     'GPRINT:avg:LAST:%5.1lf Last\l',
2546     ],
2547     vmpage_number => ['-v', 'Pages',
2548     'DEF:avg={file}:value:AVERAGE',
2549     'DEF:min={file}:value:MIN',
2550     'DEF:max={file}:value:MAX',
2551     "AREA:max#$HalfBlue",
2552     "AREA:min#$Canvas",
2553     "LINE1:avg#$FullBlue:Number",
2554     'GPRINT:min:MIN:%4.1lf Min,',
2555     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
2556     'GPRINT:max:MAX:%4.1lf Max,',
2557     'GPRINT:avg:LAST:%4.1lf Last\l'
2558     ],
2559     vmpage_faults => [
2560     "DEF:minf_avg={file}:minflt:AVERAGE",
2561     "DEF:minf_min={file}:minflt:MIN",
2562     "DEF:minf_max={file}:minflt:MAX",
2563     "DEF:majf_avg={file}:majflt:AVERAGE",
2564     "DEF:majf_min={file}:majflt:MIN",
2565     "DEF:majf_max={file}:majflt:MAX",
2566     'CDEF:overlap=majf_avg,minf_avg,GT,minf_avg,majf_avg,IF',
2567     "AREA:majf_avg#$HalfGreen",
2568     "AREA:minf_avg#$HalfBlue",
2569     "AREA:overlap#$HalfBlueGreen",
2570     "LINE1:majf_avg#$FullGreen:Major",
2571     'GPRINT:majf_min:MIN:%5.1lf%s Min,',
2572     'GPRINT:majf_avg:AVERAGE:%5.1lf%s Avg,',
2573     'GPRINT:majf_max:MAX:%5.1lf%s Max,',
2574     'GPRINT:majf_avg:LAST:%5.1lf%s Last\l',
2575     "LINE1:minf_avg#$FullBlue:Minor",
2576     'GPRINT:minf_min:MIN:%5.1lf%s Min,',
2577     'GPRINT:minf_avg:AVERAGE:%5.1lf%s Avg,',
2578     'GPRINT:minf_max:MAX:%5.1lf%s Max,',
2579     'GPRINT:minf_avg:LAST:%5.1lf%s Last\l'
2580     ],
2581     vmpage_io => [
2582     "DEF:rpag_avg={file}:in:AVERAGE",
2583     "DEF:rpag_min={file}:in:MIN",
2584     "DEF:rpag_max={file}:in:MAX",
2585     "DEF:wpag_avg={file}:out:AVERAGE",
2586     "DEF:wpag_min={file}:out:MIN",
2587     "DEF:wpag_max={file}:out:MAX",
2588     'CDEF:overlap=wpag_avg,rpag_avg,GT,rpag_avg,wpag_avg,IF',
2589     "AREA:wpag_avg#$HalfGreen",
2590     "AREA:rpag_avg#$HalfBlue",
2591     "AREA:overlap#$HalfBlueGreen",
2592     "LINE1:wpag_avg#$FullGreen:OUT",
2593     'GPRINT:wpag_min:MIN:%5.1lf%s Min,',
2594     'GPRINT:wpag_avg:AVERAGE:%5.1lf%s Avg,',
2595     'GPRINT:wpag_max:MAX:%5.1lf%s Max,',
2596     'GPRINT:wpag_avg:LAST:%5.1lf%s Last\l',
2597     "LINE1:rpag_avg#$FullBlue:IN ",
2598     'GPRINT:rpag_min:MIN:%5.1lf%s Min,',
2599     'GPRINT:rpag_avg:AVERAGE:%5.1lf%s Avg,',
2600     'GPRINT:rpag_max:MAX:%5.1lf%s Max,',
2601     'GPRINT:rpag_avg:LAST:%5.1lf%s Last\l'
2602     ],
2603     vmpage_action => ['-v', 'Pages',
2604     'DEF:avg={file}:value:AVERAGE',
2605     'DEF:min={file}:value:MIN',
2606     'DEF:max={file}:value:MAX',
2607     "AREA:max#$HalfBlue",
2608     "AREA:min#$Canvas",
2609     "LINE1:avg#$FullBlue:Number",
2610     'GPRINT:min:MIN:%4.1lf Min,',
2611     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
2612     'GPRINT:max:MAX:%4.1lf Max,',
2613     'GPRINT:avg:LAST:%4.1lf Last\l'
2614     ],
2615     virt_cpu_total => ['-v', 'Milliseconds',
2616     'DEF:avg_raw={file}:ns:AVERAGE',
2617     'DEF:min_raw={file}:ns:MIN',
2618     'DEF:max_raw={file}:ns:MAX',
2619     'CDEF:avg=avg_raw,1000000,/',
2620     'CDEF:min=min_raw,1000000,/',
2621     'CDEF:max=max_raw,1000000,/',
2622     "AREA:avg#$HalfBlue",
2623     "LINE1:avg#$FullBlue:CPU time",
2624     'GPRINT:min:MIN:%4.1lf Min,',
2625     'GPRINT:avg:AVERAGE:%4.1lf Avg,',
2626     'GPRINT:max:MAX:%4.1lf Max,',
2627     'GPRINT:avg:LAST:%4.1lf Last\l'
2628     ],
2629   };
2630   $GraphDefs->{'if_multicast'} = $GraphDefs->{'ipt_packets'};
2631   $GraphDefs->{'if_tx_errors'} = $GraphDefs->{'if_rx_errors'};
2632   $GraphDefs->{'dns_qtype'} = $GraphDefs->{'dns_opcode'};
2633   $GraphDefs->{'dns_rcode'} = $GraphDefs->{'dns_opcode'};
2634   $GraphDefs->{'vmpage_io-memory'} = $GraphDefs->{'vmpage_io'};
2635   $GraphDefs->{'vmpage_io-swap'} = $GraphDefs->{'vmpage_io'};
2636   $GraphDefs->{'virt_cpu_total'} = $GraphDefs->{'virt_cpu_total'};
2637
2638   $MetaGraphDefs->{'cpu'} = \&meta_graph_cpu;
2639   $MetaGraphDefs->{'dns_qtype'} = \&meta_graph_dns;
2640   $MetaGraphDefs->{'dns_rcode'} = \&meta_graph_dns;
2641   $MetaGraphDefs->{'if_rx_errors'} = \&meta_graph_if_rx_errors;
2642   $MetaGraphDefs->{'if_tx_errors'} = \&meta_graph_if_rx_errors;
2643   $MetaGraphDefs->{'memory'} = \&meta_graph_memory;
2644   $MetaGraphDefs->{'nfs_procedure'} = \&meta_graph_nfs_procedure;
2645   $MetaGraphDefs->{'ps_state'} = \&meta_graph_ps_state;
2646   $MetaGraphDefs->{'swap'} = \&meta_graph_swap;
2647   $MetaGraphDefs->{'mysql_commands'} = \&meta_graph_mysql_commands;
2648   $MetaGraphDefs->{'mysql_handler'} = \&meta_graph_mysql_commands;
2649   $MetaGraphDefs->{'tcp_connections'} = \&meta_graph_tcp_connections;
2650   $MetaGraphDefs->{'vmpage_number'} = \&meta_graph_vmpage_number;
2651   $MetaGraphDefs->{'vmpage_action'} = \&meta_graph_vmpage_action;
2652 } # load_graph_definitions
2653
2654 sub meta_graph_generic_stack
2655 {
2656   confess ("Wrong number of arguments") if (@_ != 2);
2657
2658   my $opts = shift;
2659   my $sources = shift;
2660   my $i;
2661
2662   my $timespan_str = _get_param_timespan ();
2663   my $timespan_int = (-1) * $ValidTimespan->{$timespan_str};
2664
2665   $opts->{'title'} ||= 'Unknown title';
2666   $opts->{'rrd_opts'} ||= [];
2667   $opts->{'colors'} ||= {};
2668
2669   my @cmd = ('-', '-a', 'PNG', '-s', $timespan_int,
2670     '-t', $opts->{'title'} || 'Unknown title',
2671     @RRDDefaultArgs, @{$opts->{'rrd_opts'}});
2672
2673   my $max_inst_name = 0;
2674   my @vnames = ();
2675
2676   for ($i = 0; $i < @$sources; $i++)
2677   {
2678     my $tmp = $sources->[$i]->{'name'};
2679     $tmp =~ tr/A-Za-z0-9\-_/_/c;
2680     $vnames[$i] = $i . $tmp;
2681   }
2682
2683   for ($i = 0; $i < @$sources; $i++)
2684   {
2685     my $inst_data = $sources->[$i];
2686     my $inst_name = $inst_data->{'name'} || confess;
2687     my $file = $inst_data->{'file'} || confess;
2688     my $vname = $vnames[$i];
2689
2690     if (length ($inst_name) > $max_inst_name)
2691     {
2692       $max_inst_name = length ($inst_name);
2693     }
2694
2695     confess ("No such file: $file") if (!-e $file);
2696
2697     push (@cmd,
2698       qq#DEF:${vname}_min=$file:value:MIN#,
2699       qq#DEF:${vname}_avg=$file:value:AVERAGE#,
2700       qq#DEF:${vname}_max=$file:value:MAX#,
2701       qq#CDEF:${vname}_nnl=${vname}_avg,UN,0,${vname}_avg,IF#);
2702   }
2703
2704   {
2705     my $vname = $vnames[@vnames - 1];
2706
2707     push (@cmd, qq#CDEF:${vname}_stk=${vname}_nnl#);
2708   }
2709   for (my $i = 1; $i < @$sources; $i++)
2710   {
2711     my $vname0 = $vnames[@vnames - ($i + 1)];
2712     my $vname1 = $vnames[@vnames - $i];
2713
2714     push (@cmd, qq#CDEF:${vname0}_stk=${vname0}_nnl,${vname1}_stk,+#);
2715   }
2716
2717   for (my $i = 0; $i < @$sources; $i++)
2718   {
2719     my $inst_data = $sources->[$i];
2720     my $inst_name = $inst_data->{'name'};
2721
2722     my $vname = $vnames[$i];
2723
2724     my $legend = sprintf ('%-*s', $max_inst_name, $inst_name);
2725
2726     my $line_color;
2727     my $area_color;
2728
2729     my $number_format = $opts->{'number_format'} || '%6.1lf';
2730
2731     if (exists ($opts->{'colors'}{$inst_name}))
2732     {
2733       $line_color = $opts->{'colors'}{$inst_name};
2734       $area_color = _string_to_color ($line_color);
2735     }
2736     else
2737     {
2738       $area_color = _get_random_color ();
2739       $line_color = _color_to_string ($area_color);
2740     }
2741     $area_color = _color_to_string (_get_faded_color ($area_color));
2742
2743     push (@cmd, qq(AREA:${vname}_stk#$area_color),
2744       qq(LINE1:${vname}_stk#$line_color:$legend),
2745       qq(GPRINT:${vname}_min:MIN:$number_format Min,),
2746       qq(GPRINT:${vname}_avg:AVERAGE:$number_format Avg,),
2747       qq(GPRINT:${vname}_max:MAX:$number_format Max,),
2748       qq(GPRINT:${vname}_avg:LAST:$number_format Last\\l),
2749     );
2750   }
2751
2752   RRDs::graph (@cmd);
2753   if (my $errmsg = RRDs::error ())
2754   {
2755     confess ("RRDs::graph: $errmsg");
2756   }
2757 } # meta_graph_generic_stack
2758
2759 sub meta_graph_cpu
2760 {
2761   confess ("Wrong number of arguments") if (@_ != 5);
2762
2763   my $host = shift;
2764   my $plugin = shift;
2765   my $plugin_instance = shift;
2766   my $type = shift;
2767   my $type_instances = shift;
2768
2769   my $opts = {};
2770   my $sources = [];
2771
2772   $opts->{'title'} = "$host/$plugin"
2773   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
2774
2775   $opts->{'rrd_opts'} = ['-v', 'Percent'];
2776
2777   my @files = ();
2778
2779   $opts->{'colors'} =
2780   {
2781     'idle'      => 'ffffff',
2782     'nice'      => '00e000',
2783     'user'      => '0000ff',
2784     'wait'      => 'ffb000',
2785     'system'    => 'ff0000',
2786     'softirq'   => 'ff00ff',
2787     'interrupt' => 'a000a0',
2788     'steal'     => '000000'
2789   };
2790
2791   _custom_sort_arrayref ($type_instances,
2792     [qw(idle nice user wait system softirq interrupt steal)]);
2793
2794   for (@$type_instances)
2795   {
2796     my $inst = $_;
2797     my $file = '';
2798     my $title = $opts->{'title'};
2799
2800     for (@DataDirs)
2801     {
2802       if (-e "$_/$title-$inst.rrd")
2803       {
2804         $file = "$_/$title-$inst.rrd";
2805         last;
2806       }
2807     }
2808     confess ("No file found for $title") if ($file eq '');
2809
2810     push (@$sources,
2811       {
2812         name => $inst,
2813         file => $file
2814       }
2815     );
2816   } # for (@$type_instances)
2817
2818   return (meta_graph_generic_stack ($opts, $sources));
2819 } # meta_graph_cpu
2820
2821 sub meta_graph_dns
2822 {
2823   confess ("Wrong number of arguments") if (@_ != 5);
2824
2825   my $host = shift;
2826   my $plugin = shift;
2827   my $plugin_instance = shift;
2828   my $type = shift;
2829   my $type_instances = shift;
2830
2831   my $opts = {};
2832   my $sources = [];
2833
2834   $opts->{'title'} = "$host/$plugin"
2835   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
2836
2837   $opts->{'rrd_opts'} = ['-v', 'Queries/s'];
2838
2839   my @files = ();
2840
2841   @$type_instances = sort @$type_instances;
2842
2843   $opts->{'colors'} = _get_n_colors ($type_instances);
2844
2845   for (@$type_instances)
2846   {
2847     my $inst = $_;
2848     my $file = '';
2849     my $title = $opts->{'title'};
2850
2851     for (@DataDirs)
2852     {
2853       if (-e "$_/$title-$inst.rrd")
2854       {
2855         $file = "$_/$title-$inst.rrd";
2856         last;
2857       }
2858     }
2859     confess ("No file found for $title") if ($file eq '');
2860
2861     push (@$sources,
2862       {
2863         name => $inst,
2864         file => $file
2865       }
2866     );
2867   } # for (@$type_instances)
2868
2869   return (meta_graph_generic_stack ($opts, $sources));
2870 } # meta_graph_dns
2871
2872 sub meta_graph_memory
2873 {
2874   confess ("Wrong number of arguments") if (@_ != 5);
2875
2876   my $host = shift;
2877   my $plugin = shift;
2878   my $plugin_instance = shift;
2879   my $type = shift;
2880   my $type_instances = shift;
2881
2882   my $opts = {};
2883   my $sources = [];
2884
2885   $opts->{'title'} = "$host/$plugin"
2886   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
2887   $opts->{'number_format'} = '%5.1lf%s';
2888
2889   $opts->{'rrd_opts'} = ['-b', '1024', '-v', 'Bytes'];
2890
2891   my @files = ();
2892
2893   $opts->{'colors'} =
2894   {
2895     'free'     => '00e000',
2896     'cached'   => '0000ff',
2897     'buffered' => 'ffb000',
2898     'used'     => 'ff0000'
2899   };
2900
2901   _custom_sort_arrayref ($type_instances,
2902     [qw(free cached buffered used)]);
2903
2904   for (@$type_instances)
2905   {
2906     my $inst = $_;
2907     my $file = '';
2908     my $title = $opts->{'title'};
2909
2910     for (@DataDirs)
2911     {
2912       if (-e "$_/$title-$inst.rrd")
2913       {
2914         $file = "$_/$title-$inst.rrd";
2915         last;
2916       }
2917     }
2918     confess ("No file found for $title") if ($file eq '');
2919
2920     push (@$sources,
2921       {
2922         name => $inst,
2923         file => $file
2924       }
2925     );
2926   } # for (@$type_instances)
2927
2928   return (meta_graph_generic_stack ($opts, $sources));
2929 } # meta_graph_memory
2930
2931 sub meta_graph_if_rx_errors
2932 {
2933   confess ("Wrong number of arguments") if (@_ != 5);
2934
2935   my $host = shift;
2936   my $plugin = shift;
2937   my $plugin_instance = shift;
2938   my $type = shift;
2939   my $type_instances = shift;
2940
2941   my $opts = {};
2942   my $sources = [];
2943
2944   $opts->{'title'} = "$host/$plugin"
2945   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
2946   $opts->{'number_format'} = '%5.2lf';
2947   $opts->{'rrd_opts'} = ['-v', 'Errors/s'];
2948
2949   my @files = ();
2950
2951   for (sort @$type_instances)
2952   {
2953     my $inst = $_;
2954     my $file = '';
2955     my $title = $opts->{'title'};
2956
2957     for (@DataDirs)
2958     {
2959       if (-e "$_/$title-$inst.rrd")
2960       {
2961         $file = "$_/$title-$inst.rrd";
2962         last;
2963       }
2964     }
2965     confess ("No file found for $title") if ($file eq '');
2966
2967     push (@$sources,
2968       {
2969         name => $inst,
2970         file => $file
2971       }
2972     );
2973   } # for (@$type_instances)
2974
2975   return (meta_graph_generic_stack ($opts, $sources));
2976 } # meta_graph_if_rx_errors
2977
2978 sub meta_graph_mysql_commands
2979 {
2980   confess ("Wrong number of arguments") if (@_ != 5);
2981
2982   my $host = shift;
2983   my $plugin = shift;
2984   my $plugin_instance = shift;
2985   my $type = shift;
2986   my $type_instances = shift;
2987
2988   my $opts = {};
2989   my $sources = [];
2990
2991   $opts->{'title'} = "$host/$plugin"
2992   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
2993   $opts->{'number_format'} = '%5.2lf';
2994
2995   my @files = ();
2996
2997   for (sort @$type_instances)
2998   {
2999     my $inst = $_;
3000     my $file = '';
3001     my $title = $opts->{'title'};
3002
3003     for (@DataDirs)
3004     {
3005       if (-e "$_/$title-$inst.rrd")
3006       {
3007         $file = "$_/$title-$inst.rrd";
3008         last;
3009       }
3010     }
3011     confess ("No file found for $title") if ($file eq '');
3012
3013     push (@$sources,
3014       {
3015         name => $inst,
3016         file => $file
3017       }
3018     );
3019   } # for (@$type_instances)
3020
3021   return (meta_graph_generic_stack ($opts, $sources));
3022 } # meta_graph_mysql_commands
3023
3024 sub meta_graph_nfs_procedure
3025 {
3026   confess ("Wrong number of arguments") if (@_ != 5);
3027
3028   my $host = shift;
3029   my $plugin = shift;
3030   my $plugin_instance = shift;
3031   my $type = shift;
3032   my $type_instances = shift;
3033
3034   my $opts = {};
3035   my $sources = [];
3036
3037   $opts->{'title'} = "$host/$plugin"
3038   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3039   $opts->{'number_format'} = '%5.1lf%s';
3040
3041   my @files = ();
3042
3043   for (sort @$type_instances)
3044   {
3045     my $inst = $_;
3046     my $file = '';
3047     my $title = $opts->{'title'};
3048
3049     for (@DataDirs)
3050     {
3051       if (-e "$_/$title-$inst.rrd")
3052       {
3053         $file = "$_/$title-$inst.rrd";
3054         last;
3055       }
3056     }
3057     confess ("No file found for $title") if ($file eq '');
3058
3059     push (@$sources,
3060       {
3061         name => $inst,
3062         file => $file
3063       }
3064     );
3065   } # for (@$type_instances)
3066
3067   return (meta_graph_generic_stack ($opts, $sources));
3068 } # meta_graph_nfs_procedure
3069
3070 sub meta_graph_ps_state
3071 {
3072   confess ("Wrong number of arguments") if (@_ != 5);
3073
3074   my $host = shift;
3075   my $plugin = shift;
3076   my $plugin_instance = shift;
3077   my $type = shift;
3078   my $type_instances = shift;
3079
3080   my $opts = {};
3081   my $sources = [];
3082
3083   $opts->{'title'} = "$host/$plugin"
3084   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3085   $opts->{'rrd_opts'} = ['-v', 'Processes'];
3086
3087   my @files = ();
3088
3089   $opts->{'colors'} =
3090   {
3091     'Running'      => '00e000',
3092     'Sleeping'  => '0000ff',
3093     'Paging'      => 'ffb000',
3094     'Zombies'   => 'ff0000',
3095     'Blocked'   => 'ff00ff',
3096     'Stopped' => 'a000a0'
3097   };
3098
3099   _custom_sort_arrayref ($type_instances,
3100     [qw(paging blocked zombies stopped running sleeping)]);
3101
3102   for (@$type_instances)
3103   {
3104     my $inst = $_;
3105     my $file = '';
3106     my $title = $opts->{'title'};
3107
3108     for (@DataDirs)
3109     {
3110       if (-e "$_/$title-$inst.rrd")
3111       {
3112         $file = "$_/$title-$inst.rrd";
3113         last;
3114       }
3115     }
3116     confess ("No file found for $title") if ($file eq '');
3117
3118     push (@$sources,
3119       {
3120         name => ucfirst ($inst),
3121         file => $file
3122       }
3123     );
3124   } # for (@$type_instances)
3125
3126   return (meta_graph_generic_stack ($opts, $sources));
3127 } # meta_graph_ps_state
3128
3129 sub meta_graph_swap
3130 {
3131   confess ("Wrong number of arguments") if (@_ != 5);
3132
3133   my $host = shift;
3134   my $plugin = shift;
3135   my $plugin_instance = shift;
3136   my $type = shift;
3137   my $type_instances = shift;
3138
3139   my $opts = {};
3140   my $sources = [];
3141
3142   $opts->{'title'} = "$host/$plugin"
3143   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3144   $opts->{'number_format'} = '%5.1lf%s';
3145   $opts->{'rrd_opts'} = ['-v', 'Bytes'];
3146
3147   my @files = ();
3148
3149   $opts->{'colors'} =
3150   {
3151     'Free'     => '00e000',
3152     'Cached'   => '0000ff',
3153     'Reserved' => 'ffb000',
3154     'Used'     => 'ff0000'
3155   };
3156
3157   _custom_sort_arrayref ($type_instances,
3158     [qw(free cached reserved used)]);
3159
3160   for (@$type_instances)
3161   {
3162     my $inst = $_;
3163     my $file = '';
3164     my $title = $opts->{'title'};
3165
3166     for (@DataDirs)
3167     {
3168       if (-e "$_/$title-$inst.rrd")
3169       {
3170         $file = "$_/$title-$inst.rrd";
3171         last;
3172       }
3173     }
3174     confess ("No file found for $title") if ($file eq '');
3175
3176     push (@$sources,
3177       {
3178         name => ucfirst ($inst),
3179         file => $file
3180       }
3181     );
3182   } # for (@$type_instances)
3183
3184   return (meta_graph_generic_stack ($opts, $sources));
3185 } # meta_graph_swap
3186
3187 sub meta_graph_tcp_connections
3188 {
3189   confess ("Wrong number of arguments") if (@_ != 5);
3190
3191   my $host = shift;
3192   my $plugin = shift;
3193   my $plugin_instance = shift;
3194   my $type = shift;
3195   my $type_instances = shift;
3196
3197   my $opts = {};
3198   my $sources = [];
3199
3200   $opts->{'title'} = "$host/$plugin"
3201   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3202   $opts->{'number_format'} = '%6.2lf';
3203
3204   $opts->{'rrd_opts'} = ['-v', 'Connections'];
3205
3206   my @files = ();
3207
3208   $opts->{'colors'} =
3209   {
3210     ESTABLISHED   => '00e000',
3211     SYN_SENT      => '00e0ff',
3212     SYN_RECV      => '00e0a0',
3213     FIN_WAIT1     => 'f000f0',
3214     FIN_WAIT2     => 'f000a0',
3215     TIME_WAIT     => 'ffb000',
3216     CLOSE         => '0000f0',
3217     CLOSE_WAIT    => '0000a0',
3218     LAST_ACK      => '000080',
3219     LISTEN        => 'ff0000',
3220     CLOSING       => '000000'
3221   };
3222
3223   _custom_sort_arrayref ($type_instances,
3224     [reverse qw(ESTABLISHED SYN_SENT SYN_RECV FIN_WAIT1 FIN_WAIT2 TIME_WAIT CLOSE
3225     CLOSE_WAIT LAST_ACK CLOSING LISTEN)]);
3226
3227   for (@$type_instances)
3228   {
3229     my $inst = $_;
3230     my $file = '';
3231     my $title = $opts->{'title'};
3232
3233     for (@DataDirs)
3234     {
3235       if (-e "$_/$title-$inst.rrd")
3236       {
3237         $file = "$_/$title-$inst.rrd";
3238         last;
3239       }
3240     }
3241     confess ("No file found for $title") if ($file eq '');
3242
3243     push (@$sources,
3244       {
3245         name => $inst,
3246         file => $file
3247       }
3248     );
3249   } # for (@$type_instances)
3250
3251   return (meta_graph_generic_stack ($opts, $sources));
3252 } # meta_graph_tcp_connections
3253
3254 sub meta_graph_vmpage_number
3255 {
3256   confess ("Wrong number of arguments") if (@_ != 5);
3257
3258   my $host = shift;
3259   my $plugin = shift;
3260   my $plugin_instance = shift;
3261   my $type = shift;
3262   my $type_instances = shift;
3263
3264   my $opts = {};
3265   my $sources = [];
3266
3267   $opts->{'title'} = "$host/$plugin"
3268   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3269   $opts->{'number_format'} = '%6.2lf';
3270
3271   $opts->{'rrd_opts'} = ['-v', 'Pages'];
3272
3273   my @files = ();
3274
3275   $opts->{'colors'} =
3276   {
3277     anon_pages    => '00e000',
3278     bounce        => '00e0ff',
3279     dirty         => '00e0a0',
3280     file_pages    => 'f000f0',
3281     mapped        => 'f000a0',
3282     page_table_pages      => 'ffb000',
3283     slab          => '0000f0',
3284     unstable      => '0000a0',
3285     writeback     => 'ff0000',
3286   };
3287
3288   _custom_sort_arrayref ($type_instances,
3289     [reverse qw(anon_pages bounce dirty file_pages mapped page_table_pages slab unstable writeback)]);
3290
3291   for (@$type_instances)
3292   {
3293     my $inst = $_;
3294     my $file = '';
3295     my $title = $opts->{'title'};
3296
3297     for (@DataDirs)
3298     {
3299       if (-e "$_/$title-$inst.rrd")
3300       {
3301         $file = "$_/$title-$inst.rrd";
3302         last;
3303       }
3304     }
3305     confess ("No file found for $title") if ($file eq '');
3306
3307     push (@$sources,
3308       {
3309         name => $inst,
3310         file => $file
3311       }
3312     );
3313   } # for (@$type_instances)
3314
3315   return (meta_graph_generic_stack ($opts, $sources));
3316 } # meta_graph_vmpage_number
3317
3318 sub meta_graph_vmpage_action
3319 {
3320   confess ("Wrong number of arguments") if (@_ != 5);
3321
3322   my $host = shift;
3323   my $plugin = shift;
3324   my $plugin_instance = shift;
3325   my $type = shift;
3326   my $type_instances = shift;
3327
3328   my $opts = {};
3329   my $sources = [];
3330
3331   $opts->{'title'} = "$host/$plugin"
3332   . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
3333   $opts->{'number_format'} = '%6.2lf';
3334
3335   $opts->{'rrd_opts'} = ['-v', 'Pages'];
3336
3337   my @files = ();
3338
3339   $opts->{'colors'} =
3340   {
3341     activate      => '00e000',
3342     deactivate    => '00e0ff',
3343     free          => '00e0a0',
3344     alloc         => 'f000f0',
3345     refill        => 'f000a0',
3346     scan_direct   => 'ffb000',
3347     scan_kswapd   => '0000f0',
3348     steal         => '0000a0',
3349   };
3350
3351   _custom_sort_arrayref ($type_instances,
3352     [reverse qw(activate deactivate alloc free refill scan_direct scan_kswapd steal)]);
3353
3354   for (@$type_instances)
3355   {
3356     my $inst = $_;
3357     my $file = '';
3358     my $title = $opts->{'title'};
3359
3360     for (@DataDirs)
3361     {
3362       if (-e "$_/$title-$inst.rrd")
3363       {
3364         $file = "$_/$title-$inst.rrd";
3365         last;
3366       }
3367     }
3368     confess ("No file found for $title") if ($file eq '');
3369
3370     push (@$sources,
3371       {
3372         name => $inst,
3373         file => $file
3374       }
3375     );
3376   } # for (@$type_instances)
3377
3378   return (meta_graph_generic_stack ($opts, $sources));
3379 } # meta_graph_vmpage_action
3380 # vim: shiftwidth=2:softtabstop=2:tabstop=8