java - 在 spring-boot 中为 Graphite 千分尺事件添加前缀

标签 java spring-boot metrics graphite micrometer

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

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

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

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

谢谢。

最佳答案

首先,您可以使用 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

关于java - 在 spring-boot 中为 Graphite 千分尺事件添加前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49872765/

相关文章:

java - AWS Redshift Posix 模式匹配

java - 正在加载重复的 Spring 配置?

tomcat - Spring Boot 重定向到 https

java - 错误 java.lang.ClassNotFoundException : com. fastxml.jackson.databind.Module

java - keycloak (spring boot) 不验证 REST 端点

python-3.x - “torchmetrics”不适用于 PyTorchLightning

apache-spark - Spark Streaming 处理时间 vs 总延迟 vs 处理延迟

php - mySQL - 大型指标表和繁重的查询性能 - 缓存?

java - 在 ViewSwitcher 中切换不确定的 ProgressBar 和 Image

java - Android CheckBox增量错误