杨梅冲
每天在想什么呢?
随笔 - 198,  文章 - 0,  评论 - 8,  阅读 - 17万

一、域名过期时间监控

域名的监控通过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/

 

 

 

 

 

 

posted on   杨梅冲  阅读(835)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-04-24 三元表达式、列表推导式、生成器表达式、递归、匿名函数、内置函数

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示