centreon-plugins/os/aix/snmp/mode/swap.pm

221 lines
7.3 KiB
Perl
Raw Normal View History

2014-03-11 14:29:04 +01:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2014-03-11 14:29:04 +01:00
package os::aix::snmp::mode::swap;
2019-03-28 13:55:17 +01:00
use base qw(centreon::plugins::templates::counter);
2014-03-11 14:29:04 +01:00
use strict;
use warnings;
2019-03-28 13:55:17 +01:00
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
2020-05-20 08:50:37 +02:00
return sprintf(
"Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
2019-03-28 13:55:17 +01:00
}
sub custom_usage_calc {
my ($self, %options) = @_;
return -10 if ($options{new_datas}->{$self->{instance} . '_total'} <= 0);
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ', cb_init => 'skip_global', },
2020-05-20 08:50:37 +02:00
{ name => 'swap', type => 1, cb_prefix_output => 'prefix_swap_output', message_multiple => 'All page spaces are ok' }
2019-03-28 13:55:17 +01:00
];
$self->{maps_counters}->{global} = [
2019-04-17 22:45:31 +02:00
{ label => 'total-usage', nlabel => 'page.space.usage.bytes', set => {
2019-03-28 13:55:17 +01:00
key_values => [ { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
threshold_use => 'prct_used',
perfdatas => [
{ label => 'total_page_space', value => 'used', template => '%s', cast_int => 1,
2020-05-20 08:50:37 +02:00
unit => 'B', min => 0, max => 'total', threshold_total => 'total' }
]
2019-03-28 13:55:17 +01:00
}
},
2019-04-17 22:45:31 +02:00
{ label => 'total-active', nlabel => 'page.space.active.count', display_ok => 0, set => {
2019-03-28 13:55:17 +01:00
key_values => [ { name => 'nactive' }, { name => 'ntotal' } ],
output_template => 'Total page space active : %s',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'total_active', value => 'nactive', template => '%s',
2020-05-20 08:50:37 +02:00
min => 0, max => 'ntotal' }
]
2019-03-28 13:55:17 +01:00
}
2020-05-20 08:50:37 +02:00
}
2019-03-28 13:55:17 +01:00
];
$self->{maps_counters}->{swap} = [
2019-04-17 22:45:31 +02:00
{ label => 'usage', nlabel => 'page.space.usage.bytes', set => {
2019-03-28 13:55:17 +01:00
key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
threshold_use => 'prct_used',
perfdatas => [
{ label => 'page_space', value => 'used', template => '%s', cast_int => 1,
unit => 'B', min => 0, max => 'total', threshold_total => 'total',
2020-05-20 08:50:37 +02:00
label_extra_instance => 1, instance_use => 'display' }
]
2019-03-28 13:55:17 +01:00
}
2020-05-20 08:50:37 +02:00
}
2019-03-28 13:55:17 +01:00
];
}
sub prefix_swap_output {
my ($self, %options) = @_;
return "Page space '" . $options{instance_value}->{display} . "' ";
}
sub skip_global {
my ($self, %options) = @_;
scalar(keys %{$self->{swap}}) > 1 ? return(0) : return(1);
}
2014-03-11 14:29:04 +01:00
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
2019-03-28 13:55:17 +01:00
$options{options}->add_options(arguments => {
2020-05-20 08:50:37 +02:00
'paging-state-buggy' => { name => 'paging_state_buggy' }
2019-03-28 13:55:17 +01:00
});
2014-03-11 14:29:04 +01:00
return $self;
}
2020-05-20 08:50:37 +02:00
my $mapping = {
swap_name => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.1' }, # aixPageName
swap_total => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.4' }, # aixPageSize (in MB)
swap_usage => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.5' }, # aixPagePercentUsed
swap_status => { oid => '.1.3.6.1.4.1.2.6.191.2.4.2.1.6' } # aixPageStatus
};
2019-03-28 13:55:17 +01:00
sub manage_selection {
2014-03-11 14:29:04 +01:00
my ($self, %options) = @_;
my $aix_swap_pool = ".1.3.6.1.4.1.2.6.191.2.4.2.1"; # aixPageEntry
2020-05-20 08:50:37 +02:00
my $snmp_result = $options{snmp}->get_table(
oid => $aix_swap_pool,
end => $mapping->{swap_status}->{oid},
nothing_quit => 1
2019-03-28 13:55:17 +01:00
);
2014-03-11 14:29:04 +01:00
# Check if the paging space is active.
# Values are :
# 1 = "active"
# 2 = "notActive"
# Some systems may however return the contrary.
my $active_swap = 1;
2015-05-12 10:02:27 +02:00
if (defined($self->{option_results}->{paging_state_buggy})) {
$active_swap = 2;
2015-05-12 10:02:27 +02:00
}
2019-03-28 13:55:17 +01:00
$self->{global} = { nactive => 0, ntotal => 0, total => 0, used => 0 };
$self->{swap} = {};
2020-05-20 08:50:37 +02:00
foreach (keys %$snmp_result) {
next if (! /^$mapping->{swap_status}->{oid}\.(.*)$/);
2019-03-28 13:55:17 +01:00
$self->{global}->{ntotal}++;
2020-05-20 08:50:37 +02:00
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
next if ($result->{swap_status} != $active_swap);
$self->{global}->{nactive}++;
2014-03-11 14:29:04 +01:00
2020-05-20 08:50:37 +02:00
my $used = ($result->{swap_usage} * $result->{swap_total} / 100) * 1024 * 1024;
my $total = $result->{swap_total} * 1024 * 1024;
$self->{swap}->{ $result->{swap_name} } = {
display => $result->{swap_name},
used => $used,
total => $total
};
$self->{global}->{used} += $used;
$self->{global}->{total} += $total;
2014-03-11 14:29:04 +01:00
}
}
1;
__END__
=head1 MODE
Check AIX swap memory.
=over 8
2019-03-28 13:55:17 +01:00
=item B<--warning-usage>
Threshold warning in percent.
=item B<--critical-usage>
Threshold critical in percent.
=item B<--warning-total-usage>
2014-03-11 14:29:04 +01:00
Threshold warning in percent.
2019-03-28 13:55:17 +01:00
=item B<--critical-total-usage>
2014-03-11 14:29:04 +01:00
Threshold critical in percent.
2019-03-28 13:55:17 +01:00
=item B<--warning-total-active>
Threshold warning total page space active.
=item B<--critical-total-active>
Threshold critical total page space active.
2015-05-12 10:02:27 +02:00
=item B<--paging-state-buggy>
Paging state can be buggy. Please use the following option to swap state value.
2014-03-11 14:29:04 +01:00
=back
=cut