enhance swap local
This commit is contained in:
parent
8481da33c7
commit
e5bdaa98fb
|
@ -49,34 +49,29 @@ sub set_counters {
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{swap} = [
|
$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' } ],
|
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||||
closure_custom_output => $self->can('custom_swap_output'),
|
closure_custom_output => $self->can('custom_swap_output'),
|
||||||
threshold_use => 'used_absolute',
|
|
||||||
perfdatas => [
|
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' } ],
|
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||||
closure_custom_output => $self->can('custom_swap_output'),
|
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 => [
|
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 => {
|
{ label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
|
||||||
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
key_values => [ { name => 'prct_used' } ],
|
||||||
closure_custom_output => $self->can('custom_swap_output'),
|
output_template => 'Swap used: %.2f %%',
|
||||||
threshold_use => 'prct_free_absolute',
|
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);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'hostname:s' => { name => 'hostname' },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'remote' => { name => 'remote' },
|
||||||
"remote" => { name => 'remote' },
|
'ssh-option:s@' => { name => 'ssh_option' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'ssh-path:s' => { name => 'ssh_path' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
'timeout:s' => { name => 'timeout', default => 30 },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'sudo' => { name => 'sudo' },
|
||||||
"sudo" => { name => 'sudo' },
|
'command:s' => { name => 'command', default => 'cat' },
|
||||||
"command:s" => { name => 'command', default => 'cat' },
|
'command-path:s' => { name => 'command_path' },
|
||||||
"command-path:s" => { name => 'command_path' },
|
'command-options:s' => { name => 'command_options', default => '/proc/meminfo 2>&1' },
|
||||||
"command-options:s" => { name => 'command_options', default => '/proc/meminfo 2>&1' },
|
'no-swap:s' => { name => 'no_swap' },
|
||||||
"no-swap:s" => { name => 'no_swap' },
|
});
|
||||||
});
|
|
||||||
$self->{no_swap} = 'critical';
|
$self->{no_swap} = 'critical';
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +104,6 @@ sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
|
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) {
|
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} . "'.");
|
$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 {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
my $stdout = centreon::plugins::misc::execute(
|
||||||
options => $self->{option_results},
|
output => $self->{output},
|
||||||
sudo => $self->{option_results}->{sudo},
|
options => $self->{option_results},
|
||||||
command => $self->{option_results}->{command},
|
sudo => $self->{option_results}->{sudo},
|
||||||
command_path => $self->{option_results}->{command_path},
|
command => $self->{option_results}->{command},
|
||||||
command_options => $self->{option_results}->{command_options});
|
command_path => $self->{option_results}->{command_path},
|
||||||
|
command_options => $self->{option_results}->{command_options}
|
||||||
|
);
|
||||||
|
|
||||||
my ($total_size, $swap_free);
|
my ($total_size, $swap_free);
|
||||||
foreach (split(/\n/, $stdout)) {
|
foreach (split(/\n/, $stdout)) {
|
||||||
|
@ -152,14 +148,12 @@ sub manage_selection {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $swap_used = $total_size - $swap_free;
|
my $swap_used = $total_size - $swap_free;
|
||||||
|
|
||||||
my $prct_used = $swap_used * 100 / $total_size;
|
my $prct_used = $swap_used * 100 / $total_size;
|
||||||
my $prct_free = 100 - $prct_used;
|
my $prct_free = 100 - $prct_used;
|
||||||
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
|
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_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));
|
my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used));
|
||||||
|
|
||||||
|
|
||||||
$self->{swap} = {
|
$self->{swap} = {
|
||||||
used => $swap_used,
|
used => $swap_used,
|
||||||
free => $swap_free,
|
free => $swap_free,
|
||||||
|
@ -167,7 +161,6 @@ sub manage_selection {
|
||||||
prct_free => $prct_free,
|
prct_free => $prct_free,
|
||||||
total => $total_size
|
total => $total_size
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -180,14 +173,6 @@ Check swap memory (need '/proc/meminfo' file).
|
||||||
|
|
||||||
=over 8
|
=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>
|
=item B<--no-swap>
|
||||||
|
|
||||||
Threshold if no active swap (default: 'critical').
|
Threshold if no active swap (default: 'critical').
|
||||||
|
@ -233,6 +218,10 @@ Command path (Default: none).
|
||||||
|
|
||||||
Command options (Default: '/proc/meminfo 2>&1').
|
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
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
Loading…
Reference in New Issue