使用nginx-prometheus-exporter 監控nginx


因為nginx 已經提供了stub_status 模塊,一般我們可以基於此進行監控,目前官方提供了一個exporter
盡管有一些限制(web必須使用8080)。以下是一個簡單的學習使用

環境准備

  • docker-compose 文件
    注意使用了ranadeeppolavarapu 提供的nginx 鏡像(很方便,可以學習各種nginx 插件的使用)
 
version: "3"
services:
    httpservice:
        image: ranadeeppolavarapu/nginx-http3:edge
        volumes:
            - "./nginx.conf:/etc/nginx/nginx.conf"
            - "./h3.nginx.conf:/etc/nginx/conf.d/h3.nginx.conf"
            - "./status.conf:/etc/nginx/conf.d/status.conf"
            - "./localhost.crt:/etc/ssl/localhost.crt"
            - "./localhost.key:/etc/ssl/localhost.key"
        ports:
            - "443:443/tcp"
            - "443:443/udp"
            - "8080:8080"
    prome:
        image: nginx/nginx-prometheus-exporter:0.8.0
        command: -nginx.scrape-uri http://httpservice:8080/stub_status
        ports:
            - "9113:9113"
  • nginx 配置
    nginx.conf:
    核心部分主要是關於nginx 的配置加載
  include /etc/nginx/conf.d/*.conf;

status.conf:

server {
  listen 8080;
  server_name localhost;
  gzip on;
  gzip_http_version 1.1;
  gzip_vary on;
  gzip_comp_level 6;
  gzip_proxied any;
  gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript;
  brotli_static on;
  brotli on;
  brotli_types text/plain text/css application/json application/javascript application/x-javascript text/javascript;
  brotli_comp_level 4;
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }
  location = /stub_status {
    stub_status;
  }
}
  • 啟動訪問效果

exporter信息

 

 

說明

nginx-prometheus-exporter 的實現並不是很難,可以學習下實現,而且目前官方也提供了grafana 的dashboard 配置,但是總的來說監控點
還是太弱了

參考資料

https://github.com/nginxinc/nginx-prometheus-exporter
http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
https://github.com/RanadeepPolavarapu/docker-nginx-http3


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM