Prometheus之Blackbox监控
部署Blackbox
下载地址 https://github.com/prometheus/blackbox_exporter
这里使用amd64架构的软件包,根据自己设备架构选择
右键复制链接地址
下载软件包
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采集信息
- 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
重载prometheus配置
docker restart prometheus
配置Grafnana
导入模版ID 9965
效果如下
完成