From 7d13d7a14278699dd5acbd9b1c94f99c270421af Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 4 Feb 2019 14:30:49 +0100 Subject: [PATCH] adapt cadvisor to new counter template --- .../exporters/cadvisor/mode/storage.pm | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/cloud/prometheus/exporters/cadvisor/mode/storage.pm b/cloud/prometheus/exporters/cadvisor/mode/storage.pm index b24830cec..14b96e8ee 100644 --- a/cloud/prometheus/exporters/cadvisor/mode/storage.pm +++ b/cloud/prometheus/exporters/cadvisor/mode/storage.pm @@ -30,15 +30,14 @@ my $instance_mode; sub custom_usage_perfdata { my ($self, %options) = @_; + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{label} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my $label = 'used'; my $value_perf = $self->{result_values}->{used}; if (defined($instance_mode->{option_results}->{free})) { $label = 'free'; $value_perf = $self->{result_values}->{free}; } - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{perf} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - $extra_label .= '_' . $self->{result_values}->{device} if (!defined($options{extra_instance_lvl2}) || $options{extra_instance_lvl2} != 0); my %total_options = (); if ($instance_mode->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; @@ -82,9 +81,9 @@ sub custom_usage_output { sub custom_usage_calc { my ($self, %options) = @_; + $self->{result_values}->{label} = $self->{instance}; $self->{result_values}->{container} = $options{new_datas}->{$self->{instance} . '_container'}; $self->{result_values}->{pod} = $options{new_datas}->{$self->{instance} . '_pod'}; - $self->{result_values}->{perf} = $options{new_datas}->{$self->{instance} . '_perf'}; $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_limit'}; $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; @@ -105,14 +104,18 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'containers', type => 3, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers storages usage are ok', - counters => [ { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages usage are ok' } ] }, + { name => 'containers', type => 3, cb_prefix_output => 'prefix_containers_output', cb_long_output => 'long_output', + message_multiple => 'All containers storages usage are ok', indent_long_output => ' ', + group => [ + { name => 'storage', display_long => 1, cb_prefix_output => 'prefix_storage_output', + message_multiple => 'All storages usage are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; $self->{maps_counters}->{storage} = [ { label => 'usage', set => { - key_values => [ { name => 'used' }, { name => 'limit' }, { name => 'container' }, { name => 'pod' }, - { name => 'perf' } ], + key_values => [ { name => 'used' }, { name => 'limit' }, { name => 'container' }, { name => 'pod' } ], closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), @@ -122,10 +125,22 @@ sub set_counters { ]; } +sub prefix_container_output { + my ($self, %options) = @_; + + return "Container '" . $options{instance_value}->{display} . "' "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . "]"; +} + sub prefix_storage_output { my ($self, %options) = @_; - return "Container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . "] Device '" . $options{instance_value}->{device} . "' "; + return "Storage '" . $options{instance_value}->{display} . "' "; } sub new { @@ -196,10 +211,10 @@ sub manage_selection { foreach my $result (@{$results}) { next if (!defined($result->{metric}->{$self->{labels}->{pod}}) || !defined($result->{metric}->{$self->{labels}->{container}})); + $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{display} = $result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}; $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{storage}->{$result->{metric}->{$self->{labels}->{device}}}->{container} = $result->{metric}->{$self->{labels}->{container}}; $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{storage}->{$result->{metric}->{$self->{labels}->{device}}}->{pod} = $result->{metric}->{$self->{labels}->{pod}}; $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{storage}->{$result->{metric}->{$self->{labels}->{device}}}->{device} = $result->{metric}->{$self->{labels}->{device}}; - $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{storage}->{$result->{metric}->{$self->{labels}->{device}}}->{perf} = $result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}; $self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{storage}->{$result->{metric}->{$self->{labels}->{device}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1]; }