【问题标题】:Add prefix to graphite micrometer event in spring-boot在 spring-boot 中为石墨千分尺事件添加前缀
【发布时间】:2018-04-17 08:00:55
【问题描述】:

我正在使用spring-boot 2graphite。我想为我的所有指标添加前缀。

@Bean
public MeterRegistry graphiteRegistsry() {
    return new GraphiteMeterRegistry(
           GraphiteConfig.DEFAULT, Clock.SYSTEM,
           (id, convention) -> "prefix." + 
           HierarchicalNameMapper.DEFAULT.toHierarchicalName(id,convention));
}

如果我使用此代码,这实际上是添加前缀,但也会创建一些没有前缀的指标。似乎他们几乎所有的指标都是重复的。

如何添加此前缀?并且从这个应用程序到石墨的所有指标都将包含前缀?

谢谢。

【问题讨论】:

    标签: java spring-boot metrics graphite micrometer


    【解决方案1】:

    首先,您可以使用MeterRegistryCustomizer添加一个通用标签:

    @Configuration
    public class MetricsConfig {
      @Bean
      public MeterRegistryCustomizer<MeterRegistry> commonTags() {
        return r -> r.config().commonTags("commonTag", "somePrefix");
      }
    }
    

    其次,扩展您的应用程序属性,将此标记转换为前缀:

    management.metrics.export.graphite.tags-as-prefix=commonTag
    

    请看详细解释here

    【讨论】:

    • 我试过了,不知道我上次做错了什么
    • 这适用于 statsd 配置吗?我的 springboot 应用程序有以下配置。 statsd: host: "localhost" port: 8125 enabled: true prefix: ${spring.application.name}
    猜你喜欢
    • 2020-06-19
    • 2020-12-30
    • 2021-02-28
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多