prometheus - Prometheus 中的实例标签问题
问题描述
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 管理 UI 中显示为 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
为什么所有目标的元数据值都相同,即使它们的配置和标签不同?
解决方案
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
推荐阅读
- python-3.x - 为特定数据选择 ε 有什么问题?
- ruby-on-rails - 如何扩展 ActionView::Template::Types
- xamarin - 使用 Real To Tap() 警报上的“确定”按钮
- arrays - 使用循环获取一组元素
- c++ - LOKI C++:“ScatterHierarchyTag”如何解决继承歧义?
- oracle - Oracle Pl/SQL 循环仅在记录插入表时返回
- regex - perl 单行中转义和捕获的正确语法是什么?
- python-3.x - 将字符串添加到列表正在创建字符列表
- sql-server - TSQL - 枢轴不返回所有行
- excel-formula - 在 Excel 中搜索后查找最后一个值