8.prometheus远端探测监控-blackbox_exporter
一、远端探测介绍
监控应用程序的两种主要方法:探测和内省(例:node_exporter)。
探测监视应用程序的外部,可以查询应用程序的外部特征:是否响应开放端口上的轮询并返回正确的数据或响应代码?eg:执行ICMP ping或echo检查并确认是否收到了响应。这种类型的探测也称为黑盒探测,将内部应用程序视为黑盒。
Prometheus探测工作是通过blackbox_exporter 来探测远程目标,并公开在本地端点上收集的任何时间序列。然后,Prometheus从端点中提取指标。
探测有三个限制:
-
能到到达探测的资源池
-
探测的位置能够访问到应用程序资源的正确路径。
-
探测exporter的位置能够被prometheus-server scape。
二、远端探测配置blackbox_exporter
1、概述
blackbox_exporter是一个二进制Go应用程序,默认监听端口9115。exporter允许通过HTTP、HTTPS、DNS、TCP和ICMP探测端点。在exporter中,我们定义一系列执行特定检查的模块,例:检查正在运行的web服务器,或者DNS解析记录。当exporter运行时,它会在URL上公开这些模块和API。
2、安装配置
安装配置blackbox_exporter
[root@master soft]# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz [root@master soft]# tar xf blackbox_exporter-0.16.0.linux-amd64.tar.gz [root@master soft]# mv blackbox_exporter-0.16.0.linux-amd64 /opt/prometheus/blackbox_exporter [root@master blackbox_exporter]# vim blackbox.yml #只添加简单检测,更多配置参考官方文档 modules: http_2xx: prober: http timeout: 5s http: valid_status_codes: [] method: GET icmp_check: prober: icmp timeout: 5s icmp: preferred_ip_protocol: "ipv4" dns_examplecom_check: prober: dns dns: preferred_ip_protocol: "ipv4" query_name: "baidu.com" [root@master blackbox_exporter]# nohup ./blackbox_exporter --config.file="prober.yml" &
浏览器访问: http://192.168.42.128:9115/ 可以看到指标
prometheus配置添加一个job
[root@node1 prometheus]# vim prometheus.yml ...... - job_name: black_exporter metrics_path: /probe params: modules: [http_2xx_check] static_configs: - targets: - 192.168.42.128:9115 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.42.128:9115 [root@node1 prometheus]# docker restart prometheus-server
访问prometheus web页面,可以看到已经检测了。

查看metric:
访问blackbox_exporter的web页面,也可以看到Recent Probes。
分类:
监控
标签:
prometheus
, 监控
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!