如何使用千分尺指定我想在 spring-boot 中使用的指标的白名单 [英] How to specify a whitelist of the metrics I want to use in spring-boot with micrometer
问题描述
我们只想在我们的 spring-boot 应用程序中使用来自 micrometer 的一些给定指标.我们在文档中找到以下代码片段.这将默认禁用所有指标,并使我们能够创建可能指标的白名单.
We want to use only some of the given metrics from micrometer in our spring-boot application. We find the following code-snippet in the docs. This should disable all metrics by default and should enable us to create a whitelist of possible metrics.
management.metrics.enable.root=false
management.metrics.enable.jvm=true
问题是,它不起作用.所有现有指标都写入我们的石墨实例.
The problem is, that it doesn't work. All existing metrics are written to our graphite instance.
我们已经找到了一种解决方法,但我们想在我们的属性文件中编辑我们的指标.
We found already a workaround but we would like to edit our metrics in our property files.
这是我们目前的解决方法:
This is our current workaround:
@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.");
}
}
有没有人有任何经验可以分享,我们必须考虑在属性文件配置中达到这个目标?
Do anyone has any experience to share, what we have to think of to reach this goal within the property-file configuration?
推荐答案
你需要使用 management.metrics.enable.all=false
而不是 management.metrics.enable.root=false
因为该属性已被删除.我有同样的要求将指标列入白名单,然后选择所需的指标.这篇博文已过时,Spring Boot 开发人员在 gitter 上建议使用 management.metrics.enable.all=false
.
You need to use management.metrics.enable.all=false
not management.metrics.enable.root=false
as that property has been removed.
I had the same requirement to whitelist the metrics and just choose the required ones. The blog post is out of date and was advised to use management.metrics.enable.all=false
by the Spring Boot devs on gitter.
这篇关于如何使用千分尺指定我想在 spring-boot 中使用的指标的白名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!