(plugin) cloud::cadvisor::restapi - manage cgroupv2 api (#3599)
This commit is contained in:
parent
3db06de4d9
commit
5b5ae8334f
|
@ -161,7 +161,8 @@ sub internal_api_list_containers {
|
|||
my $response = $self->{http}->request(
|
||||
hostname => $options{node_name},
|
||||
url_path => '/api/' . $self->{option_results}->{api_version} . $self->{option_results}->{api_path},
|
||||
unknown_status => '', critical_status => '', warning_status => '');
|
||||
unknown_status => '', critical_status => '', warning_status => ''
|
||||
);
|
||||
my $containers = [];
|
||||
my $containers_ids;
|
||||
eval {
|
||||
|
@ -174,21 +175,35 @@ sub internal_api_list_containers {
|
|||
short_msg => "Node '$options{node_name}': cannot decode json get containers response: $@"
|
||||
);
|
||||
}
|
||||
foreach my $container (@{$containers_ids->{subcontainers}}) {
|
||||
my $json_response = JSON::XS->new->utf8->decode(
|
||||
$self->{http}->request(
|
||||
hostname => $options{node_name},
|
||||
url_path => '/api/' . $self->{option_results}->{api_version} . '/containers/' . $container->{name}
|
||||
)
|
||||
);
|
||||
|
||||
push @$containers, {
|
||||
id => defined($json_response->{id}) ? $json_response->{id} : $json_response->{name},
|
||||
names => defined($json_response->{aliases}) ? $json_response->{aliases} : [$json_response->{name}],
|
||||
node => $options{node_name}
|
||||
};
|
||||
|
||||
# cgroup v1
|
||||
if (defined($containers_ids->{subcontainers})) {
|
||||
foreach my $container (@{$containers_ids->{subcontainers}}) {
|
||||
my $json_response = JSON::XS->new->utf8->decode(
|
||||
$self->{http}->request(
|
||||
hostname => $options{node_name},
|
||||
url_path => '/api/' . $self->{option_results}->{api_version} . '/containers/' . $container->{name}
|
||||
)
|
||||
);
|
||||
|
||||
push @$containers, {
|
||||
id => defined($json_response->{id}) ? $json_response->{id} : $json_response->{name},
|
||||
names => defined($json_response->{aliases}) ? $json_response->{aliases} : [$json_response->{name}],
|
||||
node => $options{node_name}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
# cgroup v2
|
||||
foreach (values %$containers_ids) {
|
||||
next if (!defined($_->{id}));
|
||||
push @$containers, {
|
||||
id => defined($_->{id}) ? $_->{id} : $_->{name},
|
||||
names => defined($_->{aliases}) ? $_->{aliases} : [$_->{name}],
|
||||
node => $options{node_name}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $containers;
|
||||
}
|
||||
|
||||
|
@ -218,10 +233,12 @@ sub internal_api_get_machine_stats {
|
|||
|
||||
sub internal_api_get_container_stats {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $response = $self->{http}->request(
|
||||
hostname => $options{node_name},
|
||||
url_path => '/api/' . $self->{option_results}->{api_version} . $self->{option_results}->{api_path} . '/' . $options{container_id},
|
||||
unknown_status => '', critical_status => '', warning_status => '');
|
||||
unknown_status => '', critical_status => '', warning_status => ''
|
||||
);
|
||||
my $container_stats;
|
||||
my $full_container_stats;
|
||||
eval {
|
||||
|
|
|
@ -48,7 +48,7 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers are ok', skipped_code => { -11 => 1 } },
|
||||
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers are ok', skipped_code => { -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{containers} = [
|
||||
|
@ -56,8 +56,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'cpu_number'}, { name => 'display' } ],
|
||||
output_template => 'CPU: %d core(s)',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_number', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -65,8 +64,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'cpu_total'}, { name => 'display' } ],
|
||||
output_template => 'CPU Usage: %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_total', template => '%.2f',
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -74,8 +72,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'cpu_user'}, { name => 'display' } ],
|
||||
output_template => 'CPU User: %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_user', template => '%.2f',
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -83,8 +80,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'cpu_system' }, { name => 'display' } ],
|
||||
output_template => 'CPU System: %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_system', template => '%.2f',
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -93,8 +89,7 @@ sub set_counters {
|
|||
closure_custom_output => $self->can('custom_memory_output'),
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'memory_used', template => '%s',
|
||||
min => 0, max => 'memory_total',unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%s', min => 0, max => 'memory_total',unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -103,8 +98,7 @@ sub set_counters {
|
|||
output_template => 'Memory Cache: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'memory_cache', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -113,8 +107,7 @@ sub set_counters {
|
|||
output_template => 'Memory RSS: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'memory_rss', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -123,8 +116,7 @@ sub set_counters {
|
|||
output_template => 'Swap: %s %s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'swap', template => '%s',
|
||||
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -181,8 +173,7 @@ sub manage_selection {
|
|||
my $last_cpu_system = $last_stat->{cpu}{usage}{system};
|
||||
|
||||
my $diff_ts = $last_dt - $first_dt;
|
||||
my $cpu_number = $machine_stats->{$result->{$container_id}->{NodeName}}->{num_cores};
|
||||
|
||||
my $cpu_number = $machine_stats->{ $result->{$container_id}->{NodeName} }->{num_cores};
|
||||
|
||||
$self->{containers}->{$container_id} = {
|
||||
node_name => $result->{$container_id}->{NodeName},
|
||||
|
@ -196,7 +187,7 @@ sub manage_selection {
|
|||
memory_cache => $last_stat->{memory}{cache},
|
||||
memory_rss => $last_stat->{memory}{rss},
|
||||
swap => $last_stat->{memory}{swap},
|
||||
memory_total => $machine_stats->{$result->{$container_id}->{NodeName}}->{memory_capacity},
|
||||
memory_total => $machine_stats->{$result->{$container_id}->{NodeName}}->{memory_capacity}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -204,7 +195,7 @@ sub manage_selection {
|
|||
$self->{output}->add_option_msg(short_msg => "No containers found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
my $hostnames = $options{custom}->get_hostnames();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue