Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Actuator Metrics generate logs

I'm trying to get micrometer metrics data to Splunk. Each metric endpoint gives the current value of a metric, so I would need Splunk to send a http request to my application periodically, or I can write the metric values to a log file periodically.

So how do I get my application to write the metric values to logs?

like image 861
George Avatar asked Jul 11 '26 20:07

George


1 Answers

If you are in spring boot 2.x and Micrometer is of version 1.1.0+ you can create a bean of periodic (1 minute) special logging registry see (https://github.com/micrometer-metrics/micrometer/issues/605)

@Bean
LoggingMeterRegistry loggingMeterRegistry() {
    return new LoggingMeterRegistry();
}

This is by far the easiest way to log everything via logging system.

Another alternative is creating a scheduled job that will run some method on a bean with injected metering registry that will iterate over all the metrics (with possibly filtering out the metrics that you won't need) and preparing the log of your format.

If you think about this, this is exactly what the metrics endpoint of spring boot actuator does, except returning the data via http instead of writing to log.

Here is an up-to-date implementation of the relevant endpoint from the spring boot actuator source

like image 191
Mark Bramnik Avatar answered Jul 13 '26 21:07

Mark Bramnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!