系统运维
767
Monitor nginx for Prometheus
nginx vts and lua 的安装
前置条件
- 源码安装 nginx
安装
###下载 wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz tar xf v0.3.0.tar.gz wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz tar xf v0.10.9rc7.tar.gz wget https://github.com/vozlt/nginx-module-vts/archive/v0.1.15.tar.gz ## 解压 tar xf v0.1.15.tar.gz ## 切换到ngin的源码目录 cd ../nginx-1.13.7 ./configure [参数] --add-module=/opt/nginx-module-vts-0.1.15 make //编译完,在objs目录下有一个nginx执行文件,不要make install,否则就是覆盖安装; mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old cp objs/nginx /usr/local/nginx/sbin/nginx make upgrade //替换老的nginx进程 #再次执行:/usr/local/nginx/sbin/nginx -V 将会显示新的nginx的版本及编译的参数。
修改nginx配置文件并且重启nginx
http { vhost_traffic_status_zone; ... server { ... location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } } }
安装nginx-vts-exporter
# 这是一个由Golang开发的exporter,直接下载二进制使用 wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.7/nginx-vts-exporter-0.7.linux-amd64.tar.gz tar xf /nginx-vts-exporter-0.7.linux-amd64.tar.gz
启动
cd nginx-vts-exporter-0.7.linux-amd64 nohup ./nginx-vts-exporter \ --nginx.scrape_uri=http://192.168.1.232:9146/ngx_status/format/json &
检查
netstat -ntlp | grep 9913 ----- tcp 0 0 :::9913 :::* LISTEN 4418/./nginx-vts-ex ----- curl http://192.168.1.232:9913/metrics