Community

Blog
×
Community Blog How to Monitor Nginx using Netdata on CentOS 7

How to Monitor Nginx using Netdata on CentOS 7

In this article, we will be installing Netdata on an Alibaba Cloud ECS CentOS 7 instance to monitor the performance of an Nginx server.

By Sajid Qureshi, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Netdata is an open source performance and health monitoring system for Linux and MacOS. Metrics in Netdata are organized in collections called charts. Charts have a purpose and a scope. This makes Netdata extremely useful for learning the underlying technologies. It helps us to understand how things work and what is available. Real - time alarms are also supported in Netdata and these alarms can be setup on any metrics or any combination of them. Netdata is very resource efficient and you can control its resource consumption.

Prerequisites

  1. You must have an Alibaba Cloud Elastic Compute Service (ECS) instance activated and have verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don't know about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.

Install Nginx Web server

Before installing netdata on your CentOS server, we will have to install nginx web server. Nginx web server can be installed from epel repository. so first install EPEL repository using following command, if you do not have it.

yum -y install epel-release

(You can switch from non root user to root user using sudo -i )

Now install nginx from following command.

yum -y install nginx

Once the installation is finished, start the service using the following command below.

systemctl start nginx

Next, enable it to launch automatically at system boot using below command.

systemctl enable nginx

Now you'll need to open HTTP and HTTPS ports using following commands, so execute following commands one-by-one.

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

If in case you don't have firewalld services running then you can install it using below command.

yum -y install firewalld

Enable Nginx Module

To install netdata you'll have to enable 'stub_status' module and you can do that by editing the configuration file 'nginx.conf'. Go to the '/etc/nginx/' directory using following command.

cd /etc/nginx/

Next, edit the configuration with any text editor. Here we are using nano text editor.

nano nginx.conf

If in case you don't have it you can also install it using this command.

yum -y install nano

Paste the following content 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;  
     }

Save the file and exit from the text editor.

Now, test the nginx configuration and make sure there is no error and to do so execute following command.

nginx -t

Next, restart nginx using following command.

systemctl restart nginx

Install Netdata

Now we will install netdata to monitor nginx server. You'll need to install some required packages before installing netdata and you can do so using following command.

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

Now download netdata source code from github using following git command.

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

Go to netdata directory using following cd command.

cd netdata/

Next, run the Netdata installer script with sudo privileges and you can do so using following command.

sudo ./netdata-installer.sh

Press the Enter button to continue the netdata installation and complete the installation.

Netdata will run on port '19999' so you'll need to open this port using following command.

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

Reload firewalld service to apply changes that we just configured.

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. So execute following commands one by one.

systemctl restart netdata
systemctl enable netdata

Next, make sure that port is opened to run netdata so execute following command and check if port 19999 on the 'LISTEN' state or NOT.

netstat -plntu

Monitor Nginx using Netdata

All the required packages have been installed and now we are ready to monitor our nginx server using netdata. To monitor system applications netdata provides modules. There are some applications like Apache, Nginx, MongoDB etc that use python modules for monitoring using Netdata.

Change your current directory to netdata 'python.d' directory using following command.

cd /etc/netdata/python.d/

Now edit the nginx configuration file 'nginx.conf' using any text editor. Here we are using nano text editor.

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'

Save the file and exit from text editor.

Finally restart the netdata service using following command.

systemctl restart netdata

Testing

Netdata is successfully installed and running on your server. Open your favorite web browser to test it. Point your web browser to YourServerIP with port 19999.

http://YourServerIPAddress:19999

Replace YourServerIPAddress with your actual server IP address and you will be redirected to netdata dashboard. You can manage netdata operations like Nginx active connections, requests, status and the connection rate from that dashboard.

Congratulations! You have successfully installed Netdata on your server. Your Nginx services are being monitored using Netdata on your Alibaba Cloud Elastic Compute Service (ECS) CentOS 7 server.

0 0 0
Share on

Sajid Qureshi

2 posts | 0 followers

You may also like

Comments

Sajid Qureshi

2 posts | 0 followers

Related Products

More Posts by Sajid Qureshi

See All