给已经运行的Nginx安装nginx-module-vts模块
下载nginx-module-vts
解压重新配置****configure
./configure ${上面 nginx -V 显示出来的编译参数,原样的放在这里} --add-module=/home/monitor/nginx-module-vts
make 但不要install,否则就会把正在运行的覆盖了
备份并替换启动文件nginx
cp /home/software/nginx/sbin/nginx /home/software/nginx/sbin/nginx-bak
cp /home/software/nginx-1.16.1/objs/nginx /home/software/nginx/sbin/nginx
添加监控模块
vhost_traffic_status_zone;
server {
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
检查config
/home/software/nginx/sbin/nginx -t
重启
/home/software/nginx/sbin/nginx -s reload
检查
curl localhost/status/format/prometheus
添加到 prometheus
-
job_name: '47nginx'
metrics_path: '/status/format/prometheus'
static_configs:
-
targets: ['172.16.10.4']
-
targets: ['172.16.10.7']
18.1解压安装****nginx-vts-exporte****r(后来发现用不上)
tar -zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
mv nginx-vts-exporter-0.10.3.linux-amd64 nginx-exporter
rm -rf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
18.2 自启动
touch /usr/lib/systemd/system/nginx_exporter.service
chown prometheus2:prometheus2 /usr/lib/systemd/system/nginx_exporter.service
chown -R prometheus2:prometheus2 /home/monitor/nginx_exporter
vim /usr/lib/systemd/system/nginx_exporter.service
[Unit]
Description=nginx_exporter
After=network.target
[Service]
Type=simple
User=prometheus2
ExecStart=/home/monitor/nginx_exporter/nginx-vts-exporter -nginx.scrape_uri=https://IP/status/format/json
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动
systemctl daemon-reload
systemctl enable nginx_exporter.service
systemctl start nginx_exporter.service
systemctl status nginx_exporter.service
systemctl stop nginx_exporter.service
systemctl restart nginx_exporter.service
18.3 添加到Prometheus
-
job_name: '47nginx'
static_configs:
-
targets: ['172.16.10.4:9913']
-
targets: ['172.16.10.7:9913']
-
18.4 添加grafana
Import dashboard 2949选择数据源 Prometheus
注意模板key值是否正确
网友评论