对编译安装的Nginx使用nginx

it2022-05-09  26

参考自: https://blog.51cto.com/xujpxm/2080146 https://github.com/hnlq715/nginx-vts-exporter#environment-variables

在nginx编译时添加vts模块

下载解压

wget https://github.com/vozlt/nginx-module-vts/archive/v0.1.18.tar.gz # nginx -V

将之前的编译参数完整复制一份,加上vts模块 重新编译 nginx-1.16.0

./configure \ --user=nginx --group=nginx --with-debug \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --with-stream --with-http_sub_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_mp4_module \ --with-pcre --with-http_ssl_module \ --with-stream_ssl_module \ --add-module=../nginx-module-vts-0.1.18

nginx修改http区块、server区块

http { ... #增加vhost过滤 vhost_traffic_status_zone; vhost_traffic_status_filter_by_host on; #增加一个专用server server { listen 80; server_name localhost 127.0.0.1; location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; allow 127.0.0.1; deny all; } } }

启动Nginx,检查结果

curl http://localhost/status/format/json

下载nginx-vts-exporter二进制包

wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz cd nginx-vts-exporter-0.10.3.linux-amd64 nohup ./nginx-vts-exporter -nginx.scrape_uri=http://localhost/status/format/json &

浏览器打开 http://x.x.x.x:9913/metrics

prometheus.yml

- job_name: 'nginx-check' metrics_path: /metrics file_sd_configs: - files: - 'instances/ins_nginx.yaml' refresh_interval: 1m

instances/ins_nginx.yaml

- labels: env: "test" targets: - 127.0.0.1:9913

grafana dashboard模板参考 https://grafana.com/grafana/dashboards?search=Nginx


最新回复(0)