4

Just installed nagios on a central machine and nrpe on 10 remote linux machines and just started monitoring them. It works great. I can get cpu load, current users, processes, mysql, etc. I can't find a way to monitor memory usage using the core plugins. What am I missing? Do I need an external plugin to do this?

3 Answers 3

4

i suggest you rather monitor swap usage. check out check_swap plugin - it comes by default [at least in debian].

1
  • This is exactly what I was looking for... thanks... Sep 30, 2010 at 19:40
2

yes, i do thought why they didnt include a plugin which will check the memory, when they have included check_swap and check_disk... ok, something wrong... but the check_memory plugin is available from the exchange.nagios.org http://exchange.nagios.org/directory/Plugins/Operating-Systems/Solaris/check_mem-2Epl/details

this one works pretty nice.. its a perl script, so not even an installation needed... this is the link http://sysadminsjourney.com/content/2009/06/04/new-and-improved-checkmempl-nagios-plugin/ from the above plugin page...simple and good documentation...

$ /usr/local/nagios/libexec/check_mem.pl -w 10 -c 5 -f 

WARNING - 9.9% (406520 kB) free!|TOTAL=4113824KB;;;; USED=3707304KB;;;; FREE=406520KB;;;; CACHES=816947KB;;;;

So, the configuration steps are simple:

  • Copy the perl script and write it as "check_memory" (or check_mem or a suitable name for you) in the same directory as where you have the check_disk, check_load etc
    • important to change the execute permissions to that check_memory similar to the other check_plugins(i mean, the execute permission should be given to the nagios user. in our dev environment i gave 755, please verify whether you need 754 or 755)
    • update the remote client nrpe.cfg config file with the command[check_memory]=/usr/lib64/nagios/plugins/check_memory -u -w 8% -c 90%
0
-1

Working with Nagios Server and NRPE Client to automatically restart services on failure January 13, 2015

Executing Remote Commands using Nagios and NRPE

1. Installing NRPE on remote host:

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm yum –enablerepo=epel -y install nrpe nagios-plugins yum –enablerepo=epel -y list nagios-plugins* vim /etc/nagios/nrpe.cfg

service nrpe start chkconfig nrpe on

2. To execute commands on remote nagios client follow below steps:

  1. Open NRPE configuration file and make below mentioned changes:

vim /etc/nagios/nrpe.cfg a. Change from 0 to 1, as shown below: dont_blame_nrpe=1 b. Configuring the Command in NRPE Open your nrpe.cfg file in a text editor and add the following line to define the command in NRPE. Add below mentioned command below the commands section in the nrpe.cfg file: command[runcmd]=sudo service $ARG1$ restart

  1. Granting NRPE Permission to Restart Services Run the following command as root to give NRPE permission to restart services. Make Changes to sudoers file:

vim /etc/sudoers nagios ALL = NOPASSWD: /sbin/service nrpe ALL = NOPASSWD: /sbin/service

Testing runcmd command from the nagios server:

Testing the Commands from Nagios Server Moving over to the Nagios command line, the service restart script will be using Check_Nrpe to send the command to the Service’s Host. Navigate to the Nagios command line and enter the following commands:

/usr/local/nagios/libexec/check_nrpe -H 192.168.5.180 -p 5666 -c runcmd -a httpd

Executing remote commands using Nagios NRPE & Event Handler Configuring the nagios client/remote machine 1. Modify the nrpe.cfg as shown below: Change dont_blame_nrpe=0 to don’t_blame_nrpe=1 2. Add the below custom command in the nrpe.cfg as shown below: command[event-ntp]=/usr/lib64/nagios/plugins/event-ntp $ARG1$ $ARG2$ $ARG3$ 3. Create a event handler, as shown below: vim /usr/lib64/nagios/plugins/event-ntp

#!/bin/bash

case “$1″ in
OK)
;;
WARNING)
    echo -e “Running NTP Query” “\n”
    ntpq -p | mailx -s “HOSTNAME – NTP Query” [email protected]
;;
UNKNOWN)
;;
CRITICAL)
    case “$2″ in
    SOFT)
        case “$3″ in
        3)
            echo -e “Running NTP Query & Restarting NTP Service” “\n”
            ntpq -p | mailx -s “HOSTNAME – NTP Query – Restarted NTPD” \
              [email protected] &&
              /usr/bin/sudo /sbin/service ntpd restart
        ;;
        esac
    ;;
    HARD)
        echo -e “Running NTP Query & Restarting NTP Service” “\n”
        ntpq -p | mailx -s “HOSTNAME – NTP Query – Restarted NTPD” \
            [email protected] &&
        /usr/bin/sudo /sbin/service ntpd restart
    ;;
    esac
;;
esac
exit 0
  1. Give execution permission and change owner and group: chmod +x /usr/lib64/nagios/plugins/event-ntp chown nagios:nagios /usr/lib64/nagios/plugins/event-ntp

  2. The tricky, and probably not the most secure way to do this, is to modify the sudoer’s file to allow the nagios user to execute system commands

visudo add the following: User_Alias NAGIOS = nagios,nagcmd Cmnd_Alias NAGIOSCOMMANDS = /sbin/service Defaults:NAGIOS !requiretty NAGIOS ALL=(ALL) NOPASSWD: NAGIOSCOMMANDS

  1. Once everything is complete restart nrpe service and client configuration is done.

Configuring Event Handler on the Nagios Server First thing you need to do is create an event-ntp command in the commands.cfg file:

  1. Vim /usr/local/nagios/etc/objects/commands.cfg

define command{ command_name event-ntp command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTNAME$ -c event-ntp -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ }

  1. This will be called by the event-handler object in your configuration file. now, modify your service description in wherever you configure your service/host definitions. In my case I have a separate configuration file called linux.cfg.

define service{ use local-service host_name neeraj-test service_description Time Sync Check event_handler event-ntp check_command check_nrpe!check_ntp }

  1. Now restart nagios (service nagios restart), and test the configuration from the server end: /usr/local/nagios/libexec/check_nrpe -H REMOTEHOSTNAME -c event-ntp -a CRITICAL HARD

If all goes well, you should receive an email from your client with an output from ntpq -p, and an ntpd service restart. If you have any problems, not receiving email, or not executing the said script, set the debug level=1 on nrpe.cfg, restart nrpe, execute the above event-ntp test, and check your logs. As you can see, it’s not too difficult to execute event-handler scripts, and saves Administrator’s time when nagios can do the leg-work on system/host critical alerts.

2
  • 1
    Thanks for the detailed explanation. However, I voted your answer down because you copied and dumped a whole blog post here without (1) paying attention to the fact the the formatting is all wrong unless you adjust it, and (2) boiling your answer down to the key points. Jan 16, 2015 at 9:53
  • Just want to know is event handler used only for service restart ! I want to write event handler for /mnt Free Space ! In this alert it should delete unnecessary log ! That also not on all server only on web servers ps I have created separate hosts groups for webservers n db servers so it should not run on db servers ! Feb 16, 2016 at 10:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .