一、没有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