Prometheus监控domain域名
一、环境
主机名 | IP地址 | 系统 | 说明 |
---|---|---|---|
localhost | 192.168.224.11 | Centos7.6 | docker安装的prometheus |
server2.com | 192.168.224.12 | Centos7.6 | domain_exporter版本1.20.0 |
1、环境搭建
docker安装
略
docker-compose安装
略
二、域名过期时间监控
域名的监控通过domain_exporter
来完成
domain_exporter
https://github.com/caarlos0/domain_exporter/releases
https://prometheus.io/download/1
2
3
4
## 1、二进制安装(二选一)wget https://github.com/caarlos0/domain_exporter/releases/download/v1.20.0/domain_exporter_1.20.0_linux_amd64.tar.gz1
2
mkdir /usr/local/Prometheus/domain_exporter -p
tar zxvf domain_exporter_1.20.0_linux_amd64.tar.gz -C /usr/local/Prometheus/domain_exporter
1 |
|
useradd -M -s /usr/sbin/nologin prometheus
1 |
|
chown prometheus:prometheus -R /usr/local/Prometheus
1 |
|
cat <<”EOF” >/etc/systemd/system/domain_exporter.service
[Unit]
Description=domain_exporter
After=network.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/Prometheus/domain_exporter/domain_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
1 |
|
systemctl daemon-reload
systemctl start domain_exporter
1 |
|
systemctl enable domain_exporter
1 |
|
systemctl status domain_exporter
1 |
|
journalctl -u domain_exporter -f
1 |
|
docker run -d –restart=always –name domain_exporter -p 9222:9222 caarlos0/domain_exporter
1 |
|
cd /data/docker-prometheus
1 |
|
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.224.12:9222 # domain_exporter address
static_configs: - targets:
- qq.com
- baidu.cn
EOFcurl -X POST http://localhost:9090/-/reload1
2
### 重新加载配置http://192.168.224.11:9090/targets?search=1
2
### 检查
- source_labels: [address]
1 |
|
domain_expiry_days 域名到期时间
domain_probe_success 域名检测状态
1 |
|
报警(触发器)配置
rule_files:
- “alert.yml”
- “rules/*.yml”cat >> prometheus/rules/domain.yml <<”EOF”
1
2
### 添加domain触发器(告警规则)
groups:- name: domain
rules:
- name: domain
- alert: 域名检测失败
expr: domain_probe_success == 0
for: 2h
labels:
severity: warning
annotations:
summary: ‘‘
description: ‘域名检测失败’ - alert: 域名过期
expr: domain_expiry_days < 30
for: 2h
labels:
severity: warning
annotations:
summary: ‘‘
description: ‘将在30天后过期’ - alert: 域名过期
expr: domain_expiry_days < 5
for: 2h
labels:
severity: page
annotations:
summary: ‘‘
description: ‘将在5天后过期’
EOFcurl -X POST http://localhost:9090/-/reload1
2
### 重新加载配置http://192.168.224.11:9090/alerts?search=1
2
### 检查https://grafana.com/grafana/dashboards/146051
2
3
4
5
6
## 6、Doshboard
问题处理:
找到右边的Column Styles,在找到“域名”这列,把instance
修改为domain
如下图
- 本文标题:Prometheus监控domain域名
- 本文作者:yichen
- 本文链接:https://yc6.cool/2023/05/08/Prometheus监控domain域名/
- 版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!