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