自动化监控运维(四) 基于Prometheus+Grafana监控Nginx
一、 基于nginx-module-vts
监控
1.1 下载
https://github.com/vozlt/nginx-module-vts
1.2 重新编译nginx
./configure \ |
1.3 nginx 配置
http { |
1.4 Prometheus 配置
- job_name: "nginx_vts_status" |
1.5 配置 grafana
导入模板: https://grafana.com/grafana/dashboards/14824-nginx-vts-stats/
二、 基于nginx-prometheus-exporter
监控
2.1 配置nginx
确保当前运行的nginx支持http_stub_status
./nginx -V 2>&1 | grep -o with-http_stub_status_module
nginx 开启http_stub_status
vim /path2yournginx/nginx.conf
server {
listen 80;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
2.2 配置nginx-prometheus-exporter
下载
https://github.com/nginxinc/nginx-prometheus-exporter
解压
tar -xzvf node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/
运行
./nginx-prometheus-exporter -nginx.scrape-uri http://127.0.0.1/nginx_status
2.3 配置 Prometheus
- job_name: "nginx_status" |
2.4 导入模板
https://grafana.com/grafana/dashboards/11199-nginx/