How to Monitor Nginx using Netdata on CentOS 7

Netdata is an open source monitoring system for Linux servers. It provides real-time performance and health monitoring with beautiful dashboard and analytics. Netdata should run on any Linux distribution - has been tested on Alpine Linux, Arch Linux, CentOS, Ubuntu etc. It offers real-time health monitoring tools for your servers, CPU, memory usage, IPv4 and IPv6 networks and user applications such as Nginx, fail2ban, MySQL, MongoDB etc.

In this tutorial, I will show you how to monitor Nginx using Netdata. This tutorial will cover the Nginx web server installation, enabling of the 'stub_status' module, and Netdata installation on CentOS 7.

What we will do

  1. Install Nginx Webserver.
  2. Enable Nginx 'stub_status' module.
  3. Install Netdata on CentOS 7.
  4. Monitor Nginx using Netdata.
  5. Testing.

Prerequisites

  • CentOS 7 Server
  • Root privileges

Step 1 - Install Nginx Web server

In this step, we will install the Nginx web server from the EPEL (Extra Packages for Enterprise Linux) repository. Before installing Nginx, make sure the EPEL repository has been installed on your server.

If you do not have it, you can install it using the command below.

yum -y install epel-release

Install Nginx Web server

Next, install Nginx with the yum command below.

yum -y install nginx

And if the installation has been completed, start the service and enable it to launch automatically at system boot using the systemctl commands below.

systemctl start nginx
systemctl enable nginx

After the installation, open HTTP and HTTPS ports using the firewall-cmd command below.

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload

Configure the firewall

Note: If you do not have the firewall-cmd command, you can install the firewalld packages from the repository.

yum -y install firewalld

The Nginx web server has been installed.

Step 2 - Enable Nginx stub_status module

To monitor Nginx using Netdata, we must enable the 'stub_status' module by editing the configuration. Make sure your Nginx version has a module named 'stub_status', check the module with the command below.

nginx -V

You should get a result similar to the following.

Enable Nginx stub_status module

Make sure you have the 'stub_status' module on the list.

Next, edit the nginx configuration file 'nginx.conf' to enable the 'stub_status' module. Go to the '/etc/nginx/' directory and edit the configuration with vim.

cd /etc/nginx/
vim nginx.conf

Paste the following configuration inside the 'server {}' block.

    location /stub_status {
        stub_status;
        # Security: Only allow access from the IP below.
        allow 127.0.0.1;
        # Deny anyone else
        deny all;
    }

Configure nginx

Save and exit.

Now, test the nginx configuration and make sure there is no error. Then restart nginx.

nginx -t
systemctl restart nginx

Test nginx config and restart nginx

Nginx 'stub_status' module has been enabled - we can check it using the curl command as shown below.

curl http://127.0.0.1/stub_status

When it's enabled, you can see the result as below.

Test nginx stub status

Step 3 - Install Netdata on CentOS 7

In this step, we will install Netdata on the CentOS 7 server. Before installing Netdata, we need to install some packages for Netdata installation.

Install packages needed for Netdata installation using the following yum command.

yum -y install zlib-devel libuuid-devel libmnl-devel gcc make git autoconf autogen automake pkgconfig curl jq nodejs

Next, download Netdata source code using the following git command.

cd ~
git clone https://github.com/firehol/netdata.git --depth=1

Install Netdata on CentOS 7

Go to the netdata directory and run the Netdata installer script with sudo privileges.

cd netdata/
sudo ./netdata-installer.sh

Press 'Enter' to continue with the Nedata installation.

Install Netdata

And when the installation is complete, you will see the result as below.

Eun netdata installer

Netdata has been installation on CentOS 7, and it's running on port '19999'.

Open the port using the firewall-cmd command below.

sudo firewall-cmd --permanent --add-port=19999/tcp
sudo firewall-cmd --reload

Netdata provides a systemd services script, so you can manage Netdata using the systemctl command. Restart netdata and enable it to launch automatically every time at system boot.

systemctl restart netdata
systemctl enable netdata

Check the opened port of the server - make sure you get the port 19999 on the 'LISTEN' state.

netstat -plntu

Check network port

The Netdata monitoring tool has been installed on CentOS 7.

Step 4 - Monitor Nginx using Netdata

At this stage, Nginx has been installed, the stub_status module has been enabled, and the Netdata installation has been completed. In this step, we want to monitor the nginx web server using Netdata. Monitoring for requests, active connection, and the status.

Netdata provides modules for monitoring system applications. There are some applications like Apache, Nginx, MongoDB etc that use python modules for monitoring using Netdata.

Go to the netdata 'python.d' directory and edit the configuration file nginx.conf using vim.

cd /etc/netdata/python.d/
vim nginx.conf

Go to the bottom line and make sure you have a configuration as shown below.

localhost:
  name : 'local'
  url  : 'http://localhost/stub_status'

Configure netdata

Save and exit.

Now restart the netdata service using the systemctl command.

systemctl restart netdata

Step 5 - Testing

Open your web browser and visit the server IP address with port 19999.

http://192.168.1.11:19999/

And you will get the Netdata Dashboard.

Netdata System Overview

Click on the 'nginx local' on the right, and see Nginx active connections, requests, status and the connection rate.

connections, requests, status and the connection rate

Netdata has been installed on the CentOS 7 server, and the Nginx web server is being monitored using Netdata.

Preference

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: striker at: 2018-06-03 14:39:53

I have followed steps to a T everything came out as expected but im not able to get to the web interface states problem loading page