mariog has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have the following code to monitor the real physical memory usage in a Linux Appliance.
I want to include in the free memory the buffers and cache instead of just the free that is returned by snmp
I am wondering how to calculate the real free percentage without using the temp variables (buffers. cache, free, total). I use those to extract the values returned by Net::SNMP and be able to calculate the percentage.use strict; use warnings; use Net::SNMP; use Nagios::Plugin; use nagios::Plugin::Getopt; my $memRealTotalOID = '.1.3.6.1.4.1.2021.4.5.0'; my $memRealFreeOID = '.1.3.6.1.4.1.2021.4.6.0'; my $memRealCachedOID = '.1.3.6.1.4.1.2021.4.15.0'; my $memRealBuffersOID = '.1.3.6.1.4.1.2021.4.14.0'; my ($session, $error) = Net::SNMP->session( -hostname => shift || '192.168.1.1', -community => shift || 'private', ); if (!defined $session) { printf "ERROR: %s.\n", $error; exit 1; } my $memRealFree = $session->get_request(-varbindlist => [ $memRealF +reeOID],); my $memRealTotal = $session->get_request(-varbindlist => [ $memReal +TotalOID],); my $memRealCached = $session->get_request(-varbindlist => [ $memRea +lCachedOID],); my $memRealBuffers = $session->get_request(-varbindlist => [ $memRe +alBuffersOID],); my $buffers = $memRealBuffers->{$memRealBuffersOID}; my $cache = $memRealCached->{$memRealCachedOID}; my $total= $memRealTotal->{$memRealTotalOID}; my $free = $memRealFree->{$memRealFreeOID}; my $memRealUsed = $total - $free; my $realPercent = (($memRealUsed - $buffers - $cache)/ $total) * 100 +;
my final purpose is to create a nagios plugin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: best way to monitor real memory usage on linux
by anonymized user 468275 (Curate) on Aug 06, 2015 at 13:46 UTC | |
by mariog (Acolyte) on Aug 06, 2015 at 14:11 UTC | |
by anonymized user 468275 (Curate) on Aug 06, 2015 at 15:41 UTC | |
by mariog (Acolyte) on Aug 06, 2015 at 16:13 UTC | |
by anonymized user 468275 (Curate) on Aug 06, 2015 at 19:36 UTC | |
|