blackbox_exporter简介
项目地址: https://github.com/prometheus/blackbox_exporter
grafana: https://grafana.com/grafana/dashboards/13659
https://grafana.com/grafana/dashboards/9965
blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。
Blackbox_exporter 应用场景
- HTTP 测试
定义 Request Header 信息
判断 Http status / Http Respones Header / Http Body 内容
- TCP 测试
业务组件端口状态监听
应用层协议定义与监听
- ICMP 测试
主机探活机制
- POST 测试
接口联通性
- SSL 证书过期时间
部署
下载软件
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz tar xf blackbox_exporter-0.19.0.linux-amd64.tar.gz -C /opt ln -s /opt/blackbox_exporter-0.19.0.linux-amd64 /opt/blackbox_exporter
准备启动文件
[Unit] Description=blackbox_exporter Exporter Wants=network-online.target After=network-online.target [Service] ExecStart=/opt/blackbox_exporter/blackbox_exporter --config.file=/opt/blackbox_exporter/blackbox.yml StandardOutput=syslog StandardError=syslog SyslogIdentifier=blackbox_exporter [Install] WantedBy=default.target
启动
systemctl start blackbox_exporter.service
systemctl enable blackbox_exporter.service
systemctl status blackbox_exporter.service
示例
URL测试
http://192.168.168.106:9115/probe?target=https://www.baidu.com&module=http_2xx&debug=true
配置文件-http
- job_name: 'blackbox-http' metrics_path: /probe params: module: [http_2xx] static_configs: - targets: - http://prometheus.io - https://www.baidu.com - http://192.168.168.106:3000 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9115
配置文件-ssh
- job_name: 'blackbox-ssh' metrics_path: /probe params: module: [ssh_banner] static_configs: - targets: - 192.168.168.105 - 192.168.168.106 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.168.106:9115
配置文件-icmp
- job_name: 'blackbox-icmp' metrics_path: /probe params: module: [icmp] static_configs: - targets: - 192.168.168.105 - 192.168.168.106 labels: instance: node_status group: 'node' relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.168.106:9115
配置文件-端口状态
- job_name: 'blackbox-port' metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: - 192.168.168.105:3000 labels: instance: 'port_status' group: 'tcp' relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.168.106:9115