Change method: use UCD and special memories information (not the storage)
This commit is contained in:
garnier-quentin 2013-12-15 21:53:02 +01:00
parent a79f10173c
commit 6b9bd382d8
4 changed files with 33 additions and 84 deletions

View File

@ -51,9 +51,11 @@ sub new {
'load' => 'snmp_standard::mode::loadaverage',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages',
'memory' => 'snmp_standard::mode::memory',
'packet-errors' => 'snmp_standard::mode::packeterrors',
'processcount' => 'snmp_standard::mode::processcount',
'storage' => 'snmp_standard::mode::storage',
'swap' => 'snmp_standard::mode::swap',
'traffic' => 'snmp_standard::mode::traffic',
'uptime' => 'snmp_standard::mode::uptime',
);
@ -68,6 +70,6 @@ __END__
=head1 PLUGIN DESCRIPTION
Check Freebsd operating systems in SNMP.
Some modes ('cpu', 'load') needs 'bsnmp-ucd'.
Some modes ('cpu', 'load, 'swap', 'memory') needs 'bsnmp-ucd'.
=cut

View File

@ -33,7 +33,7 @@
#
####################################################################################
package os::linux::plugin;
package os::freebsd::plugin;
use strict;
use warnings;
@ -52,11 +52,11 @@ sub new {
'load' => 'snmp_standard::mode::loadaverage',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages',
'memory' => 'os::linux::mode::memory',
'memory' => 'snmp_standard::mode::memory',
'packet-errors' => 'snmp_standard::mode::packeterrors',
'processcount' => 'snmp_standard::mode::processcount',
'storage' => 'snmp_standard::mode::storage',
'swap' => 'os::linux::mode::swap',
'swap' => 'snmp_standard::mode::swap',
'traffic' => 'snmp_standard::mode::traffic',
'uptime' => 'snmp_standard::mode::uptime',
);

View File

@ -33,7 +33,7 @@
#
####################################################################################
package os::linux::mode::memory;
package snmp_standard::mode::memory;
use base qw(centreon::plugins::mode);
@ -51,10 +51,6 @@ sub new {
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
$self->{cached_memory_id} = undef;
$self->{buffer_memory_id} = undef;
$self->{physical_memory_id} = undef;
return $self;
}
@ -78,51 +74,23 @@ sub run {
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $oid_hrStorageDescr = '.1.3.6.1.2.1.25.2.3.1.3';
my $oid_memTotalReal = '.1.3.6.1.4.1.2021.4.5.0';
my $oid_memAvailReal = '.1.3.6.1.4.1.2021.4.6.0';
my $oid_memShared = '.1.3.6.1.4.1.2021.4.13.0';
my $oid_memBuffer = '.1.3.6.1.4.1.2021.4.14.0';
my $oid_memCached = '.1.3.6.1.4.1.2021.4.15.0';
my $result = $self->{snmp}->get_table(oid => $oid_hrStorageDescr);
foreach my $key (keys %$result) {
next if ($key !~ /\.([0-9]+)$/);
my $oid = $1;
if ($result->{$key} =~ /^Physical memory$/i) {
$self->{physical_memory_id} = $oid;
}
if ($result->{$key} =~ /^Cached memory$/i) {
$self->{cached_memory_id} = $oid;
}
if ($result->{$key} =~ /^Memory buffers$/i) {
$self->{buffer_memory_id} = $oid;
}
}
if (!defined($self->{physical_memory_id})) {
$self->{output}->add_option_msg(short_msg => "Cannot find physical memory informations.");
$self->{output}->option_exit();
}
if (!defined($self->{cached_memory_id})) {
$self->{output}->add_option_msg(short_msg => "Cannot find cached memory informations.");
$self->{output}->option_exit();
}
if (!defined($self->{buffer_memory_id})) {
$self->{output}->add_option_msg(short_msg => "Cannot find buffer memory informations.");
$self->{output}->option_exit();
}
my $oid_hrStorageAllocationUnits = '.1.3.6.1.2.1.25.2.3.1.4';
my $oid_hrStorageSize = '.1.3.6.1.2.1.25.2.3.1.5';
my $oid_hrStorageUsed = '.1.3.6.1.2.1.25.2.3.1.6';
my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalReal, $oid_memAvailReal,
$oid_memShared, $oid_memBuffer, $oid_memCached],
nothing_quit => 1);
$self->{snmp}->load(oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed],
instances => [$self->{physical_memory_id}, $self->{cached_memory_id}, $self->{buffer_memory_id}]);
$result = $self->{snmp}->get_leef();
my $cached_used = $result->{$oid_hrStorageUsed . "." . $self->{cached_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{cached_memory_id}};
my $buffer_used = $result->{$oid_hrStorageUsed . "." . $self->{buffer_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{buffer_memory_id}};
my $physical_used = $result->{$oid_hrStorageUsed . "." . $self->{physical_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{physical_memory_id}};
my $shared_used = $result->{$oid_memShared} * 1024;
my $cached_used = $result->{$oid_memCached} * 1024;
my $buffer_used = $result->{$oid_memBuffer} * 1024;
my $physical_used = ($result->{$oid_memTotalReal} * 1024) - ($result->{$oid_memAvailReal} * 1024);
my $nobuf_used = $physical_used - $buffer_used - $cached_used;
my $total_size = $result->{$oid_hrStorageSize . "." . $self->{physical_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{physical_memory_id}};
my $total_size = $result->{$oid_memTotalReal} * 1024;
my $prct_used = $nobuf_used * 100 / $total_size;
my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
@ -130,12 +98,14 @@ sub run {
my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used);
my ($buffer_value, $buffer_unit) = $self->{perfdata}->change_bytes(value => $buffer_used);
my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used);
my ($shared_value, $shared_unit) = $self->{perfdata}->change_bytes(value => $shared_used);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Ram used (-buffers/cache) %s (%.2f%%), Buffer: %s, Cached: %s",
short_msg => sprintf("Ram used (-buffers/cache) %s (%.2f%%), Buffer: %s, Cached: %s, Shared: %s",
$nobuf_value . " " . $nobuf_unit, $prct_used,
$buffer_value . " " . $buffer_unit,
$cached_value . " " . $cached_unit));
$cached_value . " " . $cached_unit,
$shared_value . " " . $shared_unit));
$self->{output}->perfdata_add(label => "cached",
value => $cached_used,
@ -159,7 +129,7 @@ __END__
=head1 MODE
Check Linux physical memory.
Check physical memory (UCD-SNMP-MIB).
=over 8

View File

@ -33,7 +33,7 @@
#
####################################################################################
package os::linux::mode::swap;
package snmp_standard::mode::swap;
use base qw(centreon::plugins::mode);
@ -51,8 +51,6 @@ sub new {
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
$self->{swap_memory_id} = undef;
return $self;
}
@ -75,34 +73,13 @@ sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{snmp} = $options{snmp};
my $oid_memTotalSwap = '.1.3.6.1.4.1.2021.4.3.0'; # KB
my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB
my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalSwap, $oid_memAvailSwap], nothing_quit => 1);
my $oid_hrStorageDescr = '.1.3.6.1.2.1.25.2.3.1.3';
my $result = $self->{snmp}->get_table(oid => $oid_hrStorageDescr);
foreach my $key (keys %$result) {
next if ($key !~ /\.([0-9]+)$/);
my $oid = $1;
if ($result->{$key} =~ /^Swap space$/i) {
$self->{swap_memory_id} = $oid;
}
}
if (!defined($self->{swap_memory_id})) {
$self->{output}->add_option_msg(short_msg => "Cannot find swap space informations.");
$self->{output}->option_exit();
}
my $oid_hrStorageAllocationUnits = '.1.3.6.1.2.1.25.2.3.1.4';
my $oid_hrStorageSize = '.1.3.6.1.2.1.25.2.3.1.5';
my $oid_hrStorageUsed = '.1.3.6.1.2.1.25.2.3.1.6';
$self->{snmp}->load(oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed],
instances => [$self->{swap_memory_id}]);
$result = $self->{snmp}->get_leef();
my $swap_used = $result->{$oid_hrStorageUsed . "." . $self->{swap_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{swap_memory_id}};
my $total_size = $result->{$oid_hrStorageSize . "." . $self->{swap_memory_id}} * $result->{$oid_hrStorageAllocationUnits . "." . $self->{swap_memory_id}};
my $swap_used = $result->{$oid_memAvailSwap} * 1024;
my $total_size = $result->{$oid_memAvailSwap} * 1024;
my $prct_used = $swap_used * 100 / $total_size;
my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
@ -133,7 +110,7 @@ __END__
=head1 MODE
Check Linux swap memory.
Check swap memory (UCD-SNMP-MIB).
=over 8