在k8s的master節點安裝nginx-module-vts模塊
解壓軟件包
unzip nginx-module-vts-master.zip mv nginx-module-vts-master /usr/local/
安裝nginx
tar zxvf nginx-1.15.7.tar.gz ./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module
--with-pcre --with-file-aio --with-http_realip_module --add-module=/usr/local/nginx-module-vts-master
編譯和編譯安裝
make && make install
修改nginx配置文件
cat /usr/local/nginx/conf/nginx.conf
server下添加如下:
location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; }
http中添加如下
vhost_traffic_status_zone;
測試nginx配置文件是否正確
/usr/local/nginx/sbin/nginx -t
如果正確沒問題,啟動nginx
啟動nginx:
/usr/local/nginx/sbin/nginx
訪問k8s的master節點主機ip/status可以看到nginx監控數據
安裝nginx-vts-exporter
解壓軟件包
unzip nginx-vts-exporter-0.5.zip
啟動服務
mv nginx-vts-exporter-0.5 /usr/local/
chmod +x /usr/local/nginx-vts-exporter-0.5/bin/nginx-vts-exporter
cd /usr/local/nginx-vts-exporter-0.5/bin
nohup ./nginx-vts-exporter -nginx.scrape_uri http://192.168.124.16/status/format/json &
#注意:http://192.168.124.16/status/format/json這個地方的ip地址是nginx服務所在主機的IP地址,nginx-vts-exporter的監聽端口是9913
修改prometheus-cfg.yaml文件
添加如下job:
- job_name: 'nginx' scrape_interval: 5s static_configs: - targets: ['192.168.124.16:9913'] kubectl apply -f prometheus-cfg.yaml kubectl delete -f prometheus-deploy.yaml kubectl apply -f prometheus-deploy.yaml
#注意:
- targets: ['192.168.124.16:9913']
這個ip地址是nginx-vts-exporter程序所在機器的ip地址
在grafana界面導入nginx圖表
https://mp.weixin.qq.com/s/SP3r8a6I7wNwfWB9hI5SIg
https://github.com/kumina/openvpn_exporter 監控openvpn
https://cloud.tencent.com/developer/article/1615817