For your second question, I have used this pattern to customize the meter registry in a SpringBoot application. In the example, I only care about cache.[gets|puts|evictions]
and not all the JVM values etc.
See the Micrometer MeterFilter docs for more background.
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterFilter;
@Bean
public MeterRegistryCustomizer<MeterRegistry> buildMeterRegistry() {
return new MeterRegistryCustomizer<MeterRegistry>() {
@Override
public void customize(MeterRegistry registry) {
registry.config()
.meterFilter(MeterFilter.denyUnless(meter -> meter.getName().startsWith("cache")))
.meterFilter(MeterFilter.denyNameStartsWith("cache.removals"));
}
};
}
I had also discovered a slightly different way to load properties from the environment (question 1), if it helps.
@Bean
public LoggingMeterRegistry loggingMeterRegistry(Environment environment) {
LoggingRegistryConfig config = new LoggingRegistryConfig() {
final Environment env = environment;
@Override
public String get(String key) {
return env.getProperty(key);
}
@Override
public String prefix() {
// Whatever prefix you want to use in the application.yml
return "sample.metric.logging";
}
};
LOG.info("Creating LoggingMeterRegistry, logging every {} seconds", config.step().get(ChronoUnit.SECONDS));
return new LoggingMeterRegistry(config, Clock.SYSTEM);
}
application.yml
I looked at the code to identify what the property names are and picked a couple for demonstration.
sample:
metric:
logging:
logInactive: true
step: 5000ms