#(一)yum安裝的nginx添加第三方vts模塊
- 查看nginx版本模塊
2.下載一個同版本可編譯的Nginx
cd /tools
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz && cd nginx-1.12.2
3.備份原Nginx文件
\cp /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx{,.bak}
4.克隆vts模塊倉庫
git clone git://github.com/vozlt/nginx-module-vts.git
5.添加nginx-module-vts模塊,構建編譯配置,完成後make
cd /tools/nginx-1.12.2
./configure --prefix=/usr/share/nginx --add-module=./nginx-module-vts
如果有報錯, 安裝依賴
yum -y install libxml2 libxml2-dev libxslt-devel
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install GeoIP GeoIP-devel GeoIP-data
yum -y install pcre-devel
yum -y install openssl openssl-devel
yum -y install google-perftools google-perftools-devel
會在objs目錄下生成新的nginx二進制文件
\cp objs/nginx /usr/sbin/nginx
6.修改nginx配置文件
http {
vhost_traffic_status_zone;
server {
listen 80;
server_name localhost;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
7.啓動nginx,查看輸出
# curl http://localhost/status/format/
#(2)Nginx-vts-exporter下載安裝
1.下載nginx-vts-exporter
https://github.com/hnlq715/nginx-vts-exporter/releases
centos7 64位下載: nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
2.解壓啓動
tar xf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
cd nginx-vts-exporter-0.10.3.linux-amd64
cp nginx-vts-exporter /sbin/
nohup nginx-vts-exporter -nginx.scrape_uri=http://localhost/status/format/json
-
consul添加服務
curl -X PUT -d '{"id": "nginx","name": "nginx","address": "192.168.1.52","port": 9913,"tags": ["dev"],"checks": [{"http": "http://192.168.1.52:9913/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/register
4.consul驗證
- prometheus驗證
-
配置grafana模板
grafana 添加模板id 2949
https://grafana.com/dashboards/2949
參考文檔
https://github.com/hnlq715/nginx-vts-exporter#build-docker-image
https://github.com/hnlq715/nginx-vts-exporter/releases
https://it.baiked.com/nginx/2697.html
https://yq.aliyun.com/articles/573597
https://www.cnblogs.com/juanjuankaikai/p/9598976.html