一、域名过期时间监控
域名的监控通过domain_exporter
来完成
domain_exporter:https://github.com/caarlos0/domain_exporter/releases
二、domain_exporter安装
2.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 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
2.2 docker安装方式
docker run -d --restart=always --name domain_exporter -p 9222:9222 caarlos0/domain_exporter
3.Prometheus设置
cd /data/docker-prometheus 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.10.100:9222 # domain_exporter address static_configs: - targets: - qq.com - baidu.cn EOF # 重新加载配置 curl -X POST http://localhost:9090/-/reload # 检查 http://192.168.10.100:9222/ http://192.168.10.14:9090/targets?search=
3.1 常用监控项目
domain_expiry_days 域名到期时间
domain_probe_success 域名检测状态
4.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.10.14:9090/rules
http://192.168.10.14:9090/alerts?search=
4.grafana dashboard图形展示
https://grafana.com/grafana/dashboards/14605
id14605显示域名不正确,需要修改
找到右边的Column Styles,在找到“域名”这列,把
instance
修改为domain
https://grafana.com/grafana/dashboards/13924-9116-domain/