安装nginx-vts模块
git clone https://github.com/vozlt/nginx-module-vts
./configure --prefix=/usr/local/nginx --add-module=/tmp/nginx-module-vts --with-pcre --user=daemon --group=daemon --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-stream --with-http_gzip_static_module
make && install
添加nginx配置文件,暴露监控指标
$ /usr/local/nginx/conf/nginx.conf
http {
...
vhost_traffic_status_zone;
...
}
$ vim /usr/local/nginx/conf/vhost/nginx-vts-status.conf
server {
listen 8088;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
#需要重启模块才能生效
$ /usr/local/nginx/sbin/nginx -s stop
$ /usr/local/nginx/sbin/nginx
然后访问ip:8088/status,可以看到下面的数据
部署nginx-vts-exporter
推荐docker方式
参考链接
https://github.com/hnlq715/nginx-vts-exporter/#download
docker pull sophos/nginx-vts-exporter
docker run -ti --rm -p 9913:9913 --env NGINX_STATUS="http://10.98.2.60:8081/status/format/json" sophos/nginx-vts-exporter
注意8081是nginx的端口
默认端口为 :9913/metrics
配置prometheus
$ vim /usr/local/prometheus/prometheus.yml
...
- job_name: 'nginx-vts'
static_configs:
- targets:
- 你的IPxxx:9913
重启生效
promtool check config /usr/local/src/prometheus-2.17.1.linux-amd64/prometheus.yml
kill -HUP 765
配置grafana
导入模板: 2949