blackbox
blackbox 是go 语言编写,通过http https icmp dns tcp 来探测端点并返回指标给promethues
第一步:安装blackbox
blackbox 默认配置blackbox.yml
可以不做任何修改,具体监控项在prometheus.yml中。下载
-
下载
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz tar xf blackbox_exporter-0.24.0.linux-amd64.tar.gz -
修改配置
注释:prober 英文释义 探测器
默认配置文件 cat blackbox.yml
modules: http_2xx: prober: http http: preferred_ip_protocol: "ip4" http_post_2xx: prober: http http: method: POST tcp_connect: prober: tcp pop3s_banner: prober: tcp tcp: query_response: - expect: "^+OK" tls: true tls_config: insecure_skip_verify: false grpc: prober: grpc grpc: tls: true preferred_ip_protocol: "ip4" grpc_plain: prober: grpc grpc: tls: false service: "service1" ssh_banner: prober: tcp tcp: query_response: - expect: "^SSH-2.0-" - send: "SSH-2.0-blackbox-ssh-check" irc_banner: prober: tcp tcp: query_response: - send: "NICK prober" - send: "USER prober prober prober :prober" - expect: "PING :([^ ]+)" send: "PONG ${1}" - expect: "^:[^ ]+ 001" icmp: prober: icmp icmp_ttl5: prober: icmp timeout: 5s icmp: ttl: 5 -
启动blackbox
# 监听:9155 ./blackbox_exporter -
功能验证,
probe_success 1
表示探测成功curl -s http://10.4.7.251:9115/probe?module=http_2xx&target=www.baidu.com|grep -i "probe_success" probe_success 1
第二步: 在prometheus中添加监控
prometheus.yml
事例中以http_2xx和 icmp 模块为例
- job_name: 'blackbox-http' metrics_path: /probe params: module: [http_2xx] # 指定模块 static_configs: - targets: - http://prometheus.io # Target to probe with http. - https://prometheus.io # Target to probe with https. - http://example.com:8080 # Target to probe with http on port 8080. - https://www.baidu.com relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 10.4.7.50:9115 - job_name: 'blackbox-icmp' metrics_path: /probe params: module: [icmp] # 指定模块 static_configs: - targets: - 8.8.8.8 - 10.4.7.254 - 10.4.7.11 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 10.4.7.50:9115
第三步: 在prometheus中查看监控项,probe_success=1 表示在线
主要指标 | 解释 | |
---|---|---|
probe_dns_lookup_time_seconds |
dns解析耗时 | |
probe_duration_seconds |
探测耗时 | |
probe_http_status_code |
解析状态码 | 200 |
probe_success |
探测是否成功 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏