| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package network::lenovo::rackswitch::snmp::mode::memory; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use network::lenovo::rackswitch::snmp::mode::resources; |
| 28 |
|
| 29 |
sub custom_usage_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'Memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', |
| 34 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), |
| 35 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), |
| 36 |
$self->{result_values}->{prct_used}, |
| 37 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), |
| 38 |
$self->{result_values}->{prct_free} |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub set_counters { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
$self->{maps_counters_type} = [ |
| 46 |
{ name => 'ram', type => 0, skipped_code => { -10 => 1 } } |
| 47 |
]; |
| 48 |
|
| 49 |
$self->{maps_counters}->{ram} = [ |
| 50 |
{ label => 'usage', nlabel => 'memory.usage.bytes', set => { |
| 51 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 52 |
closure_custom_output => $self->can('custom_usage_output'), |
| 53 |
perfdatas => [ |
| 54 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } |
| 55 |
] |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { |
| 59 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 60 |
closure_custom_output => $self->can('custom_usage_output'), |
| 61 |
perfdatas => [ |
| 62 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } |
| 63 |
] |
| 64 |
} |
| 65 |
}, |
| 66 |
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { |
| 67 |
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], |
| 68 |
closure_custom_output => $self->can('custom_usage_output'), |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 71 |
] |
| 72 |
} |
| 73 |
} |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
sub new { |
| 78 |
my ($class, %options) = @_; |
| 79 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 80 |
bless $self, $class; |
| 81 |
|
| 82 |
return $self; |
| 83 |
} |
| 84 |
|
| 85 |
sub manage_selection { |
| 86 |
my ($self, %options) = @_; |
| 87 |
|
| 88 |
if ($options{snmp}->is_snmpv1()) { |
| 89 |
$self->{output}->add_option_msg(short_msg => 'Need to use SNMP v2c or v3.'); |
| 90 |
$self->{output}->option_exit(); |
| 91 |
} |
| 92 |
|
| 93 |
my $branch = network::lenovo::rackswitch::snmp::mode::resources::find_rackswitch_branch( |
| 94 |
output => $self->{output}, snmp => $options{snmp} |
| 95 |
); |
| 96 |
my $oid_total = $branch . '.1.2.12.1.0'; # totalMemoryStats |
| 97 |
my $oid_free = $branch . '.1.2.12.2.0'; # memoryFreeStats |
| 98 |
my $snmp_result = $options{snmp}->get_leef( |
| 99 |
oids => [ $oid_total, $oid_free ], |
| 100 |
nothing_quit => 1 |
| 101 |
); |
| 102 |
|
| 103 |
$self->{ram} = { |
| 104 |
total => $snmp_result->{$oid_total}, |
| 105 |
used => $snmp_result->{$oid_total} - $snmp_result->{$oid_free}, |
| 106 |
free => $snmp_result->{$oid_free}, |
| 107 |
prct_used => 100 - ($snmp_result->{$oid_free} * 100 / $snmp_result->{$oid_total}), |
| 108 |
prct_free => $snmp_result->{$oid_free} * 100 / $snmp_result->{$oid_total} |
| 109 |
}; |
| 110 |
} |
| 111 |
|
| 112 |
1; |
| 113 |
|
| 114 |
__END__ |
| 115 |
|
| 116 |
=head1 MODE |
| 117 |
|
| 118 |
Check memory. |
| 119 |
|
| 120 |
=over 8 |
| 121 |
|
| 122 |
=item B<--warning-*> B<--critical-*> |
| 123 |
|
| 124 |
Thresholds. |
| 125 |
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). |
| 126 |
|
| 127 |
=back |
| 128 |
|
| 129 |
=cut |