如何使用带有prometheus的blackbox_exporter ping目标

时间:2019-04-04 23:56:42

标签: prometheus prometheus-blackbox-exporter

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

我在黑匣子中找不到应该列出目标的任何文档,因此我做出了一个奇怪的假设,即它使用了prometheus配置中提供的目标,但据我了解,这使prometheus相信有有许多黑匣子可供探索。

这是我的blackbox_exporter配置

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

但是,当我访问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

预期结果: 在旅途中的某个地方,我希望黑匣子和普罗米修斯能够对目标执行ping操作。

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

1 个答案:

答案 0 :(得分:2)

blackbox_exporter自述文件虽然有些令人困惑,但确实说明了如何配置它,请参见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