如何在 Spring Boot 2.x 中配置 LoggingMeterRegistry 步骤持续时间?

gol*_*dio 5 spring-boot micrometer spring-micrometer

我正在尝试配置 LoggingMeterRegistry 来记录我的 Spring Boot 2.1.6 应用程序的指标。我希望每小时记录一次指标。

在我的 application.yml 中,我进行了以下配置

management:
  metrics:
    export:
      logging:
        enabled: true
        step: 60m
Run Code Online (Sandbox Code Playgroud)

但在日志中我看到每分钟都会记录一次指标。我也尝试过属性键的其他变体,例如

management.metrics.export.logging:
  enabled: true
  step: 60m
Run Code Online (Sandbox Code Playgroud)

我还尝试了持续时间字符串的各种格式1h,例如,PT60M但没有成功。指标每隔 1 分钟记录一次。

我正在查看此处StepDurationConverterTest和此处StepDurationConverter 的代码,它将步骤持续时间字符串转换为 Duration 对象,看起来两种格式60m1h应该有效。

为什么我似乎无法更改记录间隔有什么想法吗?

Dav*_*ary 2

我认为这里的问题是没有 org.springframework.boot.actuate.autoconfigure.metrics.export.logging 像其他包一样的包MeterRegistry(例如org.springframework.boot.actuate.autoconfigure.metrics.export.jmx)。

即 Spring Boot 中的属性没有自动配置。这可能是因为被LoggingMeterRegistry标记为@Incubating

您需要手动将其配置LoggingMeterRegistry为 bean 并创建您自己的 bean @ConfigurationProperties LoggingPropertiesLoggingPropertiesConfigAdapter才能使其正常工作。或者只是硬编码您想要的步骤周期。