Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_mem.sh
2.0
2015-07-14
- Nagios 2.x
- Nagios 3.x
GPL
146207
File | Description |
---|---|
check_mem | Nagios plugin |
check_mem.php | pnp template |
check_mem.png | check_mem.png |
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!
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
[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)
byScottH, May 22, 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
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
byFonant, September 2, 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.
I've updated my copy so it uses kilobytes instead of bytes for the fine-resolution numbers.
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
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
byniemi, November 5, 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]=======================
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]=======================
bywhereisaaron, April 12, 2014
1 of 1 people found this review helpful
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
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
byHFroyen, October 17, 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!
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!
byAdmin_UCOP, March 19, 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!
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.
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.