nginx exporter 安装配置

nginx exporter 安装配置

  1. 二进制安装
1wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.10.0/nginx-prometheus-exporter_0.10.0_linux_amd64.tar.gz
2tar -zxvf nginx-prometheus-exporter_0.10.0_linux_amd64.tar.gz -C ./nginx-exporter
  1. 在 nginx 上配置
1./configure \
2\
3--with-http_stub_status_module
4make
5sudo make install

在 nginx.config 上配置

server {
    # 新增
    location /nginx_status {
        stub_status on;
        access_log off;
    }
}

重启 nginx 服务

1nginx -t
2nginx -s reload
  1. 启动 nginx exporter
1nginx-prometheus-exporter -nginx.scrape-uri http://<nginx>:8080/nginx_status
  1. 配置 prometheus 添加 prometheus.yml
1- job_name: "nginx-exporter"
2  file_sd_configs:
3    - files:
4        - "./file_sd/nginx-exporter.yaml"

在 ./file_sd/新建 nginx-exporter.yaml

1- targets: ["<IP>:9113"]
2  labels:
3    instance: <nginx名称>