如何重新标记consul sd config以获取基于领事元数据的服务发现统计信息?

时间:2019-05-08 19:00:46

标签: prometheus consul service-discovery promql

这是领事中的两种服务的样子:

    "1": {
        "ID": "1",
        "Service": "Service X",
        "Meta": {
              "country": "USA"
        },
        "Port": 0,
        "Address": "1.1.1.1",
        "Weights": {
            "Passing": 1,
            "Warning": 1
        },
        "EnableTagOverride": false
    }

    "2": {
        "ID": "2",
        "Service": "Service Y",
        "Meta": {
              "country": "CANADA"
        },
        "Port": 0,
        "Address": "2.2.2.2",
        "Weights": {
            "Passing": 1,
            "Warning": 1
        },
        "EnableTagOverride": false
    }

每个服务都有健康检查。

我的目标是根据领事KV找到所有健康的服务。例如,在“美国” 中找到所有“通过” 的服务,或者在“加拿大”中找到所有“关键” 的服务。

我尝试了一些选项,我遇到的问题是所有指标都有config.yaml中提到的每个重新标记

查询1

consul_health_service_status{status="passing", instance="USA"}

输出

  

consul_health_service_status {check =“ service:1”,instance =“ USA”,job =“ consul”,node =“ machine”,service_id =“ 1”,service_name =“ Service   X“,status =” passing“} 1

     

consul_health_service_status {check =“ service:2”,instance =“ USA”,job =“ consul”,node =“ machine”,service_id =“ 2”,service_name =“ Service   Y“,status =” passing“} 1

查询2

consul_health_service_status{status="passing", instance="CANADA"}

输出

  

consul_health_service_status {check =“ service:1”,instance =“ CANADA”,job =“ consul”,node =“ machine”,service_id =“ 1”,service_name =“ Service   X“,status =” passing“} 1

     

consul_health_service_status {check =“ service:2”,instance =“ CANADA”,job =“ consul”,node =“ machine”,service_id =“ 2”,service_name =“ Service   Y“,status =” passing“} 1

配置

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'consul'
    consul_sd_configs:
      - server: 'localhost:8500'
        services: []
    relabel_configs:
      - source_labels: [__meta_consul_service_metadata_country]
        target_label: instance
      - source_labels: ['__meta_consul_address']
        separator: ';'
        target_label:  '__address__'
        replacement: 'localhost:9107'
        action: 'replace'

我很想看到类似这样的输出

查询1

consul_health_service_status{status="passing", instance="USA"}

输出

  

consul_health_service_status {check =“ service:1”,instance =“ USA”,job =“ consul”,node =“ machine”,service_id =“ 1”,service_name =“ Service   X“,status =” passing“} 1

查询2

consul_health_service_status{status="passing", instance="CANADA"}

输出

  

consul_health_service_status {check =“ service:2”,instance =“ CANADA”,job =“ consul”,node =“ machine”,service_id =“ 2”,service_name =“ Service   Y“,status =” passing“} 1

0 个答案:

没有答案