Nginx Monitoring in Prometheus
Nginx Monitoring in Prometheus
Nginx Monitoring in Prometheus
Olivier Spiesser
Following my two previous blogs about monitoring, I will now focus on Nginx. Nginx Inc provides
an exporter with it’s code: https://github.com/nginxinc/nginx-prometheus-exporter
As Nginx cannot run a web application as WebLogic or WildFly can, exporter will be another
process.
Nginx Configuration
To enable metrics for Nginx, we must use stub_status directive in a server or location context
of the configuration.
Before that, we must check that stub module is enabled. A simple command will do:
Then, we must extend the existing configuration to enable stub module by adding following lines
inside a server context:
1 location /nginx_status {
2 stub_status on;
allow 127.0.0.1;
3
deny all;
4
}
5
1 Active connections: 1
2 server accepts handled requests
14 14 14
3
Reading: 0 Writing: 1 Waiting: 0
4
As the format is not Prometheus compliant, we need the exporter to do the reformatting for us.
Nginx Exporter
Further, I can also test the URL where metrics are now properly formatted for Prometheus
ingestion (i.e. http://localhost:9113/metrics):
1 # HELP nginx_connections_accepted Accepted client connections
Prometheus Integration
1 - job_name: "Nginx"
2 metrics_path: /metrics
3 static_configs:
4 - targets: ['172.17.0.1:9113']
Prometheus Targets
Grafana
I will use the dashboard provided in the github repository (grafana/dashboard.json) and point it to
Prometheus datasource:
Nginx Dashboard
Nginx Plus provides much more metrics as documented here.
We use cookies on our website to provide you with the most relevant experience by remembering
your preferences. No personal data is stored. By clicking on "Accept All", you consent to the use of
ALL cookies. However, you can visit "Cookie Settings" to provide controlled consent. Read More