Prometheus - Blackbox Exporter

BlackBox Exporter 顾名思义就是在应用程序的外部对其进行探测,

支持 HTTP、HTTPS、DNS、TCP、ICMP等方式对目标进行检测。


ICMP

cat prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs: 
  - job_name: "ICMP"
    metrics_path: /probe
    params:
      module: [icmp]
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - targets/blackbox-exporter-icmp.yml
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox-exporter-service:9115


cat targets/blackbox-exporter-icmp.yml

- targets: 
  - 119.29.29.29
  - 223.5.5.5


HTTP

cat prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs: 
  - job_name: "HTTP"
    metrics_path: /probe
    params:
      module: [http_2xx]
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - targets/blackbox-exporter-http.yml
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox-exporter-service:9115


cat targets/blackbox-exporter-http.yml

- targets: 
  - https://www.baidu.com
  - https://www.google.com


TCP

cat prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs: 
  - job_name: "TCP"
    metrics_path: /probe
    params:
      module: [tcp]
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - targets/blackbox-exporter-tcp.yml
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: blackbox-exporter-service:9115


cat targets/blackbox-exporter-tcp.yml

- targets: 
  - aliyun.com:443
  - huaweicloud.com:443



标签重改& 监控原理

将 [__address__] 输出到 __param_target,是为了 Prometheus 在BlackboxExporter采集时使用对应的域名

例如 Target 中设置的是 https://www.baidu.com 则 __address__ 为 https://www.baidu.com

Prometheus 采集时则使用 http://blackbox-exporter:9115/probe?module=http_2xx&target=https://www.baidu.com

Prometheus - Blackbox Exporter


由此可见,Prometheus 主动传递参数给 Blackbox 进行执行,并在 Blackbox 接口暴露出指标提供给 Prometheus 采集。

Prometheus - Blackbox Exporter


probe?module=http_2xx&target=https://www.google.com

http_2xx 为模块名称

https://www.google.com 为执行监控的目标


Grafana

Dashboard ID: 13659

Prometheus - Blackbox Exporter


Dashboard ID: 9965

需要额外安装饼图插件支持: grafana-cli plugins install grafana-piechart-panel

Prometheus - Blackbox Exporter


Trouble

报错: 通过 IPv6 连接不到目标

解决方案: 修改对应模块的IP协议为 IPv4

modules:
  http_2xx:
    prober: http
    http:
 preferred_ip_protocol: "ip4"
  icmp:
    prober: icmp
    icmp:
 preferred_ip_protocol: "ip4"
  tcp:
    prober: tcp
    tcp:
 preferred_ip_protocol: "ip4"

Refer: https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md



Debug

probe?target=119.29.29.29&module=icmp&debug=true

通过传递 debug=true 参数可以进行 Probe 过程中的调试

Prometheus - Blackbox Exporter


上一篇:Elasticsearch Document & Type & Index


下一篇:Elasticsearch Mapping & Setting