From cb99fa1a2f6f01e6eb33a29ba9974b57d10fe2d2 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Fri, 7 Jun 2019 17:59:52 +0200 Subject: [PATCH] move kubernetes perfdata --- cloud/kubernetes/mode/daemonsetstatus.pm | 53 +++++++++++++++-------- cloud/kubernetes/mode/deploymentstatus.pm | 45 ++++++++++++------- cloud/kubernetes/mode/nodeusage.pm | 21 ++++----- cloud/kubernetes/mode/podstatus.pm | 26 ++++++----- 4 files changed, 92 insertions(+), 53 deletions(-) diff --git a/cloud/kubernetes/mode/daemonsetstatus.pm b/cloud/kubernetes/mode/daemonsetstatus.pm index eadb334d6..051928133 100644 --- a/cloud/kubernetes/mode/daemonsetstatus.pm +++ b/cloud/kubernetes/mode/daemonsetstatus.pm @@ -29,23 +29,42 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - - $self->{output}->perfdata_add(label => 'desired' . $extra_label, - value => $self->{result_values}->{desired}); - $self->{output}->perfdata_add(label => 'current' . $extra_label, - value => $self->{result_values}->{current}); - $self->{output}->perfdata_add(label => 'available' . $extra_label, - value => $self->{result_values}->{available}); - $self->{output}->perfdata_add(label => 'up_to_date' . $extra_label, - value => $self->{result_values}->{up_to_date}); - $self->{output}->perfdata_add(label => 'ready' . $extra_label, - value => $self->{result_values}->{ready}); - $self->{output}->perfdata_add(label => 'misscheduled' . $extra_label, - value => $self->{result_values}->{misscheduled}); + $self->{output}->perfdata_add( + label => 'desired', + nlabel => 'daemonset.pods.desired.count', + value => $self->{result_values}->{desired}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'current', + nlabel => 'daemonset.pods.current.count', + value => $self->{result_values}->{current}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'available', + nlabel => 'daemonset.pods.available.count', + value => $self->{result_values}->{available}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'up_to_date', + nlabel => 'daemonset.pods.uptodate.count', + value => $self->{result_values}->{up_to_date}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'ready', + nlabel => 'daemonset.pods.ready.count', + value => $self->{result_values}->{ready}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'misscheduled', + nlabel => 'daemonset.pods.misscheduled.count', + value => $self->{result_values}->{misscheduled}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); } sub custom_status_output { diff --git a/cloud/kubernetes/mode/deploymentstatus.pm b/cloud/kubernetes/mode/deploymentstatus.pm index e57e74242..215e8a418 100644 --- a/cloud/kubernetes/mode/deploymentstatus.pm +++ b/cloud/kubernetes/mode/deploymentstatus.pm @@ -29,21 +29,36 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - - $self->{output}->perfdata_add(label => 'desired' . $extra_label, - value => $self->{result_values}->{desired}); - $self->{output}->perfdata_add(label => 'current' . $extra_label, - value => $self->{result_values}->{current}); - $self->{output}->perfdata_add(label => 'available' . $extra_label, - value => $self->{result_values}->{available}); - $self->{output}->perfdata_add(label => 'ready' . $extra_label, - value => $self->{result_values}->{ready}); - $self->{output}->perfdata_add(label => 'up_to_date' . $extra_label, - value => $self->{result_values}->{up_to_date}); + $self->{output}->perfdata_add( + label => 'desired', + nlabel => 'deployment.replicas.desired.count', + value => $self->{result_values}->{desired}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'current', + nlabel => 'deployment.replicas.current.count', + value => $self->{result_values}->{current}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'available', + nlabel => 'deployment.replicas.available.count', + value => $self->{result_values}->{available}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'ready', + nlabel => 'deployment.replicas.ready.count', + value => $self->{result_values}->{ready}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); + $self->{output}->perfdata_add( + label => 'up_to_date', + nlabel => 'deployment.replicas.uptodate.count', + value => $self->{result_values}->{up_to_date}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); } sub custom_status_output { diff --git a/cloud/kubernetes/mode/nodeusage.pm b/cloud/kubernetes/mode/nodeusage.pm index a181d8ca2..39c578e84 100644 --- a/cloud/kubernetes/mode/nodeusage.pm +++ b/cloud/kubernetes/mode/nodeusage.pm @@ -31,8 +31,7 @@ sub custom_usage_perfdata { my $label = 'allocated_pods'; my $value_perf = $self->{result_values}->{allocated}; - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{allocatable}; @@ -40,11 +39,13 @@ sub custom_usage_perfdata { } $self->{output}->perfdata_add( - label => $label . $extra_label, + label => $label, + nlabel => 'pods.allocated.count', value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{allocatable} + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), + min => 0, max => $self->{result_values}->{allocatable}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, ); } @@ -57,8 +58,8 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_allocated}; } $exit = $self->{perfdata}->threshold_check( - value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] + value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ] ); return $exit; } @@ -120,8 +121,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, + "filter-name:s" => { name => 'filter_name' }, + "units:s" => { name => 'units', default => '%' }, }); return $self; diff --git a/cloud/kubernetes/mode/podstatus.pm b/cloud/kubernetes/mode/podstatus.pm index 8101fccde..d3046e0df 100644 --- a/cloud/kubernetes/mode/podstatus.pm +++ b/cloud/kubernetes/mode/podstatus.pm @@ -64,19 +64,21 @@ sub custom_ready_perfdata { my ($self, %options) = @_; my $value_perf = $self->{result_values}->{ready}; - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); if ($self->{result_values}->{total} > 0 && $self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => 'containers_ready' . $extra_label, - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $total_options{total}); + $self->{output}->perfdata_add( + label => 'containers_ready', + nlabel => 'containers.ready.count', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), + min => 0, max => $total_options{total}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + ); } sub custom_ready_threshold { @@ -87,8 +89,10 @@ sub custom_ready_threshold { if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_ready}; } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check( + value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] + ); return $exit; } @@ -147,7 +151,7 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'total-restarts-count', set => { + { label => 'total-restarts-count', nlabel => 'restarts.total.count', set => { key_values => [ { name => 'restarts_total' }, { name => 'display' } ], output_template => 'Restarts: %d', perfdatas => [ @@ -166,7 +170,7 @@ sub set_counters { closure_custom_threshold_check => \&catalog_status_threshold, } }, - { label => 'restarts-count', set => { + { label => 'restarts-count', nlabel => 'containers.restarts.count', set => { key_values => [ { name => 'restarts' }, { name => 'perf' } ], output_template => 'Restarts: %d', perfdatas => [