Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Check memory and swap usage on Windows or Linux Server using SNMP queries
2.0
2018-06-02
- Nagios 3.x
- Nagios 4.x
GPL
245712
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
check_snmp_memory is written in Bash and is distributed under the GPLv2 license. This plugin have been created by Yoann LAMY.
Usage: ./check_snmp_memory -H xxx.xxx.xxx.xxx -C public -w 80 -c 90
-H ADDRESS
Name or IP address of host (default: 127.0.0.1)
-C STRING
Community name for the host's SNMP agent (default: public)
-w INTEGER
Warning level for memory in percent (default: 0)
-c INTEGER
Critical level for memory in percent (default: 0)
-h
Print this help screen
-V
Print version and license information
This plugin uses the 'snmpget' command included with the NET-SNMP package.
This plugin support performance data output. If the percentage of the warning and critical levels are set to 0, then the script returns a OK state.
This nagios plugins comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of the plugins under the terms of the GNU General Public License v2.
Usage: ./check_snmp_memory -H xxx.xxx.xxx.xxx -C public -w 80 -c 90
-H ADDRESS
Name or IP address of host (default: 127.0.0.1)
-C STRING
Community name for the host's SNMP agent (default: public)
-w INTEGER
Warning level for memory in percent (default: 0)
-c INTEGER
Critical level for memory in percent (default: 0)
-h
Print this help screen
-V
Print version and license information
This plugin uses the 'snmpget' command included with the NET-SNMP package.
This plugin support performance data output. If the percentage of the warning and critical levels are set to 0, then the script returns a OK state.
This nagios plugins comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of the plugins under the terms of the GNU General Public License v2.
Reviews (6)
bynereid, December 9, 2014
On linux system this plugin creates false alerts by exceeding thresholds without any reason. The way the memory usage is calclulated is just plain wrong. It tries to tell us that most systems have 98% usage just because the buffers for I/O are using them but they have to be subtracted before taking the thresholds into account.
byadbrennick, December 11, 2013
I have this plugin up and running and it works really well. One issue that I am having is that I cannot get the Warning and Critical state to trigger an alarm. I have -w 80 -c 90 set and I have a server at 98% ram utilization, but the status in Nagios shows as Green status. Any suggestions?
bycristiano.caruso, June 30, 2013
I do some change to the script to support faulty Windows 2000.
Defined 2 new OID:
OID_TOTAL_W2K="HOST-RESOURCES-MIB::hrMemorySize"
OID_USED_W2K="HOST-RESOURCES-MIB::hrSWRunPerfMem"
and then added after
MEMORY_USED_ID=`$CMD_SNMPWALK -t 2 -r 2 -v 1 -c $COMMUNITY $HOSTNAME $OID_TAGMEMORY | $CMD_GREP -i 'Physical Memory\|Real Memory' | $CMD_AWK '{ print $1}' | $CMD_AWK -F "." '{print $NF}'`
this test:
if [ -z "$MEMORY_USED_ID" ]; then
MEMORY_USED_ID="0"
fi
finally, in main block:
if [ $MEMORY_USED_ID != "0" ]; then
MEMORY_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${MEMORY_USED_ID}`
SWAP_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${SWAP_USED_ID}`
MEMORY_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${MEMORY_USED_ID}`
SWAP_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${SWAP_USED_ID}`
MEMORY_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${MEMORY_USED_ID}`
SWAP_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${SWAP_USED_ID}`
else
# Windows 2000
MEMORY_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL_W2K}.0`
SWAP_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${SWAP_USED_ID}`
MEMORY_UNIT=1024
SWAP_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${SWAP_USED_ID}`
MEMORY_USED=`$CMD_SNMPWALK -t 2 -r 2 -v 1 -c $COMMUNITY $HOSTNAME ${OID_USED_W2K} | cut -f 4 -d " " |paste -sd+|bc`
SWAP_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${SWAP_USED_ID}`
fi
Maybe isn't best way, but t works.
Regards
Cristiano
Defined 2 new OID:
OID_TOTAL_W2K="HOST-RESOURCES-MIB::hrMemorySize"
OID_USED_W2K="HOST-RESOURCES-MIB::hrSWRunPerfMem"
and then added after
MEMORY_USED_ID=`$CMD_SNMPWALK -t 2 -r 2 -v 1 -c $COMMUNITY $HOSTNAME $OID_TAGMEMORY | $CMD_GREP -i 'Physical Memory\|Real Memory' | $CMD_AWK '{ print $1}' | $CMD_AWK -F "." '{print $NF}'`
this test:
if [ -z "$MEMORY_USED_ID" ]; then
MEMORY_USED_ID="0"
fi
finally, in main block:
if [ $MEMORY_USED_ID != "0" ]; then
MEMORY_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${MEMORY_USED_ID}`
SWAP_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${SWAP_USED_ID}`
MEMORY_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${MEMORY_USED_ID}`
SWAP_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${SWAP_USED_ID}`
MEMORY_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${MEMORY_USED_ID}`
SWAP_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${SWAP_USED_ID}`
else
# Windows 2000
MEMORY_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL_W2K}.0`
SWAP_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_TOTAL}.${SWAP_USED_ID}`
MEMORY_UNIT=1024
SWAP_UNIT=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_UNIT}.${SWAP_USED_ID}`
MEMORY_USED=`$CMD_SNMPWALK -t 2 -r 2 -v 1 -c $COMMUNITY $HOSTNAME ${OID_USED_W2K} | cut -f 4 -d " " |paste -sd+|bc`
SWAP_USED=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -OvqU $HOSTNAME ${OID_USED}.${SWAP_USED_ID}`
fi
Maybe isn't best way, but t works.
Regards
Cristiano
It needs only one change when deciding whether to notify for WARNING or CRITICAL status:
------------------------
instead of:
if [ $MEMORY_USED_REAL_POURCENT -gt $WARNING ] && [ $WARNING != 0 ]; then
STATE=$STATE_WARNING
this line shall be like this:
if [ $MEMORY_USED_REAL_POURCENT -gt $WARNING ] && [ $MEMORY_USED_REAL_POURCENT -lt $CRITICAL ] && [ $WARNING != 0 ]; then
STATE=$STATE_WARNING
----------------------------
Also, the value for size should be changed from Go to GB.
------------------------
instead of:
if [ $MEMORY_USED_REAL_POURCENT -gt $WARNING ] && [ $WARNING != 0 ]; then
STATE=$STATE_WARNING
this line shall be like this:
if [ $MEMORY_USED_REAL_POURCENT -gt $WARNING ] && [ $MEMORY_USED_REAL_POURCENT -lt $CRITICAL ] && [ $WARNING != 0 ]; then
STATE=$STATE_WARNING
----------------------------
Also, the value for size should be changed from Go to GB.
Owner's reply
Thank you, it is corrected.
Regards.
byMajed, December 13, 2011
on a 12 GB memory produces an error:
./check_snmp_memory.txt -H 172.16.1.100 -C snmp -w 80 -c 90
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
Memory usage : Go used for a total of Go (92%), SWAP usage : Go used for a total of Go (45%)| total=12873891840B;10299113472;11586502656;0 used=11957960704B;0;0;0 swap=12575440896B;0;0;0 buffer=0B;0;0;0 cache=0B;0;0;0
./check_snmp_memory.txt -H 172.16.1.100 -C snmp -w 80 -c 90
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
./check_snmp_memory.txt: line 123: /usr/bin/bc: No such file or directory
Memory usage : Go used for a total of Go (92%), SWAP usage : Go used for a total of Go (45%)| total=12873891840B;10299113472;11586502656;0 used=11957960704B;0;0;0 swap=12575440896B;0;0;0 buffer=0B;0;0;0 cache=0B;0;0;0
Owner's reply
This error indicates that the command bc was not found.
- yum install bc
- whereis bc
Regards.
byn0ts, July 21, 2011
This plugins is very useful.
I support procotol version.
https://gist.github.com/1097533
Thanks.
I support procotol version.
https://gist.github.com/1097533
Thanks.