Skip to content

Monitoring Ubuntu nodes with Nagios

by Julien on September 27th, 2011

Une version française de ce billet est disponible ici.

Nagios is considered by a lot of people as the number 1 tool when it comes to monitor from one server to a reasonable server farm. It has a good documentation, and lucky for people like me that are dealing with Ubuntu / Debian servers, the Ubuntu packages allows simple installation. The only problem are the Ubuntu packages are placing things in different places than the official “from the source” installation guides, and there are not much tutorial for installing a full monitoring system for total noobs like me. So here is my try to explain this.


The idea is to have one central monitoring Nagios host that will monitor a bunch of remote hosts. This is easily achieved through a plugin called Nagios Remote Plugin Executor (NRPE for short), which name quite explain what it does. This plugin has 2 parts:

  1. A daemon that you install on each remote host and that is accepting plugin commands from the nagios host
  2. A plugin in the Nagios host that knows how to send commands to each of the remote hosts

Setuping the remote hosts

This part is quite easy. Here are the commands:

YOUR_NAGIOS_HOST_IP=<put your central Nagios host ip here>
sudo apt-get -y install nagios-nrpe-server
sudo sed -i.bak -r -e 's/allowed_hosts=$YOUR_NAGIOS_HOST_IP/g' /etc/nagios/nrpe.cfg
sudo /etc/init.d/nagios-nrpe-server restart

The second line is installing the daemon. The next one is instructing the daemon to accept commands only from your central nagios host (this is a minimal security precaution). Finally, you restart the daemon for taking the config change into account.

Note: when executing plugins remotely, it is more secure to not allow arguments to the plugins from the Nagios host, this is preventing script insertion, etc… This is the default setting in the config file, and this means you have to hard code the arguments of each command on the remote host. You can see the default ones and add some more at the end of the nrpe.cfg file. Here are the default commands:

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

Setuping the central Nagios host

Here is the command:

sudo apt-get -y install nagios3 nagios-nrpe-plugin

And that is it! The package will install postfix (required for sending email notification), apache and configure the ‘nagiosadmin’ user for you. All you have to do is to configure the objects in the /etc/nagios3/conf.d directory according to the documentation. Here is an example configuration of a remote host as well as a service calling the default remote hda1 check:

define host{
        use                     generic-host            ; Name of host template to use
        host_name               myServer1
        alias                   My Server 1
        address                 <ip of myServer1 here>
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       myServer1
        service_description             Disk Space
        check_command                   check_nrpe_1arg!check_hda1

You can test the configuration with:

sudo /usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg

If everything is fine, you can restart Nagios with:

sudo /etc/init.d/nagios3 restart

Finally, you can open a browser and go to http://YourNagiosHostIp/nagios3. The user is nagiosadmin and the password is the one you chose during installation.

This should give you a head start for working with Nagios.

From → Linux

  1. mandm permalink

    This is perfect!!!…. do you have any idea what i would need to modify if had to add a few more checks like (memory, swap, iostat etc) to the remote server

  2. nptr permalink

    straight to the point, helped me much :)

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS