【问题标题】:How to ping targets using blackbox_exporter with prometheus如何使用带有 prometheus 的 blackbox_exporter ping 目标
【发布时间】:2019-04-04 23:56:42
【问题描述】:

我正在尝试使用带有 prometheus 的 blackbox_exporter ping 一个目标列表,但我似乎只能探测 blackbox_exporters 而不是我想要检查的实际目标。

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

这是我的 blackbox_exporter 配置

 modules:
  icmp:
    prober: icmp
    timeout: 5s
    icmp:
      preferred_ip_protocol: ip4

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

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

这是我的普罗米修斯配置

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 ping 到,并收集结果。

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

【问题讨论】:

    标签: prometheus prometheus-blackbox-exporter


    【解决方案1】:

    虽然有点混乱,但 blackbox_exporter README 确实解释了如何配置它,请参阅 Prometheus Configuration 部分。

    你的黑盒配置是正确的。

    对于您的 Prometheus 配置,您需要以下内容。我假设黑盒导出器和 Prometheus 位于同一位置(因此是 localhost),否则适应。

    # 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.
    

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

    - 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.
    

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 1970-01-01
      • 2020-07-07
      • 2021-10-31
      相关资源
      最近更新 更多