问题
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.
Spring blog about Micrometer 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?
回答1:
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.
来源:https://stackoverflow.com/questions/54422023/how-to-specify-a-whitelist-of-the-metrics-i-want-to-use-in-spring-boot-with-micr