Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
–
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;
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.