云原生监控系统Prometheus——Exporter(Nginx监控)

Exporter(Nginx监控)

  Nginx是比较流行的一款轻量级 Web 服务器和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务,因其优良的稳定性,丰富的功能集等等优点,广受大家喜爱,所以无论网站用户访问量级别有多大,nginx 监控是必备知识。

  在 Prometheus 官方文档汇总提供了 2 个 Nginx 使用的第三方 Exporter: Nginx metric Library 和 nginx-vts-exporter。这里我们使用 nginx-vts-exporter 对已经安装好的 Nginx 服务进行监控数据采集。

 一、部署 nginx-module-vts

  nginx-module-vts 在 Nginx 官网上的第三方网站中推荐下载页面地址 https://github.com/vozlt/nginx-module-vts,也可以直接使用 git 进行 clone 操作 git clone git://github.com/vozlt/nginx-module-vts.git。

    • Clone the git repository.
      shell> git clone git://github.com/vozlt/nginx-module-vts.git
    • Add the module to the build configuration by adding --add-module=/path/to/nginx-module-vts
    • Build the nginx binary.
    • Install the nginx binary.

  模块加载完成后,需要在 Nginx 配置文件中添加如下格式的配置内容:

http {
    vhost_traffic_status_zone;

    ...

    server {

        ...

        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

  正确添加后,重新加载 Ngiinx 配置文件使配置生效,通过浏览器访问 /status,若可以看到如下的页面内容,说明 Nginx 模块 nginx-module-vts 已经开始正常运行。

二、与 Prometheus 集成

  在 Prometheus 的配置文件 prometheus.yml 中继续追加 status_configs 来采集 redis_exporter 提供的数据。添加的参考配置内容如下:

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
	
  - job_name: "node_exporter"
    static_configs:
	  - targets: ["192.168.2.121:9100"]

  - job_name: "mysqld_exporter"
    scrape_interval: 10s
    static_configs:
	  - targets: ["192.168.2.121:9104"]

  - job_name: "redis_exporter"
    scrape_interval: 10s
    static_configs:
	  - targets: ["192.168.2.121:9121"]
	  
  - job_name: "nginx_vts_exporter"
    scrape_interval: 10s
    static_configs:
	  - targets: ["192.168.2.121:9913"]
posted @ 2022-07-15 18:17  左扬  阅读(1266)  评论(0编辑  收藏  举报
levels of contents