add docker information

This commit is contained in:
qgarnier 2017-07-25 11:39:36 +02:00
parent d6f85a2efb
commit 103970c44c
2 changed files with 76 additions and 5 deletions

View File

@ -228,6 +228,25 @@ sub internal_api_list_nodes {
return $nodes;
}
sub internal_api_info {
my ($self, %options) = @_;
my $response = $self->{http}->{$options{node_name}}->request(
url_path => '/info',
unknown_status => '', critical_status => '', warning_status => '');
my $nodes;
eval {
$nodes = JSON::XS->new->utf8->decode($response);
};
if ($@) {
$nodes = [];
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Node '$options{node_name}': cannot decode json info response: $@");
}
return $nodes;
}
sub internal_api_list_containers {
my ($self, %options) = @_;
@ -289,10 +308,15 @@ sub api_list_nodes {
my $nodes = {};
foreach my $node_name (keys %{$self->{http}}) {
$nodes->{$node_name} = [];
my $info_node = $self->internal_api_info(node_name => $node_name);
my $list_nodes = $self->internal_api_list_nodes(node_name => $node_name);
$nodes->{$node_name} = { nodes => [],
containers_running => $info_node->{ContainersRunning},
containers_stopped => $info_node->{ContainersStopped},
containers_paused => $info_node->{ContainersPaused},
};
foreach my $node (@$list_nodes) {
push @{$nodes->{$node_name}}, { Status => $node->{Status}->{State}, ManagerStatus => $node->{ManagerStatus}->{Reachability}, Addr => $node->{Status}->{Addr} };
push @{$nodes->{$node_name}->{nodes}}, { Status => $node->{Status}->{State}, ManagerStatus => $node->{ManagerStatus}->{Reachability}, Addr => $node->{Status}->{Addr} };
}
}

View File

@ -72,7 +72,8 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok', skipped_code => { -11 => 1 } },
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } },
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node status are ok', skipped_code => { -11 => 1 } },
];
$self->{maps_counters}->{nodes} = [
@ -85,6 +86,35 @@ sub set_counters {
}
},
];
$self->{maps_counters}->{node} = [
{ label => 'containers-running', set => {
key_values => [ { name => 'containers_running' }, { name => 'display' } ],
output_template => 'Containers Running : %s',
perfdatas => [
{ label => 'containers_running', value => 'containers_running_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'containers-stopped', set => {
key_values => [ { name => 'containers_stopped' }, { name => 'display' } ],
output_template => 'Containers Stopped : %s',
perfdatas => [
{ label => 'containers_stopped', value => 'containers_stopped_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'containers-running', set => {
key_values => [ { name => 'containers_paused' }, { name => 'display' } ],
output_template => 'Containers Paused : %s',
perfdatas => [
{ label => 'containers_paused', value => 'containers_paused_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
@ -128,12 +158,19 @@ sub change_macros {
sub manage_selection {
my ($self, %options) = @_;
$self->{node} = {};
$self->{nodes} = {};
my $result = $options{custom}->api_list_nodes();
foreach my $node_name (keys %{$result}) {
foreach my $entry (@{$result->{$node_name}}) {
$self->{node}->{$node_name} = {
display => $node_name,
containers_running => $result->{$node_name}->{containers_running},
containers_stopped => $result->{$node_name}->{containers_stopped},
containers_paused => $result->{$node_name}->{containers_paused},
};
foreach my $entry (@{$result->{$node_name}->{nodes}}) {
my $name = $node_name . '/' . $entry->{Addr};
$self->{nodes}->{$name} = {
display => $name ,
@ -169,6 +206,16 @@ Can used special variables like: %{display}, %{status}, %{manager_status}.
Set critical threshold for status (Default: '%{status} !~ /ready/ || %{manager_status} !~ /reachable|-/').
Can used special variables like: %{display}, %{status}, %{manager_status}.
=item B<--warning-*>
Threshold warning.
Can be: 'containers-running', 'containers-paused', 'containers-stopped'.
=item B<--critical-*>
Threshold critical.
Can be: 'containers-running', 'containers-paused', 'containers-stopped'.,
=back
=cut