【问题标题】:How to configure spring-micrometer tags如何配置 spring-micrometer 标签
【发布时间】:2021-01-02 18:41:40
【问题描述】:

这篇博文"Micrometer: Spring Boot 2's new application metrics collector",提到了"The importance of dimensionality"

但是,它没有包含如何在 Spring Boot 应用程序中设置关联标签的充分示例。

现在,我正在使用 Spring Boot 2 的 Micrometer 接口来提供 Prometheus 就绪的输出,而无需进行任何基于 Java 的配置。例如,设置“主机”标签是否需要我编写一些代码?那会是什么样子?

这是我的整个配置:

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      exposure:
        include: info,health,metrics,prometheus

【问题讨论】:

    标签: prometheus spring-boot-actuator spring-micrometer


    【解决方案1】:

    metricsCommonTags 有一个相关示例,改编如下:

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> {
            String hostname = "unknown";
            try { hostname = InetAddress.getLocalHost().getHostName(); }
            catch (Exception e) {}
            registry.config().commonTags("host", hostname);
        };
    }
    
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2020-07-14
    • 2018-10-26
    • 2020-05-02
    相关资源
    最近更新 更多