prometheus监控nginx
环境:
组件nginx-prometheus-exporter部署位置:192.168.0.39
nginx服务器:172.30.0.10
通过组件nginx-prometheus-exporter进行监控
nginx需要安装有with-http_stub_status_module模块,一般高版本的nginx会自带这个模块
检查
# nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_stub_status_module
nginx增加配置
创建一个server,监听38888端口,开启监控,只允许192.168.0.39访问
server {
listen 38888;
location /nginx_status {
stub_status on;
allow 192.168.0.39; #only allow requests from localhost
deny all; #deny all other hosts
}
}
测试一下
172.30.0.10就是刚刚那台nginx主机
# curl http://172.30.0.10:38868/nginx_status
Active connections: 12189
server accepts handled requests
195544839 195544839 1147258694
Reading: 0 Writing: 63 Waiting: 12018
创建启动监控组件
需要指定被监控主机(我这里没试过能不能添加多个被监控主机,有测试过的小伙伴可以留言)
我启动了多个组件
端口:9117 自定义的
docker run -d \
--name nginx_exporter_qalb_10 \
-m 1g \
--restart=always \
--restart=on-failure:5 \
-p 9117:9113 \
nginx/nginx-prometheus-exporter:0.10.0 \
-nginx.scrape-uri http://172.30.0.10:38888/nginx_status
prometheus集成nginx-prometheus-exporter组件
prometheus.yml
添加
# nginx
- job_name: nginx-qalb-10
static_configs:
- targets: ['192.168.0.10:9117']
labels:
instance: nginx-qalb-10
有多个组件就再加一个,注意端口别冲突
- job_name: nginx-qalb-11
static_configs:
- targets: ['192.168.0.10:9118']
labels:
instance: nginx-qalb-11
重启prometheus容器
添加告警规则
nginx_export-alert-rules.yaml
groups:
- name: nginx状态-监控告警
rules:
- alert: nginx状态
expr: nginx_up == 0
for: 1s
labels:
serverity: warning
status: 非常严重
annotations:
summary: "{{$labels.instance}}:nginx服务停止"
description: "nginx服务down"
重启prometheus容器生效
grafana图形码:12708
上一篇:基础环境搭建
下一篇:URL监控