Nginx 监控工具 Prometheus

Prometheus 通过 nginx-prometheus-exporter 读取 stub_status。指标用于趋势监控,详细请求仍由日志系统承担。

开启状态接口

location = /nginx_status {
    stub_status;
    allow 10.0.0.5;
    deny all;
    access_log off;
}

运行 exporter

docker run -d --name nginx-exporter   --network host   -e NGINX_SCRAPE_URI=http://127.0.0.1/nginx_status   nginx/nginx-prometheus-exporter:latest

Prometheus 配置:

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

验证

curl http://127.0.0.1/nginx_status
curl http://127.0.0.1:9113/metrics | grep nginx_connections