FoxuTech

How to monitor hosts using Icinga on Ubuntu/Debian

How to monitor hosts using Icinga

For now we have installed icinga on the icinga server and now will start monitoring the available hosts and also some more case studies. In icinga there is two ways of monitoring,

  1. Monitor “publicly available services”
  2. Monitor via an agent that is installed on a remote host to collect and send data to Icinga

With the first method, publicly available services refer to services that are accessible across the local network or the Internet. Common examples include HTTP, mail, SSH, and ICMP ping. This method is useful for monitoring systems that you can’t (or don’t want to) install an agent on, and also for monitoring user facing network interfaces.

To implement the second method, we will install NRPE as an agent on remote hosts to monitor their local resources. This will allow Icinga to monitor things like disk usage, running processes, and other system stats that the first method can’t achieve.

Way1: Monitor “publicly available services”

First way is simply monitors listening services, the configuration for this method is done all on the Icinga server. Several things can be monitored with this method, so will see how to monitor a public interface of a web server.

Create a file with the name of your host, with this command (hostname with your own hostname):

# vi /etc/icinga/objects/<hostname>.cfg

Ex:

# vi /etc/icinga/objects/foxutech.cfg

You can use following by, replacing the values of host_name with your own hostname (in both places), alias with a description of the host, and address with the value of your host’s public IP address:

define host {

use                     generic-host

host_name               myweb-F

alias                   FoxuTech Web Server

address                 36.54.xxx.xxx

}

define service {

use                     generic-service

host_name               myweb-F

service_description     HTTP

check_command           check_http

}

Now save and quit. Reload your Icinga configuration to put any changes into effect:

# service icinga reload

Way2: Monitor via an agent

As we discussed earlier, Icinga uses NRPE tool as an agent to collect host data for icinga. To use NRPE, it must to installed on remote hosts to monitor and also icinga server too need to configure to receive data for each other.

Installing NRPE On a Remote Host

On a host that you want to monitor, update apt

# apt-get update

Now install NRPE and Nagios Plugins

# apt-get install nagios-plugins nagios-nrpe-server

Look up the name of your var filesystem (will configure monitor for this filesystem):

# df -h /var

We need to use the filesystem name in the NRPE configuration file to monitor required filesystem disk (may probably /dev/sda). Let’s open nrpe.cfg,

# vi /etc/nagios/nrpe.cfg

To setup the monitor and sent data to server we should do config changes, it’s quite lengthy file you can file the parameter and change it your setup

example:

server_address=client_private_IP

allowed_hosts=nagios_server_private_IP

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda

Note that there are several other “commands” defined in this file that will run if the Icinga server is configured to use them. Also note that NRPE will be listening on port 5666 because server_port=5666 is set. If you have any firewalls blocking that port, be sure to open it to your Icinga server.

Save and quit. Then restart NRPE to put the changes into effect:

# service nagios-nrpe-server restart

Once you are done installing and configuring NRPE on the hosts that you want to monitor, you will have to add these hosts to your Icinga server configuration before it will start monitoring them.

Add Remote Host To Icinga Server Configuration

On your Icinga server, create a new configuration file for each of the remote hosts that you want to monitor in /etc/icinga/objects. Replace yourhost with the name of your host:

# vi /etc/icinga/objects/yourhost.cfg

Add in the following host definition, replacing the host_name value with your remote hostname (I used “foxutech-1” in my example), the alias value with a description of the host, and the address value with the private IP address of the remote host,

define host {

use                     generic-host

host_name               foxuTech-web

alias                   foxutech alias site

address                 192.168.xxx.xxx

}

Then add any of these service blocks for services you want to monitor. Note that the value of check_command determines what will be monitored, including status threshold values. Here are some examples that you can add to your host’s configuration file:

Ping:

define service {

use                            generic-service

host_name                       foxuTech-web

service_description             PING

check_command                   check_ping!100.0,20%!500.0,60%

}

SSH (notifications_enabled set to 0 disables notifications for a service):

define service {

use                             generic-service

host_name                       foxuTech-web

service_description             SSH

check_command                   check_ssh

notifications_enabled           0

}

Load:

define service {

use                             generic-service

host_name                       foxuTech-web

service_description             Current Load

check_command                  check_load!5.0!4.0!3.0!10.0!6.0!4.0

}

Current Users:

define service {

use                             generic-service

host_name                       foxuTech-web

service_description             Current Users

check_command                   check_users!20!50

}

Disk Space:

define service {

use                             generic-service

host_name                       foxuTech-web

service_description             Disk Space

check_command                   check_all_disks!20%!10%

}

If you’re wondering what use generic-service means, it is simply inheriting the values of a service template called “generic-service” that is defined by default.

Now save and quit. Reload your Icinga configuration to put any changes into effect:

# service icinga reload

Once you are done configuring Icinga to monitor all of your remote hosts, let’s check out the web interface

To check web interface, use <you-IP-Address>/icinga in your browser.

Exit mobile version