Exporting Metrics to Nagios via the collectd-nagios
Utility¶
This document provides an example of exporting filter node metrics to the Nagios monitoring system (the Nagios Core edition is suggested; however, this document is suitable for any Nagios edition) using the collectd-nagios
utility.
Assumptions and requirements
- The
collectd
service must be configured for working via a Unix domain socket (see here for details). -
It is assumed that you already have the Nagios Core edition installed.
If not, install Nagios Core (for example, follow these instructions).
You can use another edition of Nagios if necessary (for example, Nagios XI).
The “Nagios” term will be used hereinafter to refer to any edition of Nagios, unless stated otherwise.
-
You must have the ability to connect to the filter node and the Nagios host (for example, via the SSH protocol), and work under the
root
account or another account with superuser rights. - The Nagios Remote Plugin Executor service (which will be referred to as NRPE throughout this example) must be installed on the filter node.
Example Workflow¶
Example of metric
This example shows how to work with the single curl_json-wallarm_nginx/gauge-abnormal
metric, which shows the number of requests processed by the filter node.
The following deployment scheme is used in this document:
-
The Wallarm filter node is deployed on a host accessible via the
10.0.30.5
IP address and thenode.example.local
fully qualified domain name. -
Nagios is installed on a separate host accessible via the
10.0.30.30
IP address. -
To execute commands on a remote host, the NRPE plugin is used. The plugin comprises
- The
nrpe
service that is installed on the monitored host alongside the filter node. It listens on the5666/TCP
standard NRPE port. - The
check_nrpe
NRPE Nagios plugin that is installed on the Nagios host and allows Nagios to execute commands on the remote host where thenrpe
service is installed.
- The
-
NRPE will be used to call the
collectd_nagios
utility that provides thecollectd
metrics in a Nagios‑compatible format.
Configuring Metrics Export to Nagios¶
A note on this installation example
This document describes how to install and configure the NRPE plugin when Nagios is already installed with default parameters (it is assumed that Nagios is installed in the /usr/local/nagios
directory, and uses the nagios
user to operate). If you are doing a non-default installation of the plugin or Nagios, adjust the corresponding commands and instructions from the document as needed.
To configure metrics export from the filter node to Nagios, follow these steps:
1. Configure NRPE to Communicate with the Nagios Host¶
To do this, on a filter node host:
-
Open the NRPE configuration file (default:
/usr/local/nagios/etc/nrpe.cfg
). -
Add the IP address or fully qualified domain name of the Nagios server to the
allowed_hosts
directive in this file. For example, if the Nagios host uses the10.0.30.30
IP address: -
Restart the NRPE service by executing the appropriate command:
2. Install the Nagios NRPE Plugin on the Nagios Host¶
To do this, on the Nagios host, take the following steps:
-
Download and unzip the source files for the NRPE plugin, and install the necessary utilities to build and install the plugin (see the NRPE documentation for details).
-
Go to the directory with the plugin source code, build from sources, then install the plugin.
The minimal steps to take are:
3. Make Sure the NRPE Nagios Plugin Successfully Interacts with the NRPE Service¶
To do this, execute the following command on the Nagios host:
If NRPE is operating normally, the command’s output should contain an NRPE version (e.g., NRPE v3.2.1
).
4. Define the check_nrpe
Command to Run the NRPE Nagios Plugin with a Single Argument on the Nagios Host¶
To do this, add to the /usr/local/nagios/etc/objects/commands.cfg
file the following lines:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
5. Install the collectd_nagios
Utility on the Filter Node Host¶
Execute one of the following commands:
6. Configure the collectd-nagios
Utility to Run with Elevated Privileges on Behalf of the nagios
User¶
To do this, perform the following steps on the filter node host:
-
Using the
visudo
utility, add the following line to the/etc/sudoers
file:This allows the
nagios
user to run thecollectd-nagios
utility with superuser privileges usingsudo
without the need to provide any passwords.Running
collectd-nagios
with superuser privilegesThe utility must be run with superuser privileges because it uses the
collectd
Unix domain socket to receive data. Only a superuser can access this socket. -
Make sure that the
nagios
user can receive metric values fromcollectd
by executing the following test command:sudo -u nagios sudo /usr/bin/collectd-nagios -s /var/run/wallarm-collectd-unixsock -n curl_json-wallarm_nginx/gauge-abnormal -H node.example.local
This command allows the
nagios
user to get the value of thecurl_json-wallarm_nginx/gauge-abnormal
metric (the number of processed requests) for thenode.example.local
host.Example of command output:
-
Add a prefix to the NRPE service configuration file so that it will be able to execute commands using the
sudo
utility:
7. Add Commands to the NRPE Service Configuration File on the Filter Node to Get the Required Metrics¶
For example, to create a command named check_wallarm_nginx_abnormal
that will receive the curl_json-wallarm_nginx/gauge-abnormal
metric for the filter node with the node.example.local
fully qualified domain name, add the following line to the NRPE service’s configuration file:
command[check_wallarm_nginx_abnormal]=/usr/bin/collectd-nagios -s /var/run/wallarm-collectd-unixsock -n curl_json-wallarm_nginx/gauge-abnormal -H node.example.local
How to set threshold values for a metric
If necessary, you can specify a range of values for which the collectd-nagios
utility will return the WARNING
or CRITICAL
status by using the corresponding -w
and -c
options (detailed information is available in the utility documentation).
After you have added all necessary commands to the NRPE service configuration file, restart the service by executing the appropriate command:
8. On the Nagios Host, Use the Configuration Files to Specify the Filter Node Host and to Define the Services to Monitor¶
Services and Metrics
This document assumes that one Nagios service is equivalent to one metric.
For example, this can be done as follows:
-
Create a
/usr/local/nagios/etc/objects/nodes.cfg
file with the following contents:define host{ use linux-server host_name node.example.local address 10.0.30.5 } define service { use generic-service host_name node.example.local check_command check_nrpe!check_wallarm_nginx_abnormal max_check_attempts 5 service_description wallarm_nginx_abnormal }
This file defines the
node.example.local
host with the10.0.30.5
IP address and the command to check the status of thewallarm_nginx_abnormal
service, which means receiving thecurl_json-wallarm_nginx/gauge-abnormal
metric from the filter node (see the description of thecheck_wallarm_nginx_abnormal
command). -
Add the following line to the Nagios configuration file (by default,
/usr/local/nagios/etc/nagios.cfg
):This is necessary for Nagios to start using the data from the
nodes.cfg
file on the next start. -
Restart the Nagios service by running the appropriate command:
Setup is Complete¶
Nagios is now monitoring the service associated with the specific metric of the filter node. If necessary, you can define other commands and services to check the metrics you are interested in.