prometheus - 如何查看已为 Pushgateway 生成数据的实例的主机名
问题描述
我有 prometheus 服务器,它对运行 WMI 导出器的 Azure VM 使用自我发现。在 Grafana 中,我使用仪表板变量进行过滤(参见屏幕截图)。
在虚拟机上,我创建了一个自定义导出器,它为每个服务器输出值为 1 的指标,并且每个服务器将这些值发送到在 etc/prometheus/prometheus.yaml 中配置的单个 Pushgateway
- job_name: 'push-gateway'
static_configs:
- targets: ['localhost:9091']
当我查看抓取的指标时,我总是看到实例:localhost:9091 和作业:push-gateway,无论指标来自哪个服务器。如果我手动添加这些标签,我会看到“导出”前缀(见屏幕截图)。
我感到困惑的是,如何确保自定义创建的指标的“作业”和“实例”具有与生成指标的服务器匹配的相同“作业”和“实例”值,以便我可以使用仪表板为所选服务器提取正确数据的变量?
解决方案
您可以在抓取后使用metric_relabel_configs重写标签。一个例子:
- job_name: pushgateway
# This is necessary if metrics in pushgateway have "job" or "instance" labels.
# With "honor_labels: true" Prometheus will save those as "exported_job" and "exported_instance" respectively.
honor_labels: true
static_configs:
- targets:
- my-pushgateway.com:9091
metric_relabel_configs:
# copy pushgateway address from "instance" to "source" label
- source_labels: [instance]
target_label: source
# replace "instance" label value with one from "exported_instance" label
- source_labels: [exported_instance]
target_label: instance
# remove "exported_instance" label
- source_labels: [exported_instance]
action: labeldrop
如果您以前有这样的指标:
my_metric{job="pushgateway", instance="my-pushgateway.com:9091", exported_instance="example.com"}
然后使用上面示例中的配置,它们将如下所示:
my_metric{job="pushgateway", instance="example.com", source="my-pushgateway.com:9091"}
推荐阅读
- gsutil - 如何告诉 gsutil 文件上传命令“dst_url”实际上是一个文件,而不是一个目录?
- php - 如何在不重新安装 WAMP 的情况下将更新版本的 PHP 和 MySQL 添加到 WAMP 2.1?
- javascript - 使用 % 和获得奇数/偶数的最低有效位之间的区别
- aem - AEM Querybuilder - 如何仅返回路径下的文件夹?
- r - 计算 r 中每行列之间的移动差异
- ios - 使用 Scenekit 场景时间来擦洗动画 iOS
- r - Stream system() 输出到 Shiny 前端(连续)
- mysql - 带有条件的逗号出现的 SQL 平均值
- c# - 在表中插入行后出现重复错误,其中字段具有 INDEXED(DUPLICATES OK)
- reactjs - Docker 多阶段构建 - 复制失败