深色模式
Blackbox Exporter 黑盒探测
不关心内部实现,只关心“能不能访问、响应多快”。黑盒探测是探活和拨测的利器。
适用环境
- 已运行 Prometheus
- 需要探测 HTTP 接口或主机存活(ICMP)
bash
# 确认目标地址可达(ICMP 需要权限)
ping -c 1 example.com1
2
2
操作步骤
1. 安装 Blackbox Exporter
bash
VERSION=v0.25.0
cd /opt
wget https://github.com/prometheus/blackbox_exporter/releases/download/${VERSION}/blackbox_exporter-${VERSION}.linux-amd64.tar.gz
tar xf blackbox_exporter-${VERSION}.linux-amd64.tar.gz
cp blackbox_exporter-${VERSION}.linux-amd64/blackbox_exporter /usr/local/bin/1
2
3
4
5
2
3
4
5
2. 配置探测模块
yaml
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_status_codes: [200, 301, 302]
icmp_ping:
prober: icmp
timeout: 3s1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
3. 在 Prometheus 接入
yaml
- job_name: blackbox
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['https://example.com']
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:91151
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
验证
promql
probe_success{job="blackbox"}
probe_duration_seconds{job="blackbox"}1
2
2
常见坑
ICMP 需要 CAP_NET_RAW
非 root 跑 blackbox 时 ping 会失败,需用 setcap cap_net_raw+ep 或 root 运行。
别把大量目标塞进单一 job
每个 target 都会触发一次探测,目标过多会拖慢 scrape 周期。