From 25831ec7b1d3d36a7f2dac2baf9a47c8099deba4 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 26 Apr 2014 18:31:18 +0200 Subject: [PATCH] collection.cgi: Added support for df_complex types. --- contrib/collection.cgi | 76 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/contrib/collection.cgi b/contrib/collection.cgi index 1231ce8b..4b248dc1 100755 --- a/contrib/collection.cgi +++ b/contrib/collection.cgi @@ -528,6 +528,7 @@ sub _custom_sort_arrayref { my $array_ref = shift; my $array_sort = shift; + my $unknown_first = shift || 0; my %elements = map { $_ => 1 } (@$array_ref); splice (@$array_ref, 0); @@ -538,7 +539,12 @@ sub _custom_sort_arrayref push (@$array_ref, $_); delete ($elements{$_}); } - push (@$array_ref, sort (keys %elements)); + if ($unknown_first) { + unshift (@$array_ref, sort (keys %elements)); + } + else { + push (@$array_ref, sort (keys %elements)); + } } # _custom_sort_arrayref sub action_show_host @@ -2697,6 +2703,7 @@ sub load_graph_definitions $GraphDefs->{'virt_cpu_total'} = $GraphDefs->{'virt_cpu_total'}; $MetaGraphDefs->{'cpu'} = \&meta_graph_cpu; + $MetaGraphDefs->{'df_complex'} = \&meta_graph_df; $MetaGraphDefs->{'dns_qtype'} = \&meta_graph_dns; $MetaGraphDefs->{'dns_rcode'} = \&meta_graph_dns; $MetaGraphDefs->{'if_rx_errors'} = \&meta_graph_if_rx_errors; @@ -2879,6 +2886,73 @@ sub meta_graph_cpu 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'} = ['-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); -- 2.30.2