網(wǎng)站首頁 編程語言 正文
簡述
監(jiān)控Nginx主要用到以下三個(gè)模塊:
- nginx-module-vts:Nginx virtual host traffic statusmodule,Nginx的監(jiān)控模塊,能夠提供JSON格式的數(shù)據(jù)產(chǎn)出。
- nginx-vts-exporter:Simple serverthat scrapes Nginx vts stats and exports them via HTTP for Prometheus consumption。主要用于收集Nginx的監(jiān)控?cái)?shù)據(jù),并給Prometheus提供監(jiān)控接口,默認(rèn)端口號9913。
- Prometheus:監(jiān)控Nginx-vts-exporter提供的Nginx數(shù)據(jù),并存儲在時(shí)序數(shù)據(jù)庫中,可以使用PromQL對時(shí)序數(shù)據(jù)進(jìn)行查詢和聚合。
1.下載nginx-module-vts模塊
解壓 unzip nginx-module-vts-master.zip mv nginx-module-vts-master /usr/local/
2.安裝nginx
tar zxvf nginx-1.15.7.tar.gz cd nginx-1.15.7 ./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配置文件,新起一個(gè)vhost暴露給server端訪問數(shù)據(jù):
vim /usr/local/nginx/conf/nginx.conf server下添加如下:http { vhost_traffic_status_zone; --添加 ... server { ... location /status { vhost_traffic_status_display; --添加 vhost_traffic_status_display_format html; --添加 } } }
Nginx-module-vts模塊介紹:
這是一個(gè)Nginx模塊,提供對虛擬主機(jī)狀態(tài)信息的訪問。它包含當(dāng)前狀態(tài),例如servers, upstreams, caches。這類似于nginx plus的實(shí)時(shí)活動監(jiān)視。內(nèi)置的html和舊版本的演示頁面也保持一致。這個(gè)模塊主要就是來監(jiān)控nginx虛擬主機(jī)狀態(tài)的。
首先,指令vhost_traffic_status_zone
是必需的,如果指令vhost_traffic_status_display
被設(shè)置,可以通過下方式訪問:
/status/format/json
請求/status/format/json
將用一個(gè)包含當(dāng)前活動數(shù)據(jù)的json文檔進(jìn)行響應(yīng),以便在實(shí)時(shí)儀表板和三方監(jiān)視工具中使用。
/status/format/html
請求/status/format/html
將會用一個(gè)內(nèi)置的內(nèi)置的html儀表板網(wǎng)頁進(jìn)行響應(yīng),該儀表盤的內(nèi)部請求走/status/format/json
。
/status/format/jsonp
請求/status/format/jsonp
將用一個(gè)jsonp回調(diào)函數(shù)進(jìn)行響應(yīng),該函數(shù)包含用于實(shí)時(shí)儀表板和三方監(jiān)視工具的當(dāng)前活動數(shù)據(jù)。
/status/format/prometheus
請求/status/format/prometheus
將用包含當(dāng)前活動數(shù)據(jù)的prometheus文檔來響應(yīng)。
/status/control
請求/status/control
將返回基于查詢語句字符串重置或刪除區(qū)域后的JSON文檔。更多可以參考Control.
測試nginx配置文件是否正確:
/usr/local/nginx/sbin/nginx -t
如果正確沒問題,啟動nginx
啟動nginx:
/usr/local/nginx/sbin/nginx
此時(shí)訪問http://IP地址/status可以看到nginx的狀態(tài)信息了。
3.安裝nginx-vts-exporter
https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.9.1/nginx-vts-exporter-0.9.1.linux-amd64.tar.gz tar -zxvf nginx-vts-exporter-0.9.1.linux-amd64.tar.gz mv nginx-vts-exporter-0.9.1.linux-amd64 /usr/local/nginx-vts-exporter chmod +x /usr/local/nginx-vts-exporter-0.5/bin/nginx-vts-exporter cd /usr/local/nginx-vts-exporter/bin 通過nginx-vts-exporter二進(jìn)制文件來執(zhí)行nginx-vts-exporter程序 nohup ./nginx-vts-exporter -nginx.scrape_uri http://10.10.xx.xx:80/status/format/json & #注意:http://10.10.xx.xx/status/format/json這個(gè)地方的ip地址是nginx的IP地址 nginx-vts-exporter的監(jiān)聽端口是9913
也可以使用systemctl管理nginx-vts-exporter進(jìn)程。
[root@localhost nginx-vts-exporter]# vim /usr/lib/systemd/system/nginx_vts_exporter.service [Unit] Description=prometheus_nginx_vts After=network.target [Service] Type=simple ExecStart=/usr/local/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri http://10.10.xx.xx:80/status/format/json Restart=on-failure [Install] WantedBy=multi-user.target
[root@localhost nginx-vts-exporter]# systemctl daemon-reload [root@localhost nginx-vts-exporter]# systemctl enable nginx_vts_exporter [root@localhost nginx-vts-exporter]# systemctl start nginx_vts_exporter [root@localhost nginx-vts-exporter]# systemctl status nginx_vts_exporter ● nginx_vts_exporter.service - prometheus_nginx_vts Loaded: loaded (/usr/lib/systemd/system/nginx_vts_exporter.service; disabled; vendor preset: disabled) Active: active (running) since Fri xxxx-xx-xx xx:xx:xx EDT; 4 days ago Main PID: 90274 (nginx-vts-expor) CGroup: /system.slice/nginx_vts_exporter.service └─90274 /usr/local/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri http://10.10.xx.xx:80/status/format/json
4.修改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: [‘10.10.xx.xx:9913’]這個(gè)ip地址是nginx-vts-exporter程序所在機(jī)器的ip地址
5.在grafana界面導(dǎo)入nginx json文件
原文鏈接:https://blog.csdn.net/qq_34939308/article/details/123604472
相關(guān)推薦
- 2022-07-17 baselines示例程序train_cartpole.py的ImportError_python
- 2023-04-01 Python使用pptx實(shí)現(xiàn)復(fù)制頁面到其他PPT中_python
- 2022-04-22 阿里云ECS服務(wù)器Linux下載安裝JDK8
- 2022-11-01 Kotlin?ContentProvider使用方法介紹_Android
- 2022-10-14 使用docker起一個(gè)verdaccio的容器
- 2022-06-20 音視頻基本概念和FFmpeg的簡單入門教程詳解_相關(guān)技巧
- 2021-12-13 C++??系統(tǒng)IO流介紹_C 語言
- 2022-05-09 Python的Pandas時(shí)序數(shù)據(jù)詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支