Memory

check_mem.sh

Description:

check_mem is a bash script that checks buffer, cache and used memory with performance data enable

Current Version

2.0

Last Release Date

2015-07-14

Compatible With

  • Nagios 2.x
  • Nagios 3.x

Owner

License

GPL


Project Files
Project Photos
Project Notes
root@localhost # ./check_mem [MEMORY] Total: 7713 MB - Used: 2402 MB - 31% [SWAP] Total: 8189 MB - Used: 0 MB - 0% | MTOTAL=8087736320;;;; MUSED=2516549632;;;; MCACHE=2323607552;;;; MBUFFER=140218368;;;; STOTAL=8587833344;;;; SUSED=0;;;; To use it with nrpe: add command: # check_nrpe_memory define command { command_name check_nrpe_memory command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c memory } define service: # Memory define service { use default-service host_name some_host service_description Memory Usage check_command check_nrpe_memory } and define nrpe command: command[memory]=/opt/plugins/check_mem -w 80 -c 90
Reviews (8) Add a Review
Took some experimentation
by ScottH, May 31, 2020

Because I'm fairly inexperienced at managing Nagios, I had to hunt around to figure everything out. Hopefully this will be helpful to others: I added the command to objects/commands.cfg I added the service to servers/services.cfg I added the command to etc/nrpe.cfg on both the Nagios Server and the target Host I added a line to nrpe/common.cfg on both servers of: command[memory]=/usr/local/nagios/libexec/check_mem $ARG1$ $ARG2$ I restarted nrpe (xinetd) on the target host(s) with: sudo systemctl restart xinetd I restarted nagios on the nagios server sudo systemctl restart nagios



free output gets truncated
by Fonant, September 30, 2015

Nice script, however I've noticed that my server with 16G of RAM results in the "total" value in bytes from the "free" command being truncated: a bug in "free" rather this script. This results in erroneous values from this script, and the "USED" value can go negative. I've updated my copy so it uses kilobytes instead of bytes for the fine-resolution numbers.



The plugin works, but
by dot, November 30, 2014

Why do you call 'free' eight times? Why not 100? substitute this stuff " memTotal_b=`free -b |grep Mem |awk '{print $2}'` memFree_b=`free -b |grep Mem |awk '{print $4}'` memBuffer_b=`free -b |grep Mem |awk '{print $6}'` memCache_b=`free -b |grep Mem |awk '{print $7}'` memTotal_m=`free -m |grep Mem |awk '{print $2}'` memFree_m=`free -m |grep Mem |awk '{print $4}'` memBuffer_m=`free -m |grep Mem |awk '{print $6}'` memCache_m=`free -m |grep Mem |awk '{print $7}'` " with mem=`free -m |grep Mem` and "free -m |grep Mem" with echo $mem



works nice
by niemi, November 30, 2014

Nagios 3.0.6 making some changes, remove some spaces and ";" and it works on my nagios. Thanks to Athor! ======================================[code]======================= #!/bin/bash if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then memTotal_b=`free -b |grep Mem |awk '{print $2}'` memFree_b=`free -b |grep Mem |awk '{print $4}'` memBuffer_b=`free -b |grep Mem |awk '{print $6}'` memCache_b=`free -b |grep Mem |awk '{print $7}'` memTotal_m=`free -m |grep Mem |awk '{print $2}'` memFree_m=`free -m |grep Mem |awk '{print $4}'` memBuffer_m=`free -m |grep Mem |awk '{print $6}'` memCache_m=`free -m |grep Mem |awk '{print $7}'` memUsed_b=$(($memTotal_b-$memFree_b-$memBuffer_b-$memCache_b)) memUsed_m=$(($memTotal_m-$memFree_m-$memBuffer_m-$memCache_m)) memUsedPrc=$((($memUsed_b*100)/$memTotal_b)) if [ "$memUsedPrc" -ge "$4" ]; then echo "Memory: CRITICAL Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|Total=$memTotal_b;;;Used=$memUsed_b;;;Cache=$memCache_b;;;Buffer=$memBuffer_b;;;" $(exit 2) elif [ "$memUsedPrc" -ge "$2" ]; then echo "Memory: WARNING Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|Total=$memTotal_b;;;Used=$memUsed_b;;;Cache=$memCache_b;;;Buffer=$memBuffer_b;;;" $(exit 1) else echo "Memory: OK Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used|Total=$memTotal_b;;;Used=$memUsed_b;;;Cache=$memCache_b;;Buffer=$memBuffer_b;;;" $(exit 0) fi else echo "check_mem v1.1" echo "" echo "Usage:" echo "check_mem.sh -w -c " echo "" echo "warnlevel and critlevel is percentage value without %" echo "" echo "Copyright (C) 2012 Lukasz Gogolin (lukasz.gogolin@gmail.com)" exit fi ======================================[code]=======================



Work great and have made some improvements
by whereisaaron, April 30, 2014

I tested this plug-in and liked it a lot. There are others but this one doesn't have any dependencies other than 'bash' and 'free', and makes a nice chart. I felt it was a little inefficient so I made some tweaks to reduce the number of forks required. I also tweaked the chart. My changes are on Github. https://github.com/whereisaaron/linux-check-mem-nagios-plugin



Works great
by HFroyen, October 31, 2013

I also cat the check_mem.sh and touch new file and paste it in. In the nrpe_local.cfg I put /path/to/plugins/check_mem.sh -w value -c value I put the PHP file in the pnp-templates path, made command and service definition. Is it also possible to do this for Windows Servers via NSClient++ or NSCP? Great job on this!



Super, but how do I create a consolidated graph?
by Admin_UCOP, March 31, 2013

Love the plugin and its very useful. Only in my setup it produces separate graphs for every type of memory metric. On your sample image you have a consolidated graphs where different metrics are shown in different colors. How did you do it? Thanks in advance!



very nice pnp charts
by dick, January 31, 2013

This plugin works nicely with very good looking pnp charting support. Only problems I had were not related to the code itself. The check_mem.sh script download comes in a weird encoding that does not work in Linux. check_mem.sh: UTF-8 Unicode (with BOM) text, with CRLF line terminators I didn't feel like looking around to convert this so I just cat the file and pasted into a new file, which worked fine. Also note that the pnp template file, check_nrpe_memory.php, should be moved to /etc/pnp4nagios/templates or where your pnp configs are set to. Also unless you name the check nrpe_memory, you're going to have to rename the file to check_.php Thanks for the great plugin and pnp template.



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.2 (9)
Favorites
0
Views
145,470