Prometheus監控Nginx


在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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM