• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

AI, Linux, Cloud and DevOps

  • Home
  • Resources
    • Learn Linux
    • Articles
  • My Projects & Work
    • My Nagios Plugin
    • My Dockerhub Repo
    • My WordPress plugins
    • My Github Repos
  • Facebook Page
  • Contact
  • Privacy Policy
  • About Me
You are here: Home / Articles / check_memory unable to read output Nagios nrpe

check_memory unable to read output Nagios nrpe

July 2, 2013 by Sharad Chhetri Leave a Comment

check_memory unable to read output Nagios nrpe

While setting up the nagios Monitoring system in my new network.I decided to use check_memory plugin. I downloaded the plugin from exchange.nagios.com
Here below one is given link.
check_mem_avail

While working I got this error from check_memory plugin “NRPE : unable to read output” . After debugging I found the NRPE was not able to read the output from check_memory plugin because of in if statement in bash script [[ ]] was used,so I modify it to [ ] .

To implement the check_memory plugin gawk and bc command should work.So I installed the gawk and bc command in system

apt-get install gawk bc

Now copy paste the given below code and make a file check_memory and give it execute permission by command chmod 755 check_memory .And put it at nagios plugin directory. In my case it is /usr/lib/nagios/plugins


vi check_memory

# $Id: check_mem,v 1.3 2008/09/17 21:47:03 nagios Exp nagios $
#
#  Revision 1.4  2013/07/02 02:09 PM IST  nagios
#   Author : sharad kumar chhetri (for revision 1.4)
#
# $Log: check_mem,v $
# Revision 1.3  2008/09/17 21:47:03  nagios
# dropped free in favor of using /proc/meminfo
#
# Revision 1.2  2008/09/17 21:00:24  nagios
# added usage statement and input validation from http://www.nagiosexchange.org/cgi-bin/page.cgi?g=2099.html;d=1
# respects to the author
#
# Revision 1.1  2008/09/17 20:57:38  nagios
# Initial revision
#
# This plugin excludes the system cache and buffer, because on systems with stable memory
# usage it is perfectly normal for system cache to fill in all available memory
# (most of it can be freed at any time if applications requires it).
# Please keep a margin for system cache and buffers when setting thresholds.
#
#!/bin/bash
USAGE="`basename $0` [-w|--warning] [-c|--critical]"
THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"

# print usage
if [ $# -lt 4 ]
then
	echo ""
	echo "Wrong Syntax: `basename $0` $*"
	echo ""
	echo "Usage: $USAGE"
	echo ""
	exit 0
fi
# read input
while [ $# -gt 0 ]
  do
        case "$1" in
               -w|--warning)
               shift
               warning=$1
        ;;
               -c|--critical)
               shift
               critical=$1
        ;;
        esac
        shift
  done
# verify input
if [[ $warning -eq $critical || $warning -lt $critical ]]
then
	echo ""
	echo "$THRESHOLD_USAGE"
	echo ""
        echo "Usage: $USAGE"
	echo ""
        exit 0
fi

# Total physical memory
total=`cat /proc/meminfo |head -n 1 |tail -n 1| gawk '{print $2}'`

# Free physical memory
free=`cat /proc/meminfo |head -n 2 |tail -n 1| gawk '{print $2}'`

# Buffers
buffers=`cat /proc/meminfo |head -n 3 |tail -n 1| gawk '{print $2}'`

# Cached
cached=`cat /proc/meminfo |head -n 4 |tail -n 1| gawk '{print $2}'`

#Available physical memory
available=`echo "$free+$buffers+$cached" | bc`

# make it into % percent free = ((free mem / total mem) * 100)
percent=`echo "scale=2; $available/$total*100" | bc`

#echo $total
#echo $free
#echo $buffers
#echo $cached
#echo $available
#echo $percent

#echo $critical
#echo $warning

#echo `echo "$percent <=  $critical"|bc`
#echo `echo "$percent <=  $warning"|bc`
#echo `echo "$percent >  $warning"|bc`

if [ "`echo "$percent <=  $critical"|bc`" -eq 1 ]
	then
		echo "CRITICAL - $available KB ($percent%) Free Memory"
		exit 2
fi
if [ "`echo "$percent <=  $warning"|bc`" -eq 1 ]
        then
                echo "WARNING - $available KB ($percent%) Free Memory"
                exit 1
fi
if [ "`echo "$percent >  $warning"|bc`" -eq 1 ]
        then
                echo "OK - $availabe KB ($percent%) Free Memory"
                exit 0
fi

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • More
  • Print (Opens in new window) Print
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon

Articles

Nagios Plugin : check ssl certificate expiry date
How to install Nagios 4 from source on Ubuntu 14.04 LTS
Xen Server License Nagios Plugin (bash script)
Install and configure nagios core 4 on Ubuntu 12.04 LTS
Nagios monitoring on AWS Autoscaling group instances
Install nagios 4.0.2 in CentOS 6 using tarball
Installing Nagios-3.4 in CentOS 6.3
How to install and configure nagios nrpe in CentOS and Red Hat
Installing Nagios-3.4.4 in CentOS 6.3
Installing Nagios-3.5.0 in CentOS 6.4 using yum
How to install Nagios on CentOS 7 / RHEL 7
How to change the frontend of Nagios with VShell in Ubuntu and Debian
How to install and configure nagios nrpe client in Ubuntu with apt-get command
Install vshell frontend on Nagios Core 4 Ubuntu 12.04 LTS
Managing Jenkins plugins : command and GUI

Filed Under: Articles, Monitoring Server Tagged With: Nagios

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Articles

  • Install n8n docker in Ubuntu for practicing
  • Bash Script: MySQL Database backup to AWS S3
  • Automate no touch Jenkins setup wizard on docker (jcac)
  • How to run and configure Jenkins in Docker container
  • Complete Guide: How to install Nagios Monitoring on AlmaLinux / Rocky Linux
  • Install KVM on Ubuntu 24.04 LTS ( Bash Script )
  • How to install GIMP 2.10 on Ubuntu / Debian
  • 5 ways to check Ubuntu version of system (commands and GUI)
  • How To Solve Forgot MySQL / MariaDB Root Password
  • Create Self Hosted Build Agent Docker Image for Azure DevOps

Copyright © 2026 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From India.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy