如何使用联合从多个Prometheus实例(每个使用instance ="localhost:9090")收集Prometheus的指标

Pet*_*aný 3 prometheus

我们在数据中心运行了多个Prometheus实例(我将它们称为DC Prometheus实例),另外还有一个Prometheus实例(我们在下文中称之为"main"),我们从DC Prometheus实例中收集指标.使用联合功能.

主要普罗米修斯正在从自身中抓取{job ='prometheus'}值,但也来自DC Prometheus实例(每次从localhost:9090抓取).

问题是Main prometheus抱怨无序样本:

WARN [1585]摄取无序样本时出错numDropped = 369 source = target.go:475 target = dc1-prometheus:443

我发现这是因为包含{job="prometheus"}在'match []'参数中.

我试图通过标签重新贴标来解决这个问题,但是当我尝试使用单个DC Prometheus并且不断更换时,我无法让它工作(我仍然会出现乱序样本错误),而且我不知道甚至不知道在使用多个目标时使用什么作为替代品.

  - job_name: 'federate'
    scrape_interval: 15s

    honor_labels: true
    metrics_path: '/prometheus/federate'
    scheme: 'https'

    params:
      'match[]':
        - '{job="some-jobs-here..."}'
        - '{job="prometheus"}'

    relabel_configs:
    - source_labels: ['instance']
      target_label: 'instance'
      regex: 'localhost:9090'
      replacement: '??' # I've tried with 'dc1-prometheus:9090' and single target only.. no luck

    target_groups:
      - targets:
        - 'dc1-prometheus'
        - 'dc2-prometheus'
        - 'dc3-prometheus'
Run Code Online (Sandbox Code Playgroud)

我的问题是如何使用relabel_configs来摆脱乱序错误.我到处都在使用Prometheus 0.17.

bri*_*zil 8

您需要做的是external_labels在每个数据中心Prometheus服务器上指定唯一.这将导致他们在/federate端点上添加这些标签,并防止您遇到的冲突时间序列.

我关于联邦普罗米修斯的博客文章在这样的案例中有一个例子:http://www.robustperception.io/scaling-and-federating-prometheus/

(我应该补充说,这relabel_configs对你来说无法帮助,因为它只会改变目标标签.metric_relabel_configs改变从刮擦中回来的东西.见http://www.robustperception.io/life-of-a-label/)