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