blackbox_exporter是Prometheus官方提供的一个exporter,可以通过Http,Https,Dns,Tcp和ICMP对被监控节点进行数据采集.
在Prometheus中配置监控项,将监控项指向blackbox.blackbox根据监控项再去监控目标
# mkdir /apps
# cd /apps
# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.22.0/blackbox_exporter-0.22.0.linux-amd64.tar.gz
# tar xf blackbox_exporter-0.22.0.linux-amd64.tar.gz
# ln -sf /apps/blackbox_exporter-0.22.0.linux-amd64/blackbox_exporter /usr/bin/
/etc/systemd/system/blackbox_exporter.service
[Unit]
Description=Prometheus blackbox_exporter
After=network.target
[Service]
ExecStart=/usr/bin/blackbox_exporter --config.file=/apps/blackbox_exporter-0.22.0.linux-amd64/blackbox.yml --web.listen-address=:9115
[Install]
WantedBy=multi-user.target
启动服务后在9115启动监听
# systemctl enable --now blackbox_exporter
Created symlink /etc/systemd/system/multi-user.target.wants/blackbox_exporter.service → /etc/systemd/system/blackbox_exporter.service.
# ss -ntl|grep 9115
LISTEN 0 4096 *:9115 *:*
此时prometheus还没有配置,所以target里是空的
主要用来监控一些页面状态和SSL证书有效期.
- job_name: 'http_status'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['https://www.baidu.com', 'http://192.168.31.201:9090']
labels:
instance: http_status
group: web
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: url
- target_label: __address__
replacement: 192.168.31.122:9115
重启Prometheus服务后,访问blackbox:9115
同时在prometheus里也看到了相关的监控项数据
主要用来监控一些网关,vip等ip地址
- job_name: 'ping_status'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['192.168.31.101',"192.168.31.114"]
labels:
instance: 'ping_status'
group: 'icmp'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: ip
- target_label: __address__
replacement: 192.168.31.122:9115
重启prometheus,获得了ping_status的监控项
主要用来监视无法直接通过http返回2xx监控的那些服务端口
- job_name: 'port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.31.101:6443', '192.168.31.201:3000','192.168.31.121:22','192.168.31.126:3306']
labels:
instance: 'port_status'
group: 'port'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: ip
- target_label: __address__
replacement: 192.168.31.122:9115
重启prometheus后
9965