一、沒有vts的啟動方式
nginx_exporter -telemetry.address=:9113 -nginx.scrape_uri="https://xx.xx.xx.xx:18443" -insecure #端口9113應該是nginx_exporter監聽的端口,prometheus通過9113訪問metrics,18443自己可以通過nginx.conf設置其他端口
1.1、修改nginx.conf配置文件
server { listen 80; .............................. location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; } ................................ }
1.2nginx重新加載
nginx -s reload
1.3啟動nginx-exporter
nginx_exporter -telemetry.address=:9113 -nginx.scrape_uri="https://xx.xx.xx.xx:18443//nginx_status" -insecure
二、具有vts的啟動方式
nohup ./${nginx-vts_path}/nginx-vts-exporter -nginx.scrape_uri=https://xx.xx.xx.xx:18443/status/format/json #端口18443應該是nginx監聽的端口
2.1查看nginx是否有加載模塊nginx-module-vts,並拷貝configure arguments:后的字串
nginx -V
2.2備份文件
解壓nginx-module-vts至指定目錄,重新編譯nginx
cd nginx源碼
./configure {前面拷貝的configure arguments參數} --add_module=/nginx-module-vts
2.3備份原有nginx文件
cp nginx二進制文件為nginx.bak
cp nginx源碼/objs目錄 現有Nginx目錄下替換現有的nginx二進制文件
2.3修改nginx.conf文件
http { vhost_traffic_status_zone; # 添加 ... server { ... location /status { vhost_traffic_status_display; # 添加 vhost_traffic_status_display_format html; # 添加 } } }
2.4重新加載nginx
nginx -s reload
2.5安裝nginx-vts-exporter
nohup ./${nginx-vts_path}/nginx-vts-exporter -nginx.scrape_uri=https://xx.xx.xx.xx:18443/status/format/json