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

如何配置WildFly Micrometer修改app与job标签值

修改WildFly指标的app和job标签方法

方法一:在WildFly配置中直接定义标签

编辑WildFly的standalone.xml或domain.xml,找到<micrometer>配置节点,添加自定义标签覆盖默认值:

<micrometer>
    <metrics>
        <tags>
            <tag key="app" value="wildfly_app_1"/>
            <tag key="job" value="wildfly_job_1"/>
        </tags>
    </metrics>
</micrometer>

配置完成后重启WildFly即可生效,这种方式直接从指标源头修改标签。

方法二:通过OpenTelemetry Collector处理标签

修改OpenTelemetry Collector的配置文件(如otel-collector-config.yaml),用attributes处理器修改标签:

  1. 定义处理器规则:
processors:
  attributes/custom_tags:
    actions:
      - action: upsert
        key: app
        value: "wildfly_app_1"
      - action: upsert
        key: job
        value: "wildfly_job_1"
  1. 将处理器加入metrics pipeline:
service:
  pipelines:
    metrics:
      receivers: [你的指标接收器]
      processors: [attributes/custom_tags, batch]
      exporters: [prometheus]

重启Collector后,所有经过它的WildFly指标都会被替换成指定的app和job标签,适合统一管理多个服务实例的标签规则。

方法三:在Prometheus中调整标签

如果不想改动上游服务或Collector,可在Prometheus的prometheus.yml中通过配置修改标签:

方式1:添加静态标签

scrape_configs:
  - job_name: 'wildfly_job_1'
    static_configs:
      - targets: ['otel-collector:9090']
    labels:
      app: 'wildfly_app_1'
      job: 'wildfly_job_1'

方式2:覆盖原有标签(如果需要替换默认值)

scrape_configs:
  - job_name: 'wildfly_job_1'
    static_configs:
      - targets: ['otel-collector:9090']
    metric_relabel_configs:
      - source_labels: [app]
        target_label: app
        replacement: 'wildfly_app_1'
      - source_labels: [job]
        target_label: job
        replacement: 'wildfly_job_1'

配置后重启Prometheus,即可在Prometheus中看到修改后的标签。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 18:07:13