【问题标题】:How to specify a whitelist of the metrics I want to use in spring-boot with micrometer如何使用千分尺指定我想在spring-boot中使用的指标的白名单
【发布时间】:2023-03-23 10:59:01
【问题描述】:

我们只想在我们的 spring-boot 应用程序中使用来自 micrometer 的一些给定指标。我们在文档中找到了以下代码-sn-p。默认情况下,这应该会禁用所有指标,并使我们能够创建可能指标的白名单。

Spring blog about Micrometer metrics

management.metrics.enable.root=false
management.metrics.enable.jvm=true

问题是,它不起作用。所有现有指标都写入我们的石墨实例。

我们已经找到了一种解决方法,但我们想在我们的属性文件中编辑我们的指标。

这是我们当前的解决方法:

@Configuration
public class MicrometerGraphiteConfig {

    @Bean
    public MeterRegistryCustomizer<MeterRegistry> commonTags() {
        return registry -> registry
            .config()
            .meterFilter(MeterFilter.denyUnless(this::isMetricToInclude))
            .commonTags("a_tag", "some_common_tags");
    }

    private boolean isMetricToInclude(Meter.Id id) {
        return id.getName().startsWith("jvm.");
    }
}

有没有人有任何经验可以分享,我们必须考虑什么才能在属性文件配置中实现这一目标?

【问题讨论】:

    标签: java spring-boot spring-micrometer


    【解决方案1】:

    您需要使用management.metrics.enable.all=false 而不是management.metrics.enable.root=false,因为该属性已被删除。 我有相同的要求将指标列入白名单并选择所需的指标。该博文已过时,gitter 上的 Spring Boot 开发人员建议使用 management.metrics.enable.all=false

    【讨论】:

    • 感谢您的回复,我会尝试该解决方案并通知您。
    • 我试过这个解决方案,效果很好。非常感谢。
    猜你喜欢
    • 2022-11-10
    • 2019-02-22
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 2022-06-22
    • 1970-01-01
    相关资源
    最近更新 更多