首页 > 解决方案 > 按名称堆叠/重叠指标

问题描述

我有一个通过 micrometer-jmx 向 prometheus 发送指标的应用程序,我无法将应用程序更改为使用 micrometer-prometheus。因此,所有参数化指标都不是普罗米修斯标签,而是直接编码到指标名称中。

即,而不是requests_Count{processor="BILLING_PROCESSOR", type="SCRIPT"}指标的形式是requests_PRC_BILLING_PROCESSOR_TYP_SCRIPT_Count

现在假设我想要一个按类型分组(堆叠/重叠)的请求计数的 grafana 图表。有没有什么方法可以在没有标签和这种格式的指标的情况下完成?我已经设法构建了 grafana 变量,这些变量从指标名称中提取处理器和类型值,但我似乎对这些值无能为力。

标签: jmxgrafanaprometheus

解决方案


您可以配置 Prometheus 来转换指标名称。这是 Prometheus 中可用的重新标记的一部分。它在Prometheus 配置核心贡献者之一的博客文章中进行了描述。

从博客文章中提取的指标可以从

memory_pools_PS_Eden_Space_committed

memory_pools_committed_bytes{pool="PS_Eden_Space"}

通过应用如下配置:

scrape_configs:
  job_name: my_job
  # Usual fields go here to specify targets.
  metric_relabel_configs:
  - source_labels: [__name__]
    regex: '(memory_pools)_(.*)_(\w+)'
    replacement: '${2}'
    target_label: pool
  - source_labels: [__name__]
    regex: '(memory_pools)_(.*)_(\w+)'
    replacement: '${1}_${3}_bytes'
    target_label: __name__

推荐阅读