这是领事中许多服务中的两种服务的样子:
"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
}
这些服务中的每一项都有健康检查。
我的目标是找到所有基于 consul KV 的健康服务。比如,在"USA"中找到所有“通过”的服务,或者在"CANADA"中找到所有“关键”服务。
我尝试了一些选项,我遇到的问题是所有指标都有 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