| 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::mrv::optiswitch::snmp::mode::memory; |
| 22 |
|
| 23 |
use base qw(snmp_standard::mode::memory); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub memory_calc { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my $available = ($options{result}->{memTotalFree}) ? $options{result}->{memTotalFree} * 1024 : 0; |
| 32 |
my $total = ($options{result}->{memTotalReal}) ? $options{result}->{memTotalReal} * 1024 : 0; |
| 33 |
my $buffer = ($options{result}->{memBuffer}) ? $options{result}->{memBuffer} * 1024 : 0; |
| 34 |
my $cached = ($options{result}->{memCached}) ? $options{result}->{memCached} * 1024 : 0; |
| 35 |
my ($used, $free, $prct_used, $prct_free) = (0, 0, 0, 0); |
| 36 |
|
| 37 |
if ($total != 0) { |
| 38 |
$used = $total - $available - $buffer - $cached; |
| 39 |
$free = $total - $used; |
| 40 |
$prct_used = $used * 100 / $total; |
| 41 |
$prct_free = 100 - $prct_used; |
| 42 |
} |
| 43 |
|
| 44 |
$self->{ram} = { |
| 45 |
total => $total, |
| 46 |
used => $used, |
| 47 |
free => $free, |
| 48 |
prct_used => $prct_used, |
| 49 |
prct_free => $prct_free, |
| 50 |
memShared => ($options{result}->{memShared}) ? $options{result}->{memShared} * 1024 : 0, |
| 51 |
memBuffer => $buffer, |
| 52 |
memCached => $cached, |
| 53 |
}; |
| 54 |
} |
| 55 |
|
| 56 |
1; |
| 57 |
|
| 58 |
__END__ |
| 59 |
|
| 60 |
=head1 MODE |
| 61 |
|
| 62 |
Check memory usage (UCD-SNMP-MIB). |
| 63 |
|
| 64 |
=over 8 |
| 65 |
|
| 66 |
=item B<--units> |
| 67 |
|
| 68 |
Units of thresholds (default: '%') ('%', 'absolute'). |
| 69 |
|
| 70 |
=item B<--free> |
| 71 |
|
| 72 |
Thresholds are on free space left. |
| 73 |
|
| 74 |
=item B<--swap> |
| 75 |
|
| 76 |
Check swap also. |
| 77 |
|
| 78 |
=item B<--warning-*> |
| 79 |
|
| 80 |
Warning threshold. |
| 81 |
Can be: 'usage', 'swap', 'buffer' (absolute), |
| 82 |
'cached' (absolute), 'shared' (absolute). |
| 83 |
|
| 84 |
=item B<--critical-*> |
| 85 |
|
| 86 |
Critical threshold. |
| 87 |
Can be: 'usage', 'swap', 'buffer' (absolute), |
| 88 |
'cached' (absolute), 'shared' (absolute). |
| 89 |
|
| 90 |
=back |
| 91 |
|
| 92 |
=cut |