下载地址:https://prometheus.io/download/#blackbox_exporter
#blackbox_exporter 是 Prometheus 官方提供的一个exporter,可以监控 HTTP、HTTPS,、DNS、 TCP 、ICMP 等目标实例,
#从而实现对被监控节点进行监控和数据采集。
#HTTP/HTPPS: URL/API可用性检测
#TCP: 端口监听检测
#ICMP: 主机存活检测
#DNS: 域名解析
#1、下载blackbox_exporter、部署
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.23.0/blackbox_exporter-0.23.0.linux-amd64.tar.gz
[root@xksnode2 prometheus]# tar zxvf blackbox_exporter-0.23.0.linux-amd64.tar.gz
[root@xksnode2 blackbox_exporter-0.23.0.linux-amd64]# cp blackbox_exporter /usr/local/bin/
[root@xksnode2 blackbox_exporter-0.23.0.linux-amd64]# vim /etc/systemd/system/blackbox-exporter.service
[Unit]
Description=Prometheus Blackbox Exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/blackbox_exporter \
--config.file=/root/prometheus/blackbox_exporter/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@xksnode2 blackbox_exporter]# systemctl restart blackbox-exporter.service
[root@xksnode2 blackbox_exporter]# systemctl status blackbox-exporter.service
[root@xksnode2 blackbox_exporter]# systemctl enalbe blackbox-exporter.service
[root@xksnode2 blackbox_exporter]# netstat -nltp | grep 9115
tcp6 0 0 :::9115 :::* LISTEN 29722/blackbox_expoerter
#2、测试访问
http://192.168.19.182:9115/
#3、实现URL监控
#prometheus 调用 blackbox exporter 实现对 URL/ICMP 的监控
- job_name: 'http_status'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://www.xiaomi.com', 'http://www.magedu.com']
labels:
instance: http_status
group: web
relabel_configs:
- source_labels: [__address__] #将__address__(当前监控目标URL地址的标签)修改为__param_target,用于传递给blackbox_exporter
target_label: __param_target #标签key为__param_target、value为www.xiaomi.com。key为__param_target、value为www.magedu.com
- source_labels: [__param_target] #基于__param_target获取监控目标
target_label: url #将监控目标的值与url创建一个label
- target_label: __address__ #新添加一个目标__address__,指向blackbox_exporter服务器地址,用于将监控请求发送给指定的blackbox_exporter服务器
replacement: 192.168.19.182:9115 #指定blackbox_exporter服务器地址
#4、实现ICMP监控
[root@xksmaster1 yaml]# cat /apps/prometheus/prometheus.yml
# icmp 检测
- job_name: 'ping_status'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['172.31.0.2',"223.6.6.6","192.168.19.2"]
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.19.182:9115
[root@xksmaster1 yaml]# systemctl restart prometheus
#5、实现端口监控
[root@xksmaster1 yaml]# cat /apps/prometheus/prometheus.yml
# 端口监控
- job_name: 'port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.19.180:9090', '192.168.19.181:3000','192.168.19.182:80']
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.19.182:9115
[root@xksmaster1 yaml]# systemctl restart prometheus
#6、Grafana导入模板-13587、9965
标签:__,exporter,blackbox,target,prometheus,Prometheus,root From: https://www.cnblogs.com/birkhoffxia/p/17362174.html