Prometheus似乎正在以错误的方式为目标实例标记和设置其他元数据,这可能是由于配置错误所致。
这里是配置,用于抓取多个目标并标记每个目标:
global:
scrape_interval: 5s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
labels:
host: 'Server0'
service: 'Prometheus'
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
labels:
host: 'Server0'
- job_name: 'wmi_exporter'
static_configs:
- targets: ['xxx.xxx.xxx.xxx:9100']
labels:
host: 'Server1'
- targets: ['xxx.xxx.xxx.xxx:9100']
labels:
host: 'Server2'
所有目标在Prometheus管理界面中都显示为UP。但是,当我对prometheus_sd_discovered_targets
运行查询时,它返回的目标具有相同的job
名称,instance
地址,host
和service
标签:
prometheus_sd_discovered_targets{config="node_exporter",host="Local",instance="localhost:9090",job="prometheus",name="scrape",service="Prometheus"} 1
prometheus_sd_discovered_targets{config="prometheus",host="Local",instance="localhost:9090",job="prometheus",name="scrape",service="Prometheus"} 1
prometheus_sd_discovered_targets{config="wmi_exporter",host="Local",instance="localhost:9090",job="prometheus",name="scrape",service="Prometheus"} 2
为什么元数据值对于所有目标而言都是相同的,即使它们的配置和标签不同?
答案 0 :(得分:1)
prometheus_sd_discovered_targets
是Prometheus(不是节点导出器,不是wmi导出器)导出的度量标准,因此所有这些时间序列都来自您唯一的Prometheus实例,即host="Local",instance="localhost:9090",job="prometheus",service="Prometheus"
。
name="scrape",config="wmi_exporter"
标签来自度量标准本身,因为如果您选中http://localhost:9090/metrics
,则会发现(其中包括)以下内容:
prometheus_sd_discovered_targets{name="scrape",config="node_exporter"} 1
prometheus_sd_discovered_targets{name="scrape",config="prometheus"} 1
prometheus_sd_discovered_targets{name="scrape",config="wmi_exporter"} 2