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