| 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 alarm 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::viptela::snmp::mode::memory; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_usage_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return sprintf( |
| 32 |
'Ram total: %s %s used (-buffers/cache): %s %s (%.2f%%) free: %s %s (%.2f%%)', |
| 33 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), |
| 34 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), |
| 35 |
$self->{result_values}->{prct_used}, |
| 36 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), |
| 37 |
$self->{result_values}->{prct_free} |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'ram', type => 0, skipped_code => { -10 => 1 } } |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{ram} = [ |
| 49 |
{ label => 'usage', nlabel => 'memory.usage.bytes', set => { |
| 50 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 51 |
closure_custom_output => $self->can('custom_usage_output'), |
| 52 |
perfdatas => [ |
| 53 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } |
| 54 |
] |
| 55 |
} |
| 56 |
}, |
| 57 |
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { |
| 58 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 59 |
closure_custom_output => $self->can('custom_usage_output'), |
| 60 |
perfdatas => [ |
| 61 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } |
| 62 |
] |
| 63 |
} |
| 64 |
}, |
| 65 |
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { |
| 66 |
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], |
| 67 |
closure_custom_output => $self->can('custom_usage_output'), |
| 68 |
perfdatas => [ |
| 69 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 70 |
] |
| 71 |
} |
| 72 |
}, |
| 73 |
{ label => 'buffer', nlabel => 'memory.buffer.bytes', set => { |
| 74 |
key_values => [ { name => 'buffers' } ], |
| 75 |
output_template => 'buffer: %s %s', |
| 76 |
output_change_bytes => 1, |
| 77 |
perfdatas => [ |
| 78 |
{ template => '%d', min => 0, unit => 'B' } |
| 79 |
] |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'cached', nlabel => 'memory.cached.bytes', set => { |
| 83 |
key_values => [ { name => 'cached' } ], |
| 84 |
output_template => 'cached: %s %s', |
| 85 |
output_change_bytes => 1, |
| 86 |
perfdatas => [ |
| 87 |
{ template => '%d', min => 0, unit => 'B' } |
| 88 |
] |
| 89 |
} |
| 90 |
} |
| 91 |
]; |
| 92 |
} |
| 93 |
|
| 94 |
sub new { |
| 95 |
my ($class, %options) = @_; |
| 96 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 97 |
bless $self, $class; |
| 98 |
|
| 99 |
$options{options}->add_options(arguments => {}); |
| 100 |
|
| 101 |
return $self; |
| 102 |
} |
| 103 |
|
| 104 |
sub manage_selection { |
| 105 |
my ($self, %options) = @_; |
| 106 |
|
| 107 |
my $mapping = { |
| 108 |
total => { oid => '.1.3.6.1.4.1.41916.11.1.17' }, # systemStatusMemTotal |
| 109 |
used => { oid => '.1.3.6.1.4.1.41916.11.1.18' }, # systemStatusMemUsed |
| 110 |
free => { oid => '.1.3.6.1.4.1.41916.11.1.19' }, # systemStatusMemFree |
| 111 |
buffers => { oid => '.1.3.6.1.4.1.41916.11.1.20' }, # systemStatusMemBuffers |
| 112 |
cached => { oid => '.1.3.6.1.4.1.41916.11.1.21' } # systemStatusMemCached |
| 113 |
}; |
| 114 |
|
| 115 |
my $snmp_result = $options{snmp}->get_leef( |
| 116 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 117 |
nothing_quit => 1 |
| 118 |
); |
| 119 |
|
| 120 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 121 |
|
| 122 |
my $used = $result->{used}; |
| 123 |
$used -= (defined($result->{cached}) ? $result->{cached} : 0) - (defined($result->{buffers}) ? $result->{buffers} : 0); |
| 124 |
$used *= 1024; |
| 125 |
|
| 126 |
$result->{total} *= 1024; |
| 127 |
|
| 128 |
$self->{ram} = { |
| 129 |
total => $result->{total}, |
| 130 |
used => $used, |
| 131 |
free => $result->{total} - $used, |
| 132 |
prct_used => $used * 100 / $result->{total}, |
| 133 |
prct_free => 100 - ($used * 100 / $result->{total}), |
| 134 |
cached => $result->{cached} * 1024, |
| 135 |
buffers => $result->{buffers} * 1024 |
| 136 |
}; |
| 137 |
} |
| 138 |
|
| 139 |
1; |
| 140 |
|
| 141 |
__END__ |
| 142 |
|
| 143 |
=head1 MODE |
| 144 |
|
| 145 |
Check memory usage. |
| 146 |
|
| 147 |
=over 8 |
| 148 |
|
| 149 |
=item B<--warning-usage> |
| 150 |
|
| 151 |
Warning threshold on used memory (in B). |
| 152 |
|
| 153 |
=item B<--critical-usage> |
| 154 |
|
| 155 |
Critical threshold on used memory (in B) |
| 156 |
|
| 157 |
=item B<--warning-usage-prct> |
| 158 |
|
| 159 |
Warning threshold on used memory (in %). |
| 160 |
|
| 161 |
=item B<--critical-usage-prct> |
| 162 |
|
| 163 |
Critical threshold on percentage used memory (in %) |
| 164 |
|
| 165 |
=item B<--warning-usage-free> |
| 166 |
|
| 167 |
Warning threshold on free memory (in B). |
| 168 |
|
| 169 |
=item B<--critical-usage-free> |
| 170 |
|
| 171 |
Critical threshold on free memory (in B) |
| 172 |
|
| 173 |
=item B<--warning-*> B<--critical-*> |
| 174 |
|
| 175 |
Thresholds (in B) on other metrics where '*' can be: |
| 176 |
buffer, cached |
| 177 |
|
| 178 |
=back |
| 179 |
|
| 180 |
=cut |