Memory

Check mem (by Nestor@Toronto)

Description:

** Please note that this script was originally written by Lukasz Gogolin (lukasz.gogolin@gmail.com). I only i proved and bug fix to make sure it run smoothly.

Script were written in BASH, tested on CentOS 6.X, Nagios 3.X

Current Version

v1.0

Last Release Date

August 21, 2015

Compatible With

Owner


Project Files
Project Notes
Reviews (3) Add a Review
New version using /proc/meminfo available
by whereisaaron, March 31, 2018

This is a great script that various people have improved. I've been using a forked version on github for some years. We recently improved it to use '/proc/meminfo' output so it its less brittle to changes in 'free' output. So it works with almost all Linux releases/versions. Small improvements to the chart also. https://github.com/whereisaaron/linux-check-mem-nagios-plugin



Modification for CentOS/RHEL 6.x Buffer and Cache
by Petaris, January 31, 2016

Hi, Here is a modification for more accurate results on CentOS/RHEL 6.x. This changes the memUsed_m variable to use a custom calculation instead of just using the Used number from free -m. This is similar to what the other reviewer did for 7.x systems. It uses the number from memTotal_m and then subtracts memFree_m, memBuffer_m, and memCache_m to come up with memUsed_m. You need to comment the original memUsed_m line then add a line after memCache_m as shown: memTotal_m=`echo "$FreeM" |grep Mem |awk '{print $2}'` # Comment This Line #memUsed_m=`echo "$FreeM" |grep Mem |awk '{print $3}'` memFree_m=`echo "$FreeM" |grep Mem |awk '{print $4}'` memBuffer_m=`echo "$FreeM" |grep Mem |awk '{print $6}'` memCache_m=`echo "$FreeM" |grep Mem |awk '{print $7}'` #Add the following line: memUsed_m=$(($memTotal_m-$memFree_m-$memBuffer_m-$memCache_m)) memUsedPrc=`echo $((($memUsed_m*100)/$memTotal_m))||cut -d. -f1` Thanks for the great plugin!



Modified a bit for Centos7
by bikram, December 31, 2015

Centos 7 Free command output changed a bit, plus I would count cached memory as free. #!/bin/bash if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then FreeM=`free -m` memTotal_m=`echo "$FreeM" |grep Mem |awk '{print $2}'` memUsed_m=`echo "$FreeM" |grep Mem |awk '{print $3}'` memFree_m=`echo "$FreeM" |grep Mem |awk '{print $4}'` memBuffer_cache_m=`echo "$FreeM" |grep Mem |awk '{print $6}'` memAvailable_m=`echo "$FreeM" |grep Mem |awk '{print $7}'` memUsed_m=$(($memTotal_m-$memFree_m-$memBuffer_cache_m)) memUsedPrc=`echo $((($memUsed_m*100)/$memTotal_m))||cut -d. -f1` if [ "$memUsedPrc" -ge "$4" ]; then echo "Memory: CRITICAL Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; BUFFER/CACHE=$memBuffer_cache_m;;;; AVAILABLE=$memAvailable_m;;;;" exit 2 elif [ "$memUsedPrc" -ge "$2" ]; then echo "Memory: WARNING Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; BUFFER/CACHE=$memBuffer_cache_m;;;; AVAILABLE=$memAvailable_m;;;;" exit 1 else echo "Memory: OK Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; BUFFER/CACHE=$memBuffer_cache_m;;;; AVAILABLE=$memAvailable_m;;;;" exit 0 fi else # If inputs are not as expected, print help. sName="`echo $0|awk -F '/' '{print $NF}'`" echo -e "nntt### $sName Version 2.1###n" echo -e "# Usage:t$sName -w -c " echo -e "tt= warnlevel and critlevel is percentage value without %n" echo "# EXAMPLE:t/usr/lib64/nagios/plugins/$sName -w 80 -c 90" echo -e "nCopyright (C) 2012 Lukasz Gogolin (lukasz.gogolin@gmail.com), improved by Nestor 2015nn" exit fi



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.3 (4)
Favorites
0
Views
19,557