Prometheus scrape /metric with custom header

Prometheus scrape /metric with custom header

我有一个将由 Prometheus 监控的应用程序, 但是应用程序需要自定义 header 键,例如:

x-auth-token: <customrandomtoken>

我应该用 prometheus.yml 做什么?

Prometheus 本身无法定义自定义 headers 以到达出口商。 this GitHub issue 中讨论了添加该功能的想法。 Tl;dr:如果您需要自定义 header,请将其注入正向或反向代理。

prometheus-blackbox-exporter 标签表明问题是关于制作探测器的出口商,这是一个单独的事情,它确实有办法设置 headers。只是,它不会抓取指标,而是让它们

Blackbox 导出器有自己的配置文件,它由 模块 组成。模块是一组参数,定义了如何进行探测以及预期的结果。这是一个查找 200-299 响应代码并使用 X-Auth-Token header:

的模块示例
modules:
  http_2xx_with_header:
    prober: http
    http:
      headers:
        X-Auth-Token: skdjfh98732hjf22exampletoken

可以找到更多示例 here and the list of configuration options - here

当您让黑盒导出器加载新配置时,您还需要调整 Prometheus 配置:

scrape_configs:
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx_with_header]  # <- Here goes the name of the new module
    static_configs:
      - targets:
        - http://prometheus.io
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115