title: 2.14.域名过期监控
order: 18
icon: lightbulb
主机名 | IP地址 | 系统 | 说明 |
localhost | 192.168.11.61 | Ubuntu 20.04 | docker安装的prometheus |
test | 192.168.11.62 | Ubuntu 20.04 | domain_exporter版本1.20.0 |
1、环境搭建
docker安装
略
docker-compose安装
略
二、域名过期时间监控
域名的监控通过domain_exporter
来完成
- domain_exporter
https://github.com/caarlos0/domain_exporter/releases
1、二进制安装(二选一)
https://prometheus.io/download/
wget https://github.com/caarlos0/domain_exporter/releases/download/v1.20.0/domain_exporter_1.20.0_linux_amd64.tar.gz
tar zxvf domain_exporter_1.20.0_linux_amd64.tar.gz
mkdir /opt/prometheus -p
mv domain_exporter_1.20.0_linux_amd64 /opt/prometheus/domain_exporter
创建用户
useradd -M -s /usr/sbin/nologin prometheus
更改exporter文件夹权限
chown prometheus:prometheus -R /opt/prometheus
创建systemd
cat <<"EOF" >/etc/systemd/system/domain_exporter.service
[Unit]
Description=domain_exporter
After=network.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/domain_exporter/domain_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
启动
systemctl daemon-reload
systemctl start domain_exporter
加入到开机自启动
systemctl enable domain_exporter
检查
systemctl status domain_exporter
启动不了检查日志
journalctl -u domain_exporter -f
2、docker安装
docker run -d --restart=always --name domain_exporter -p 9222:9222 caarlos0/domain_exporter
3、Prometheus设置
cd /data/docker-prometheus
使用cat追加
cat >> prometheus/prometheus.yml <<"EOF"
- job_name: domain
#scrape_interval: 1h
scrape_interval: 15s
metrics_path: /probe
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.11.62:9222 # domain_exporter address
static_configs:
- targets:
- qq.com
- baidu.cn
EOF
重新加载配置
curl -X POST http://localhost:9090/-/reload
检查
http://192.168.11.61:9090/targets?search=
4、常用监控项目
domain_expiry_days 域名到期时间
domain_probe_success 域名检测状态
5、触发器
Prometheus配置
# 报警(触发器)配置
rule_files:
- "alert.yml"
- "rules/*.yml"
添加domain触发器(告警规则)
cat >> prometheus/rules/domain.yml <<"EOF"
groups:
- name: domain
rules:
- alert: 域名检测失败
expr: domain_probe_success == 0
for: 2h
labels:
severity: warning
annotations:
summary: '{{ $labels.instance }}'
description: '{{ $labels.domain }}域名检测失败'
- alert: 域名过期
expr: domain_expiry_days < 30
for: 2h
labels:
severity: warning
annotations:
summary: '{{ $labels.instance }}'
description: '{{ $labels.domain }}将在30天后过期'
- alert: 域名过期
expr: domain_expiry_days < 5
for: 2h
labels:
severity: page
annotations:
summary: '{{ $labels.instance }}'
description: '{{ $labels.domain }}将在5天后过期'
EOF
重新加载配置
curl -X POST http://localhost:9090/-/reload
检查
http://192.168.11.61:9090/alerts?search=
6、Doshboard
https://grafana.com/grafana/dashboards/14605
问题处理:
找到右边的Column Styles,在找到“域名”这列,把instance
修改为domain
如下图
三、我的微信
如果安装碰到问题,可以随时加我微信,谢谢
评论区