Page 1 of 1

check_mem warning question

Posted: Wed Oct 01, 2014 10:21 am
by cshaffer
I saw the same question for a CentOS install. This question is about an Ubuntu install. The check_mem command returns a warning even though when I check with free -mt there appears to be plenty of available memory.

Re: check_mem warning question

Posted: Wed Oct 01, 2014 10:29 am
by cshaffer
The check_mem command is using the thresholds of -w 20 -c 10. This indicates that it is looking at the available free space. Running free -mt on the remote host shows total 3910 and free 2221. The error message shows the same 2221/3910 Free Memory. This is about 57% free memory. Don't understand the warning.

Re: check_mem warning question

Posted: Wed Oct 01, 2014 2:20 pm
by lmiltchev
I believe the actual command that is used is "custom_check_mem". You can pass the "-n" (--nocache) flag, which should give you more accurate reading. For more info, please, read this post:

http://support.nagios.com/wiki/index.ph ... ree_Memory

Re: check_mem warning question

Posted: Wed Oct 01, 2014 3:20 pm
by cshaffer
When I tried custom_check_mem it said "Command custom_check_mem not defined." I tried the -n with the check_mem command and it threw the waning again.

Re: check_mem warning question

Posted: Wed Oct 01, 2014 3:42 pm
by sreinhardt
Can you give us the full command arguments as you have them defined, a full output from running that command on your system, and a full output from free please?

Re: check_mem warning question

Posted: Thu Oct 02, 2014 8:06 am
by cshaffer
I used the Linux monitoring wizard to set this up. This is what is in the "Monitor the service with this command" box.
check_nrpe!check_mem!-a '-w 20 -c 10'!!!!!!

Ran a test in the core configuration for this command and got this.
COMMAND: /usr/local/nagios/libexec/check_nrpe -H 10.206.201.37 -t 30 -c check_mem -a '-w 20 -c 10'
OUTPUT: WARNING - 2293 / 3910 MB (%) Free Memory, Used: 1617 MB, Shared: 21 MB, Buffers: 211 MB, Cached: 612 MB | total=3910MB free=2293MB used=1617MB shared=21 buffers=211MB cached=612MB

Doing free -mt on the monitored host gives
cshaffer@SVQCWS1:~$ free -mt
total used free shared buffers cached
Mem: 3910 1616 2293 21 211 612
-/+ buffers/cache: 791 3118
Swap: 11683 0 11683
Total: 15594 1616 13977

The output of the command matches the free -mt output. Total 3910, Free 2293. Even without the cached memory, this is 59% free. I can only assume the warning message is an error?

Re: check_mem warning question

Posted: Thu Oct 02, 2014 10:08 am
by cshaffer
I am looking at the /usr/lib/nagios/plugins/custom_check_mem bash script. I suspect that the section of code below is where the problem is. Specifically, in the percent calculation. I've done Unix scripting before, but I have to admit that I don't understand sed and gawk well enough to follow the calculation entirely. I'm familiar enough with reverse polish to see that it is dividing the free amount by total amount and taking that times 100. I don't follow why the scaling factor is needed ( k 5). Is it possible that the scaling is making the percent variable too small and it is causing the if [[ "$percent" -le $warning ]] to evaluate to false and print the Warning message?

# make it into % percent free = ((free mem / total mem) * 100)
echo "5" > $calc # decimal accuracy
echo "k" >> $calc # commit
echo "100" >> $calc # multiply
echo "$free" >> $calc # division integer
echo "$total" >> $calc # division integer
echo "/" >> $calc # division sign
echo "*" >> $calc # multiplication sign
echo "p" >> $calc # print
percent=`/usr/bin/dc $calc|/bin/sed 's/^\./0./'|/usr/bin/tr "." " "|/usr/bin/gawk {'print $1'}`
#percent1=`/usr/bin/dc $calc`
#echo "$percent1"
if [[ "$percent" -le $critical ]]
then
string="CRITICAL"
result=2
fi
if [[ "$percent" -le $warning ]]
then
string="WARNING"
result=1
fi
if [[ "$percent" -gt $warning ]]
then
string="OK"
result=0
fi

Re: check_mem warning question

Posted: Thu Oct 02, 2014 2:00 pm
by lmiltchev
What is the OS/Distro of the client machine? You will have to iinstall bc (or dc) - I can't remember exactly which one was needed on what distro.

The percentage number is missing in your output...
OUTPUT: WARNING - 2293 / 3910 MB (%) Free Memory, Used: 1617 MB, Shared: 21 MB, Buffers: 211 MB, Cached: 612 MB | total=3910MB free=2293MB used=1617MB shared=21 buffers=211MB cached=612MB

Re: check_mem warning question

Posted: Thu Oct 02, 2014 2:49 pm
by cshaffer
That was it. The server is running Ubuntu and did not have the dc utility installed. I ran sudo apt-get dc and it was installed. Now the test button works. Thanks a lot.