You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何拆分Prometheus实例标签新增nodegroup与core标签?

可行方案:拆分Prometheus指标标签

Prometheus 侧实现

使用 relabel_configs 可实现该需求,在Prometheus配置中添加以下规则:

relabel_configs:
  - source_labels: [instance]
    regex: '([0-9]+),([0-9]+)'
    target_label: nodegroup
    replacement: '$1'
  - source_labels: [instance]
    regex: '([0-9]+),([0-9]+)'
    target_label: core
    replacement: '$2'

通过正则匹配instance标签的数字,数字格式,分别提取两组匹配值作为nodegroup和core标签的内容,原instance标签会被保留。

OpenTelemetry Collector 侧实现

使用OTTL处理器可精准完成标签拆分,以下是正确的配置示例:

processors:
  transform:
    metric_statements:
      - context: datapoint
        statements:
          # 按逗号拆分instance标签值,提取对应元素作为新标签
          - set(attributes["nodegroup"], parse_split(attributes["instance"], ",", 0))
          - set(attributes["core"], parse_split(attributes["instance"], ",", 1))

将该transform处理器加入指标处理管道:

service:
  pipelines:
    metrics:
      receivers: [你的指标接收器]
      processors: [transform, 其他处理器]
      exporters: [你的指标导出器]

parse_split函数会把instance的值按逗号拆分为数组,索引0对应第一个元素("3"),索引1对应第二个元素("9"),最终将这两个值分别赋值给新标签nodegroup和core。

内容的提问来源于stack exchange,提问作者rismoney

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 16:42:06