(plugin) cloud::prometheus::restapi - mode memory fix perfdata
This commit is contained in:
parent
eb03dc5508
commit
d38b17ece7
|
@ -25,6 +25,20 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub custom_perfdata {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
nlabel => $self->{nlabel},
|
||||
unit => 'B',
|
||||
instances => [ $self->{result_values}->{pod}, $self->{result_values}->{container} ],
|
||||
value => sprintf('%s', $self->{result_values}->{ $self->{key_values}->[0]->{name} }),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -38,13 +52,13 @@ sub custom_usage_perfdata {
|
|||
}
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label, unit => 'B',
|
||||
nlabel => 'memory.' . $label . '.bytes',
|
||||
nlabel => 'memory.' . $label . '.bytes',
|
||||
unit => 'B',
|
||||
instances => [ $self->{result_values}->{pod}, $self->{result_values}->{container} ],
|
||||
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 => $self->{result_values}->{total},
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -94,7 +108,6 @@ sub custom_usage_calc {
|
|||
$self->{result_values}->{perfdata} = $options{extra_options}->{perfdata_ref};
|
||||
$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} . '_limits'};
|
||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}};
|
||||
return 0 if ($self->{result_values}->{total} == 0);
|
||||
|
@ -104,6 +117,12 @@ sub custom_usage_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_containers_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . "] Memory ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -114,18 +133,16 @@ sub set_counters {
|
|||
|
||||
$self->{maps_counters}->{containers} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'limits' }, { name => 'usage' }, { name => 'container' },
|
||||
{ name => 'pod' }, { name => 'perf' } ],
|
||||
key_values => [ { name => 'limits' }, { name => 'usage' }, { name => 'container' }, { name => 'pod' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_calc_extra_options => { label_ref => 'usage', perfdata_ref => 'used' },
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'working', set => {
|
||||
key_values => [ { name => 'limits' }, { name => 'working' }, { name => 'container' },
|
||||
{ name => 'pod' }, { name => 'perf' } ],
|
||||
key_values => [ { name => 'limits' }, { name => 'working' }, { name => 'container' }, { name => 'pod' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_calc_extra_options => { label_ref => 'working', perfdata_ref => 'working' },
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
|
@ -134,47 +151,32 @@ sub set_counters {
|
|||
}
|
||||
},
|
||||
{ label => 'cache', nlabel => 'cache.usage.bytes', set => {
|
||||
key_values => [ { name => 'cache' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
|
||||
key_values => [ { name => 'cache' }, { name => 'container' }, { name => 'pod' } ],
|
||||
output_template => 'Cache: %.2f %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'cache', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'perf' }
|
||||
]
|
||||
closure_custom_perfdata => $self->can('custom_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'rss', nlabel => 'rss.usage.bytes', set => {
|
||||
key_values => [ { name => 'rss' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
|
||||
key_values => [ { name => 'rss' }, { name => 'container' }, { name => 'pod' } ],
|
||||
output_template => 'Rss: %.2f %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'rss', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'perf' }
|
||||
]
|
||||
closure_custom_perfdata => $self->can('custom_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'swap', nlabel => 'swap.usage.bytes', set => {
|
||||
key_values => [ { name => 'swap' }, { name => 'container' }, { name => 'pod' }, { name => 'perf' } ],
|
||||
key_values => [ { name => 'swap' }, { name => 'container' }, { name => 'pod' } ],
|
||||
output_template => 'Swap: %.2f %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'swap', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'perf' }
|
||||
]
|
||||
closure_custom_perfdata => $self->can('custom_perfdata')
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_containers_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Container '" . $options{instance_value}->{container} . "' [pod: " . $options{instance_value}->{pod} . "] Memory ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
@ -223,8 +225,6 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{containers} = {};
|
||||
|
||||
my $results = $options{custom}->query(
|
||||
queries => [
|
||||
'label_replace({__name__=~"' . $self->{metrics}->{usage} . '",' .
|
||||
|
@ -254,12 +254,12 @@ sub manage_selection {
|
|||
]
|
||||
);
|
||||
|
||||
$self->{containers} = {};
|
||||
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}}}->{container} = $result->{metric}->{$self->{labels}->{container}};
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{pod} = $result->{metric}->{$self->{labels}->{pod}};
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{perf} = $result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}};
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . "_" . $result->{metric}->{$self->{labels}->{container}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . '_' . $result->{metric}->{$self->{labels}->{container}}}->{container} = $result->{metric}->{$self->{labels}->{container}};
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . '_' . $result->{metric}->{$self->{labels}->{container}}}->{pod} = $result->{metric}->{$self->{labels}->{pod}};
|
||||
$self->{containers}->{$result->{metric}->{$self->{labels}->{pod}} . '_' . $result->{metric}->{$self->{labels}->{container}}}->{$result->{metric}->{__name__}} = ${$result->{value}}[1];
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{containers}}) <= 0) {
|
||||
|
|
|
@ -29,17 +29,16 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'cpu' => 'cloud::prometheus::exporters::cadvisor::mode::cpu',
|
||||
'list-containers' => 'cloud::prometheus::exporters::cadvisor::mode::listcontainers',
|
||||
'load' => 'cloud::prometheus::exporters::cadvisor::mode::load',
|
||||
'memory' => 'cloud::prometheus::exporters::cadvisor::mode::memory',
|
||||
'storage' => 'cloud::prometheus::exporters::cadvisor::mode::storage',
|
||||
'task-state' => 'cloud::prometheus::exporters::cadvisor::mode::taskstate',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'cpu' => 'cloud::prometheus::exporters::cadvisor::mode::cpu',
|
||||
'list-containers' => 'cloud::prometheus::exporters::cadvisor::mode::listcontainers',
|
||||
'load' => 'cloud::prometheus::exporters::cadvisor::mode::load',
|
||||
'memory' => 'cloud::prometheus::exporters::cadvisor::mode::memory',
|
||||
'storage' => 'cloud::prometheus::exporters::cadvisor::mode::storage',
|
||||
'task-state' => 'cloud::prometheus::exporters::cadvisor::mode::taskstate'
|
||||
};
|
||||
|
||||
$self->{custom_modes}{api} = 'cloud::prometheus::restapi::custom::api';
|
||||
$self->{custom_modes}->{api} = 'cloud::prometheus::restapi::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue