#(一)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