Prometheus+Grafana可视化监控【Nginx状态】
Prometheus+Grafana部署请参考上篇文章: Prometheus+Grafana部署:
一、Prometheus监控NGINX
1、配置with-http_stub_status_module模块
查看当前NGINX是否支持with-http_stub_status_module 模块
# 如果没有输出则不支持,需要编译进行添加with-http_stub_status_module模块
./nginx -V 2>&1 | grep -o with-http_stub_status_module
2、添加status页面的
server {
listen 80;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
重启NGINX
nginx -t
nginx -s reload
3、验证status页面是否可以访问
curl http://127.0.0.1/nginx_status
Active connections: 5
server accepts handled requests
5 5 7
Reading: 0 Writing: 2 Waiting: 3
4、安装nginx-prometheus-exporter
下载地址:https://github.com/nginxinc/nginx-prometheus-exporter/releases
wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
mkdir /usr/local/src/nginx-exporter
tar zxf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz -C /usr/local/src/nginx-exporter
5、启动nginx-prometheus-exporter模块
cd /usr/local/src/nginx-exporter
nohup ./nginx-prometheus-exporter -nginx.scrape-uri http://127.0.0.1:80/nginx_status &
6、默认监听9113端口,防火墙中放开
firewall-cmd --add-port=9113/tcp --permanent
firewall-cmd --reload
7、prometheus.yml添加Job配置
- job_name: 'nginx_7'
metrics_path: '/metrics'
scrape_interval: 10s
static_configs:
- targets: ['10.9.11.7:9113']
systemctl restart prometheus
8、验证
prometheus页面验证
二、Grafana添加NGINX监控模板
我这里内网环境,使用JSON
格式进行导入
最终效果图如下: