Tuesday, May 21, 2024

Prometheus and Grafana : Monitor NGINX

A: nginx configuration

1.Expose the stub_status page at /stub_status on port 8080

    server {
        listen 8080;
        server_name _;
    
        location /stub_status {
               stub_status;
        }
    }
2. Restart nginx
#systemctl restart nginx

3. Verification
#curl http://localhost:8080/stub_status

B: nginx-prometheus-exporter

1.Install nginx-prometheus-exporter
#git clone https://github.com/nginxinc/nginx-prometheus-exporter.git

2.Building the Binary. Change to nginx-prometheus-exporter folder
#dnf install go
#make

3.Move the nginx-prometheus-exporter binary to /usr/local/binary
#mv nginx-prometheus-exporter /usr/local/bin

4.Modify and create nginx_exporter.socket in /etc/systemd/system
#vi nginx_exporter.socket  (add below parameter)

[Unit]
Description=NGINX Prometheus Exporter

[Socket]
ListenStream=9113

[Install]
WantedBy=sockets.target

4.Modify and create nginx_exporter.service in /etc/systemd/system
#useradd nginx_exporter --shell=/sbin/nologin
#vi nginx_exporter.service  (add below parameter)
[Unit]
Description=NGINX Prometheus Exporter
Requires=nginx_exporter.socket

[Service]
User=nginx_exporter
ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1:8080/stub_status" --web.systemd-socket

[Install]
WantedBy=multi-user.target

5.Run #systemctl daemon-reload
6.Run #systemctl start nginx_prometheus_exporter.service
7.Run #systemctl status nginx_prometheus_exporter.service
8. Verification
#curl http://localhost:9113/metrics

C:Promethues

1.Configure Prometheus to scrape metrics from the server with the exporter.
2.Edit /etc/prometheus/prometheus.yml
3.Add the scrape metric
## NGINX
  - job_name: nginx
    static_configs:
      - targets: ['10.X.X.X:9113']

4.Run systemctl restart prometheus.service
5.Run systemctl status prometheus.service

D:Grafana

1.Use the New Dashboard button and click Import.
2.Upload dashboard.json or copy and paste the contents of the file in the textbox and click Load.
https://github.com/nginxinc/nginx-prometheus-exporter/blob/main/grafana/dashboard.json
3.Set the Prometheus data source and click Import.
4.The dashboard will appear.By default, all instances are selected
5.Access Grafana dashboard

source : https://github.com/nginxinc/nginx-prometheus-exporter/tree/main

Related Posts:

0 comments:

Post a Comment