Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to configure nagios to perform memory check on a ubuntu server. I already have the basic configuration but when a try to start nagios, the following error message is displayed:

Service check command 'check_mem' specified in service 'Current Memory Usage' for host 'xxxx' not defined anywhere!

Besides commands.cfg, is there any possible place to define the command to be executed?

Thanks in advance, Best regards!

share|improve this question
commands.cfg is probably the best place to define check_mem, yes. was that what you wanted to know, or have i misunderstood the question? – MadHatter Oct 28 '10 at 15:16
The current configuration is based on an already existing one and I know for sure, that the command definition for memory checking is not placed on commands.cfg. – Rui Gonçalves Oct 28 '10 at 15:21
Yes, that's what NAGIOS is telling you: it's not defined anywhere. You need to define it. commands.cfg would be a good place to do that. Is that what you were asking? – MadHatter Oct 28 '10 at 15:26
I am asking if there is other possible file to place the command definition. As I said, I have a running configuration where the check_mem definitions is not placed on the file commands.cfg. – Rui Gonçalves Oct 28 '10 at 15:35
up vote 0 down vote accepted


ok, that's much clearer. The answer is that NAGIOS can take any valid configuration statement in any of its configuration files, and there can be an unlimited number of these. I have a NAGIOS server with 136 config files; any of those could contain a command definition.

So if you have a running configuration that has it defined somewhere, but not in commands.cfg, then the bad news is it could be in any of its config files, and these can be anywhere.

If I wanted to find it, I'd look in nagios.cfg to see what directories the config files live in, then automate the process of finding it, perhaps with

find /config/directory1 /config/directory2 /you-get-the-idea  -type f -exec grep check_mem {} /dev/null \;

and see what matches that finds.

share|improve this answer
Here is the result of the command execution for the /etc/nagios3/conf.d directory: /etc/nagios3/conf.d/localhost.cfg: check_command check_mem!7!3. Any more suggestions for a file/directory where the check_mem command may be located? – Rui Gonçalves Oct 28 '10 at 16:00
Rui, start with nagios.cfg, as I advised. That file likely lists all the other config files, or the directories where they live. You are running this on the server that has check_mem correctly set up, aren't you? – MadHatter Oct 28 '10 at 16:44
Thanks to you search suggestion, I had finally found the check_mem command definition. I executed the command find /etc/ -type f -exec grep check_mem {} /dev/null \; and the output was the directory and file were it was defined: /etc/nagios-plugins/config/memory.cfg. Thanks all for the help! – Rui Gonçalves Oct 29 '10 at 9:32
Glad to have helped! – MadHatter Oct 29 '10 at 10:55

most probably you want to use nagios nrpe server on monitored machine and define what plugin should execute this check.

btw maybe you should rather check swap usage?

share|improve this answer
As I said on a previous comment, there is a running configuration on other servers and they are not using the nrpe server. As rather checking the swap usage, it is a good question. I don't know for sure if the perl script used for the memory check is "oriented" for the swap usage or not. – Rui Gonçalves Oct 28 '10 at 15:27

I couldn't find a decent script for checking memory so I wrote the following. I use it with nrpe as suggested above.

Service definition on the server in the host config:

define service {
       use                     generic-service
       host_name               <hostname>
       service_description     Memory Usage
       check_command           check_nrpe_1arg!check_memory

This needs to be defined in /etc/nagios/nrpe.cfg on the client, amended for the values you want to check for:

command[check_memory]=/usr/lib/nagios/plugins/ -w 85 -c 90

Example output:

#:~$ ./ -w 80 -c 90
Memory OK. 44% used.

#:~$ ./ -w 40 -c 50
Memory WARNING. 44% used.

The script:

# Script to check memory usage on Linux. Ignores memory used by disk cache. 
# Requires the bc command
print_help() {
    echo "Usage:"
    echo "[-w] Warning level as a percentage" 
    echo "[-c] Critical level as a percentage" 
    exit 0

while test -n "$1"; do
    case "$1" in
            exit 0
            echo "Unknown Argument: $1"
            exit 3

if [ "$warn_level" == "" ]; then
    echo "No Warning Level Specified"
    exit 3;

if [ "$critical_level" == "" ]; then
    echo "No Critical Level Specified"
    exit 3;

free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`


result=$(echo "$used / $total * 100" |bc -l|cut -c -2)

if [ "$result" -lt "$warn_level" ]; then
    echo "Memory OK. $result% used."
    exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
    echo "Memory WARNING. $result% used."
    exit 1;
elif [ "$result" -gt "$critical_level" ]; then
    echo "Memory CRITICAL. $result% used."
    exit 2;
share|improve this answer
Honestly, I don't quite understand the memory analysis which is performed by your script? Is it more oriented to get the free swap? – Rui Gonçalves Oct 29 '10 at 9:34
It gets the amount of free memory, without including buffers/cache. It doesn't include any swap. You can compare the output of the script with gnome-system-monitor. – sideh Oct 29 '10 at 14:01

The problem is nagios server can't find check_nrpe_1arg's define. There are somewhere else you can define commands, e.g nagios-plugins

Here, I solve the problem by define command in plugins

deploy@code:/etc/nagios-plugins/config$ pwd
deploy@code:/etc/nagios-plugins/config$ cat check_nrpe.cfg 
# this command runs a program $ARG1$ with arguments $ARG2$
define command {
    command_name    check_nrpe
    command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a                 $ARG2$

# this command runs a program $ARG1$ with no arguments
define command {
    command_name    check_nrpe_1arg
    command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

To use check_nrpe or check_nrpe_1arg, you must make sure /usr/lib/nagios/plugins/check_nrpe exist. In debian system, you can install package nagios-nrpe-plugins on the nagios server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.