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
    
    1
    2
    3
    4



    ## 1、二进制安装(二选一)
    https://prometheus.io/download/
    1
    2


    wget https://github.com/caarlos0/domain_exporter/releases/download/v1.20.0/domain_exporter_1.20.0_linux_amd64.tar.gz

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
2

### 创建用户

useradd -M -s /usr/sbin/nologin prometheus

1
2

### 更改exporter文件夹权限

chown prometheus:prometheus -R /usr/local/Prometheus

1
2

### 创建systemd

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
2

### 启动

systemctl daemon-reload

systemctl start domain_exporter

1
2

### 加入到开机自启动

systemctl enable domain_exporter

1
2

### 检查

systemctl status domain_exporter

1
2

启动不了检查日志

journalctl -u domain_exporter -f

1
2

## 2、docker安装

docker run -d –restart=always –name domain_exporter -p 9222:9222 caarlos0/domain_exporter

1
2

## 3、Prometheus设置

cd /data/docker-prometheus

1
2

使用cat追加

cat >> prometheus/prometheus.yml <<”EOF”

  • job_name: domain
    #scrape_interval: 1h
    scrape_interval: 15s
    metrics_path: /probe
    relabel_configs:

http://192.168.224.12:9222/

1
2
3
4



## 4、常用监控项目

domain_expiry_days 域名到期时间
domain_probe_success 域名检测状态

1
2
3
4

## 5、触发器

Prometheus配置

报警(触发器)配置

rule_files:

  • “alert.yml”
  • “rules/*.yml”
    1
    2

    ### 添加domain触发器(告警规则)
    cat >> prometheus/rules/domain.yml <<”EOF”
    groups:
    • name: domain
      rules:
  • 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天后过期’
    EOF
    1
    2

    ### 重新加载配置
    curl -X POST http://localhost:9090/-/reload
    1
    2

    ### 检查
    http://192.168.224.11:9090/alerts?search=
    1
    2
    3
    4
    5
    6





    ## 6、Doshboard
    https://grafana.com/grafana/dashboards/14605
    
    
    

问题处理:

p9NMpsU.png

找到右边的Column Styles,在找到“域名”这列,把instance修改为domain 如下图

p9NMVRx.png

评论


:D 一言句子获取中...

加载中,最新评论有1分钟缓存...