首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在prometheus中使用blackbox_exporter ping目标

如何在prometheus中使用blackbox_exporter ping目标
EN

Stack Overflow用户
提问于 2019-04-05 07:56:42
回答 1查看 10.2K关注 0票数 4

我正在尝试使用prometheus的blackbox_exporter对目标列表执行ping操作,但我似乎只能探测到blackbox_exporters,而不能探测我想要检查的实际目标。

我在blackbox中找不到任何关于在哪里列出目标的文档,所以我做了一个奇怪的假设,它使用了prometheus配置中提供的目标,但据我所知,这只是让prometheus相信有很多黑盒需要探测。

这是我的blackbox_exporter配置

代码语言:javascript
运行
复制
 modules:
  icmp:
    prober: icmp
    timeout: 5s
    icmp:
      preferred_ip_protocol: ip4

然而,当我访问blackbox的web GUI时,配置包含一堆我没有指定的参数。

代码语言:javascript
运行
复制
modules:
  icmp:
    prober: icmp
    timeout: 5s
    http:
      ip_protocol_fallback: true
    tcp:
      ip_protocol_fallback: true
    icmp:
      preferred_ip_protocol: ip4
      ip_protocol_fallback: true
    dns:
      ip_protocol_fallback: true

这是我的普罗米修斯配置

代码语言:javascript
运行
复制
global:
  scrape_interval:     15s
  evaluation_interval: 15s

  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets:
        - icmp-target1 # supposed to be a switch, router, pc or anything that responds to ping
        - icmp-target2

预期结果:在旅途中的某个地方,我希望我的目标会被blackbox和prometheus pinged,收集结果。

实际结果: Prometheus通过HTTP为其目标列表中列出的每个目标发送探测请求。

EN

Stack Overflow用户

回答已采纳

发布于 2019-04-06 16:54:59

尽管有些令人困惑,但blackbox_exporter自述文件确实解释了如何配置它,请参阅Prometheus Configuration一节。

您的黑盒配置是正确的。

对于您的Prometheus配置,您需要类似以下内容。我假设黑盒导出器和普罗米修斯是并置的(因此是localhost),否则就是适应。

代码语言:javascript
运行
复制
# this is to scrape blackbox itself (this is optional)
- job_name: blackbox
  static_configs:
  - targets: ['localhost:9115']


- job_name: blackbox-ping
  metrics_path: /probe
  params:
    module: [icmp]
  static_configs:
    - targets:
      - 192.168.1.1   # <== Put here your targets
  relabel_configs:    # <== This comes from the blackbox exporter README
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: localhost:9115 # Blackbox exporter.

另一个令人困惑的部分是回答这个问题:“如何将blackbox exporter用于多种协议,比如ICMP和HTTP?”在这种情况下,有多种选择,但更清楚的是每个协议都有一个部分。这就是我将ICMP探测器称为blackbox-ping的原因。假设我们还想拥有HTTP探测器,我们将添加另一个部分:

代码语言:javascript
运行
复制
- job_name: blackbox-http
  metrics_path: /probe
  params:
    module: [http_2xx]
  static_configs:
    - targets:
      - https://www.google.com  # <== your targets here
  relabel_configs:              # <== This comes from the blackbox exporter README
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: localhost:9115 # Blackbox exporter.

您还需要相应的黑盒配置:

代码语言:javascript
运行
复制
modules:
  http_2xx:        # <== This is the new section for HTTP
    prober: http
    timeout: 10s   # <== This depends on what you want to do
    http:
      valid_status_codes: []  # Defaults to 2xx
      method: HEAD              # <== This depends on what you want to do
      no_follow_redirects: true # <== this depends on what you want to do
  icmp:                         # <== this is the one you already have
    prober: icmp
    timeout: 10s                # <== This depends on what you want to do
    icmp:
      preferred_ip_protocol: ip4
票数 9
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55526487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档