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