1and1internet/blackbox_exporterdocker_blackbox_exporter是基于Prometheus Blackbox Exporter的Docker镜像,特别集成了自定义根证书支持。Blackbox Exporter是Prometheus生态中的核心探针工具,通过模拟HTTP、HTTPS、DNS、TCP、ICMP等网络请求,采集目标端点的可用性、响应时间、状态码等监控指标。本镜像在原生功能基础上增强了证书配置能力,可便捷集成私有CA证书,适用于企业私有环境或需要自定义证书链的监控场景。
config.yml)定义探测规则(模块)/metrics端点,可直接被Prometheus服务器抓取指标bashdocker run -d \ --name blackbox-exporter \ --restart=always \ -p 9115:9115 \ # 默认暴露端口 -v /path/to/your/config.yml:/etc/blackbox_exporter/config.yml \ # 挂载自定义配置文件 -v /path/to/rootca:/etc/blackbox_exporter/rootca \ # 挂载自定义根证书目录 docker_blackbox_exporter
| 参数 | 说明 |
|---|---|
-p 9115:9115 | 端口映射,暴露Blackbox Exporter默认监听端口(容器内不可修改) |
--cap-add=NET_RAW | (可选)启用ICMP协议探测时需添加,赋予容器网络原始套接字权限 |
| 配置文件挂载 | 必须挂载自定义config.yml到/etc/blackbox_exporter/config.yml |
| 证书挂载 | 自定义根证书文件需挂载到容器内指定目录(如/etc/blackbox_exporter/rootca/) |
yamlmodules: # HTTP端点探测模块(基础2xx状态码检测) http_2xx: prober: http timeout: 10s # 超时时间 http: valid_status_codes: [200, 201, 204] # 允许的状态码 method: GET # 请求方法 headers: Host: "example.com" # 自定义HTTP头 no_follow_redirects: false # 是否跟随重定向 # HTTPS端点探测模块(带自定义根证书) https_custom_ca: prober: http timeout: 15s http: valid_status_codes: [200] tls_config: ca_file: /etc/blackbox_exporter/rootca/internal_ca.crt # 引用自定义根证书 insecure_skip_verify: false # 禁用跳过证书验证(依赖自定义CA) # TCP端口探测模块(数据库端口示例) tcp_mysql: prober: tcp timeout: 5s tcp: query_response: - send: "SELECT 1;" # 发送测试命令 - expect: "1" # 预期响应内容 # ICMP协议探测模块(主机存活检测) icmp_ping: prober: icmp timeout: 5s icmp: preferred_ip_protocol: "ip4" # 优先IPv4 ttl: 64 # 生存时间(跳数)
在Prometheus的prometheus.yml中添加如下配置,抓取Blackbox Exporter指标:
yamlscrape_configs: - job_name: 'blackbox' metrics_path: /probe # Blackbox Exporter探测端点 params: module: [https_custom_ca] # 默认使用的探测模块(对应config.yml中的模块名) static_configs: - targets: - [***] # 私有HTTPS服务(使用自定义CA) - tcp://mysql.example.com:3306 # MySQL数据库端口 - icmp://server.example.com # 主机ICMP探测(需Blackbox启用NET_RAW权限) relabel_configs: # 将目标地址作为探测参数 - source_labels: [__address__] target_label: __param_target # 将目标地址作为实例标签 - source_labels: [__param_target] target_label: instance # 指向Blackbox Exporter地址(容器名或IP:端口) - target_label: __address__ replacement: blackbox-exporter:9115
ICMP协议权限:使用ICMP探测时,需在docker run命令中添加--cap-add=NET_RAW,或在Kubernetes中配置securityContext.capabilities.add: ["NET_RAW"]。
配置文件更新:修改config.yml后需重启容器或发送SIGHUP信号(docker kill -s SIGHUP <container_id>)使配置生效。
证书文件权限:挂载的证书文件需确保容器内用户(默认nobody)有读取权限,建议设置文件权限为644。
资源限制:根据探测目标数量调整容器CPU/内存资源,大量并发探测(如1000+目标)建议分配至少1CPU核心和512MB内存。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务