Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure spring-micrometer tags

This blog post "Micrometer: Spring Boot 2's new application metrics collector", mentions "The importance of dimensionality".

However, it doesn't include a sufficient example of how the associated tags can be set within a Spring Boot application.

Right now, I'm using Spring Boot 2's Micrometer interface to provide Prometheus-ready output without having done any Java-based configuration. Does setting, for example, a "host" tag require me to write some code? What would that look like?

Here's my entire configuration:

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      exposure:
        include: info,health,metrics,prometheus
like image 481
Brent Bradburn Avatar asked Oct 19 '25 15:10

Brent Bradburn


1 Answers

There is a relevant example at metricsCommonTags, adapted below:

@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
    return registry -> {
        String hostname = "unknown";
        try { hostname = InetAddress.getLocalHost().getHostName(); }
        catch (Exception e) {}
        registry.config().commonTags("host", hostname);
    };
}
like image 71
Brent Bradburn Avatar answered Oct 24 '25 16:10

Brent Bradburn



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!