Prometheus之Blackbox监控

Prometheus之Blackbox监控

部署Blackbox

1
下载地址 https://github.com/prometheus/blackbox_exporter

这里使用amd64架构的软件包,根据自己设备架构选择

右键复制链接地址

image-20240829165007463

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
32
33
34
35
36
下载软件包
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz

解压
tar xf blackbox_exporter-0.25.0.linux-amd64.tar.gz


mv blackbox_exporter-0.25.0.linux-amd64/blackbox_exporter /usr/local/bin/blackbox_exporter

mv blackbox_exporter-0.25.0.linux-amd64 /usr/local/blackbox_exporter

注册服务启动
cat > /usr/lib/systemd/system/blackbox.service << EOF
[Unit]
Description=Prometheus Blackbox Exporter
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

启动服务
systemctl start blackbox.service

查看启动状态
systemctl status blackbox.service

配置开机自启
systemctl enable blackbox.service

配置Prometheus采集信息

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
32
- job_name: "百度"
  scrape_interval: 1m # 多久采集一次信息,建议不要太频繁
  metrics_path: /probe
  params:
    module: [http_2xx]
  static_configs:
  - targets: ['https://www.baidu.com/']   # 探测的域名
    labels:
      blackbox: '测试百度'
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 172.16.0.3:9115 # 采集器blackbox信息
- job_name: "Google"
  scrape_interval: 1m
  metrics_path: /probe
  params:
    module: [http_2xx]
  static_configs:
  - targets: ['https://www.google.com/']
    labels:
      blackbox: '测试Google'
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 172.16.0.3:9115

image-20240829170155131

1
2
重载prometheus配置
docker restart prometheus

配置Grafnana

导入模版ID 9965

image-20240829170459497

效果如下

image-20240829170407309

完成

能看到连通性、状态、访问耗时、1小时可用率、证书到期时间 还是不错的


Prometheus之Blackbox监控
http://ziiix.cn/2024/11/08/Prometheus之Blackbox监控/
作者
John Doe
发布于
2024年11月8日
许可协议