Reputation: 1040
I have a java application written on top of Spring Boot and I can see the metrics being generated through the /metrics
management API. I would like to filter the metrics that are being generated (based on metric prefix) and print to stdout OR send the selected metrics to a 3rd party aggregator (not the ones referenced here)
I tried the code suggested by this answer but it didn't result in any metrics being written to the stdout. This is what I added to my Application.java
class:
@Bean
@ServiceActivator(inputChannel = "metricsChannel")
public MessageHandler metricsHandler() {
return System.out::println;
}
What is the best way to intercept the metrics on a preconfigured cadence so I can process and write them to stdout or publish them to an aggregator?
Thanks.
Upvotes: 2
Views: 1315
Reputation: 121272
Looks like it's a bug in the Spring Boot: https://github.com/spring-projects/spring-boot/issues/5517.
We have to declare something like this ourselves as a workaround:
@Bean
public MessageChannel metricsChannel() {
return new DirectChannel();
}
@Bean
@ExportMetricWriter
public MessageChannelMetricWriter messageChannelMetricWriter() {
return new MessageChannelMetricWriter(metricsChannel());
}
@Bean
@ServiceActivator(inputChannel = "metricsChannel")
public MessageHandler metricsHandler() {
return System.out::println;
}
Upvotes: 1