How to Use Nginx Prometheus Exporter?

How to Use NGINX Prometheus Exporter

In this post, I will show you how to use Nginx Prometheus exporter to monitor your Nginx Server easily with step by step procedure.

Nginx Prometheus exporter is a plugin that helps us to send nginx metrics to Prometheus for monitoring performance.

If you are interested in learning, Request you to go through the below recommended tutorial.

Prerequisites:

Here is the prerequisites that we need to make everything in place before we start using Nginx Prometheus exporter.

  • NGINX web server
  • Prometheus monitoring tool
  • NGINX Prometheus exporter

Installation:

Using simple apt-get command, we can install Nginx Prometheus exporter package.

sudo apt-get install nginx-prometheus-exporter

Above apt-get install command will install Nginx Prometheus exporter package from repositories directly.

Once the package installation is completed, Check the service status of Nginx Prometheus exporter using the following systemctl command.

sudo systemctl status nginx-prometheus-exporter

If you see the service status shows as active in state, then exporter package is installed and running successfully. We can move forward to next step.

Configuration:

In order to configure Nginx Prometheus exporter, we need to make some changes on nginx configuration file.

Default nginx configuration file will be /etc/nginx/nginx.conf

Open the Nginx configuration file using any text editor like vim or nano and add below lines:

location /metrics {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

The above configuration will enable Nginx to expose all metrics on /metrics endpoint path.

Restart Nginx to apply the changes:

Once you have updated the given changes in the nginx configuration file, please restart the nginx service to make the changes effect. Use the systemctl command to restart nginx service.

sudo systemctl restart nginx

Once nginx service is restarted, you can verify the nginx service status using systemctl command.

sudo systemctl status nginx

If all good, then we will able to access the entpoint /metrics using the following URL through browser.

http://localhost/metrics

Prometheus Configuration:

At this point, we are done the configuration part on nginx side also our Nginx Prometheus exporter is up and running.

Now, we have to configure the Prometheus to scrape metrics from Nginx server. Open Prometheus configuration file and add the below lines:

scrape_configs:
- job_name: 'nginx'
static_configs:
- targets: ['localhost:9113']

Above configuration section will tell Prometheus to scrape metrics through Nginx Prometheus exporter running on port 9113.

Also restart Prometheus service to apply the changes. Again use systemctl command to restart it.

sudo systemctl restart prometheus

Once prometheus service is restarted, We would be able to see all Nginx metrics in Prometheus web interface console through browser.

That's it for this post. Keep practicing and have fun. Leave your comments if any.

Related Searches and Questions asked:

  • How to Configure Kubernetes Restart Policies
  • How to Use HostPath Volumes on Kubernetes
  • How to Create Kubernetes Network Policies
  • How to Create Local Persistent Volume in Kubernetes

  • Post a Comment

    0 Comments