+
+sub meta_graph_generic_stack
+{
+ confess ("Wrong number of arguments") if (@_ != 2);
+
+ my $opts = shift;
+ my $sources = shift;
+ my $i;
+
+ my $timespan_str = _get_param_timespan ();
+ my $timespan_int = (-1) * $ValidTimespan->{$timespan_str};
+
+ $opts->{'title'} ||= 'Unknown title';
+ $opts->{'rrd_opts'} ||= [];
+ $opts->{'colors'} ||= {};
+
+ my @cmd = ('-', '-a', 'PNG', '-s', $timespan_int,
+ '-t', $opts->{'title'} || 'Unknown title',
+ @RRDDefaultArgs, @{$opts->{'rrd_opts'}});
+
+ my $max_inst_name = 0;
+ my @vnames = ();
+
+ for ($i = 0; $i < @$sources; $i++)
+ {
+ my $tmp = $sources->[$i]->{'name'};
+ $tmp =~ tr/A-Za-z0-9\-_/_/c;
+ $vnames[$i] = $i . $tmp;
+ }
+
+ for ($i = 0; $i < @$sources; $i++)
+ {
+ my $inst_data = $sources->[$i];
+ my $inst_name = $inst_data->{'name'} || confess;
+ my $file = $inst_data->{'file'} || confess;
+ my $vname = $vnames[$i];
+
+ if (length ($inst_name) > $max_inst_name)
+ {
+ $max_inst_name = length ($inst_name);
+ }
+
+ confess ("No such file: $file") if (!-e $file);
+
+ push (@cmd,
+ qq#DEF:${vname}_min=$file:value:MIN#,
+ qq#DEF:${vname}_avg=$file:value:AVERAGE#,
+ qq#DEF:${vname}_max=$file:value:MAX#,
+ qq#CDEF:${vname}_nnl=${vname}_avg,UN,0,${vname}_avg,IF#);
+ }
+
+ {
+ my $vname = $vnames[@vnames - 1];
+
+ push (@cmd, qq#CDEF:${vname}_stk=${vname}_nnl#);
+ }
+ for (my $i = 1; $i < @$sources; $i++)
+ {
+ my $vname0 = $vnames[@vnames - ($i + 1)];
+ my $vname1 = $vnames[@vnames - $i];
+
+ push (@cmd, qq#CDEF:${vname0}_stk=${vname0}_nnl,${vname1}_stk,+#);
+ }
+
+ for (my $i = 0; $i < @$sources; $i++)
+ {
+ my $inst_data = $sources->[$i];
+ my $inst_name = $inst_data->{'name'};
+
+ my $vname = $vnames[$i];
+
+ my $legend = sprintf ('%-*s', $max_inst_name, $inst_name);
+
+ my $line_color;
+ my $area_color;
+
+ my $number_format = $opts->{'number_format'} || '%6.1lf';
+
+ if (exists ($opts->{'colors'}{$inst_name}))
+ {
+ $line_color = $opts->{'colors'}{$inst_name};
+ $area_color = _string_to_color ($line_color);
+ }
+ else
+ {
+ $area_color = _get_random_color ();
+ $line_color = _color_to_string ($area_color);
+ }
+ $area_color = _color_to_string (_get_faded_color ($area_color));
+
+ push (@cmd, qq(AREA:${vname}_stk#$area_color),
+ qq(LINE1:${vname}_stk#$line_color:$legend),
+ qq(GPRINT:${vname}_min:MIN:$number_format Min,),
+ qq(GPRINT:${vname}_avg:AVERAGE:$number_format Avg,),
+ qq(GPRINT:${vname}_max:MAX:$number_format Max,),
+ qq(GPRINT:${vname}_avg:LAST:$number_format Last\\l),
+ );
+ }
+
+ RRDs::graph (@cmd);
+ if (my $errmsg = RRDs::error ())
+ {
+ confess ("RRDs::graph: $errmsg");
+ }
+} # meta_graph_generic_stack
+
+sub meta_graph_cpu
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+
+ $opts->{'rrd_opts'} = ['-v', 'Percent'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ 'idle' => 'ffffff',
+ 'nice' => '00e000',
+ 'user' => '0000ff',
+ 'wait' => 'ffb000',
+ 'system' => 'ff0000',
+ 'softirq' => 'ff00ff',
+ 'interrupt' => 'a000a0',
+ 'steal' => '000000'
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [qw(idle nice user wait system softirq interrupt steal)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_cpu
+
+sub meta_graph_df
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ my $prefix = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+
+ $opts->{'title'} = "Disk usage $prefix";
+
+ $opts->{'number_format'} = '%5.1lf%s';
+ $opts->{'rrd_opts'} = ['-l', 0, '-b', '1024', '-v', 'Bytes'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ 'used' => 'ff0000',
+ 'snap_normal_used' => 'c10640',
+ 'snap_reserve_used' => '820c81',
+ 'snap_reserved' => 'f15aef',
+ 'reserved' => 'ffb000',
+ 'free' => '00ff00',
+ 'sis_saved' => '00e0e0',
+ 'dedup_saved' => '00c1c1',
+ 'compression_saved' => '00a2a2'
+ };
+
+ # LVM uses LV names as type-instance; they should sort first
+ _custom_sort_arrayref ($type_instances,
+ [qw(compression_saved dedup_saved sis_saved free reserved snap_reserved
+ snap_reserve_used snap_normal_used used)], 1);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$prefix-$inst.rrd")
+ {
+ $file = "$_/$prefix-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $prefix") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_df
+
+sub meta_graph_dns
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+
+ $opts->{'rrd_opts'} = ['-v', 'Queries/s'];
+
+ my @files = ();
+
+ @$type_instances = sort @$type_instances;
+
+ $opts->{'colors'} = _get_n_colors ($type_instances);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_dns
+
+sub meta_graph_memory
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%5.1lf%s';
+
+ $opts->{'rrd_opts'} = ['-b', '1024', '-v', 'Bytes'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ 'free' => '00e000',
+ 'cached' => '0000ff',
+ 'buffered' => 'ffb000',
+ 'used' => 'ff0000'
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [qw(free cached buffered used)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_memory
+
+sub meta_graph_if_rx_errors
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%5.2lf';
+ $opts->{'rrd_opts'} = ['-v', 'Errors/s'];
+
+ my @files = ();
+
+ for (sort @$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_if_rx_errors
+
+sub meta_graph_mysql_commands
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%5.2lf';
+
+ my @files = ();
+
+ for (sort @$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_mysql_commands
+
+sub meta_graph_nfs_procedure
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%5.1lf%s';
+
+ my @files = ();
+
+ for (sort @$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_nfs_procedure
+
+sub meta_graph_ps_state
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'rrd_opts'} = ['-v', 'Processes'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ 'Running' => '00e000',
+ 'Sleeping' => '0000ff',
+ 'Paging' => 'ffb000',
+ 'Zombies' => 'ff0000',
+ 'Blocked' => 'ff00ff',
+ 'Stopped' => 'a000a0'
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [qw(paging blocked zombies stopped running sleeping)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => ucfirst ($inst),
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_ps_state
+
+sub meta_graph_swap
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%5.1lf%s';
+ $opts->{'rrd_opts'} = ['-v', 'Bytes'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ 'Free' => '00e000',
+ 'Cached' => '0000ff',
+ 'Reserved' => 'ffb000',
+ 'Used' => 'ff0000'
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [qw(free cached reserved used)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => ucfirst ($inst),
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_swap
+
+sub meta_graph_tcp_connections
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%6.2lf';
+
+ $opts->{'rrd_opts'} = ['-v', 'Connections'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ ESTABLISHED => '00e000',
+ SYN_SENT => '00e0ff',
+ SYN_RECV => '00e0a0',
+ FIN_WAIT1 => 'f000f0',
+ FIN_WAIT2 => 'f000a0',
+ TIME_WAIT => 'ffb000',
+ CLOSE => '0000f0',
+ CLOSE_WAIT => '0000a0',
+ LAST_ACK => '000080',
+ LISTEN => 'ff0000',
+ CLOSING => '000000'
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [reverse qw(ESTABLISHED SYN_SENT SYN_RECV FIN_WAIT1 FIN_WAIT2 TIME_WAIT CLOSE
+ CLOSE_WAIT LAST_ACK CLOSING LISTEN)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_tcp_connections
+
+sub meta_graph_vmpage_number
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%6.2lf';
+
+ $opts->{'rrd_opts'} = ['-v', 'Pages'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ anon_pages => '00e000',
+ bounce => '00e0ff',
+ dirty => '00e0a0',
+ file_pages => 'f000f0',
+ mapped => 'f000a0',
+ page_table_pages => 'ffb000',
+ slab => '0000f0',
+ unstable => '0000a0',
+ writeback => 'ff0000',
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [reverse qw(anon_pages bounce dirty file_pages mapped page_table_pages slab unstable writeback)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_vmpage_number
+
+sub meta_graph_vmpage_action
+{
+ confess ("Wrong number of arguments") if (@_ != 5);
+
+ my $host = shift;
+ my $plugin = shift;
+ my $plugin_instance = shift;
+ my $type = shift;
+ my $type_instances = shift;
+
+ my $opts = {};
+ my $sources = [];
+
+ $opts->{'title'} = "$host/$plugin"
+ . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+ $opts->{'number_format'} = '%6.2lf';
+
+ $opts->{'rrd_opts'} = ['-v', 'Pages'];
+
+ my @files = ();
+
+ $opts->{'colors'} =
+ {
+ activate => '00e000',
+ deactivate => '00e0ff',
+ free => '00e0a0',
+ alloc => 'f000f0',
+ refill => 'f000a0',
+ scan_direct => 'ffb000',
+ scan_kswapd => '0000f0',
+ steal => '0000a0',
+ };
+
+ _custom_sort_arrayref ($type_instances,
+ [reverse qw(activate deactivate alloc free refill scan_direct scan_kswapd steal)]);
+
+ for (@$type_instances)
+ {
+ my $inst = $_;
+ my $file = '';
+ my $title = $opts->{'title'};
+
+ for (@DataDirs)
+ {
+ if (-e "$_/$title-$inst.rrd")
+ {
+ $file = "$_/$title-$inst.rrd";
+ last;
+ }
+ }
+ confess ("No file found for $title") if ($file eq '');
+
+ push (@$sources,
+ {
+ name => $inst,
+ file => $file
+ }
+ );
+ } # for (@$type_instances)
+
+ return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_vmpage_action