enhance swap local

This commit is contained in:
garnier-quentin 2019-10-24 09:33:43 +02:00
parent fba1cff365
commit 5a540d1712
1 changed files with 38 additions and 49 deletions

View File

@ -49,34 +49,29 @@ sub set_counters {
];
$self->{maps_counters}->{swap} = [
{ label => 'swap-used', nlabel => 'swap.usage.bytes', set => {
{ label => 'usage', nlabel => 'swap.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
threshold_use => 'used_absolute',
perfdatas => [
{ label => 'swap_used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', unit => 'B', cast_int => 1 },
{ label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', unit => 'B', cast_int => 1 },
],
},
},
{ label => 'swap-free', display_ok => 0, nlabel => 'swap.free.bytes', set => {
{ label => 'usage-free', display_ok => 0, nlabel => 'swap.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
threshold_use => 'free_absolute',
},
},
{ label => 'swap-prct-used', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
threshold_use => 'prct_used_absolute',
perfdatas => [
{ label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' },
{ label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 },
],
},
},
{ label => 'swap-prct-free', display_ok => 0, nlabel => 'swap.free.percentage', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_swap_output'),
threshold_use => 'prct_free_absolute',
{ label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ],
output_template => 'Swap used: %.2f %%',
perfdatas => [
{ label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' },
],
},
},
];
@ -87,20 +82,20 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'cat' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '/proc/meminfo 2>&1' },
"no-swap:s" => { name => 'no_swap' },
});
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'cat' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '/proc/meminfo 2>&1' },
'no-swap:s' => { name => 'no_swap' },
});
$self->{no_swap} = 'critical';
return $self;
}
@ -109,7 +104,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
@ -123,12 +117,14 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
my ($total_size, $swap_free);
foreach (split(/\n/, $stdout)) {
@ -150,15 +146,13 @@ sub manage_selection {
$self->{output}->display();
$self->{output}->exit();
}
my $swap_used = $total_size - $swap_free;
my $prct_used = $swap_used * 100 / $total_size;
my $prct_free = 100 - $prct_used;
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used);
my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used));
$self->{swap} = {
used => $swap_used,
@ -167,7 +161,6 @@ sub manage_selection {
prct_free => $prct_free,
total => $total_size
};
}
1;
@ -180,14 +173,6 @@ Check swap memory (need '/proc/meminfo' file).
=over 8
=item B<--warning-swap-*>
Warning threshold, can be used (in Bytes), free (in Bytes), prct-used (Percentage), prct-free (Percentage).
=item B<--critical-swap-*>
Critical threshold, , can be used (in Bytes), free (in Bytes), prct-used (Percentage), prct-free (Percentage).
=item B<--no-swap>
Threshold if no active swap (default: 'critical').
@ -233,6 +218,10 @@ Command path (Default: none).
Command options (Default: '/proc/meminfo 2>&1').
=item B<--warning-*> B<--critical-*>
Threshold, can be 'usage' (in Bytes), 'usage-free' (in Bytes), 'usage-prct' (%).
=back
=cut