From b65cc4d62f4a818e36be8b99b98eba01a28f6f2a Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 16 Aug 2021 14:53:42 +0200 Subject: [PATCH] Relocate DiskSpace metrics to SystemMetricsAutoConfiguration Closes gh-27688 --- .../metrics/JvmMetricsAutoConfiguration.java | 9 ------- .../SystemMetricsAutoConfiguration.java | 9 +++++++ .../JvmMetricsAutoConfigurationTests.java | 23 +--------------- .../SystemMetricsAutoConfigurationTests.java | 26 +++++++++++++++++++ .../src/docs/asciidoc/actuator/metrics.adoc | 6 ++--- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java index 99ed01b22e..bbe9cd6c47 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java @@ -16,11 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics; -import java.io.File; - import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; -import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; @@ -69,10 +66,4 @@ public class JvmMetricsAutoConfiguration { return new ClassLoaderMetrics(); } - @Bean - @ConditionalOnMissingBean - public DiskSpaceMetrics diskSpaceMetrics() { - return new DiskSpaceMetrics(new File(".")); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfiguration.java index 58f8a357c5..412a3e1a5c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfiguration.java @@ -16,7 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics; +import java.io.File; + import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics; import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; import io.micrometer.core.instrument.binder.system.ProcessorMetrics; import io.micrometer.core.instrument.binder.system.UptimeMetrics; @@ -59,4 +62,10 @@ public class SystemMetricsAutoConfiguration { return new FileDescriptorMetrics(); } + @Bean + @ConditionalOnMissingBean + public DiskSpaceMetrics diskSpaceMetrics() { + return new DiskSpaceMetrics(new File(".")); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java index d0e5d16f3b..f9e2106e32 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java @@ -16,10 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics; -import java.io.File; - import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; -import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; @@ -40,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson * @author Stephane Nicoll - * @author Chris Bono */ class JvmMetricsAutoConfigurationTests { @@ -76,16 +72,9 @@ class JvmMetricsAutoConfigurationTests { assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customClassLoaderMetrics"))); } - @Test - void allowsCustomDiskSpaceMetricsToBeUsed() { - this.contextRunner.withUserConfiguration(CustomDiskSpaceMetricsConfiguration.class) - .run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customDiskSpaceMetrics"))); - } - private ContextConsumer assertMetricsBeans() { return (context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class) - .hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class) - .hasSingleBean(DiskSpaceMetrics.class); + .hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class); } @Configuration(proxyBeanMethods = false) @@ -128,14 +117,4 @@ class JvmMetricsAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - static class CustomDiskSpaceMetricsConfiguration { - - @Bean - DiskSpaceMetrics customDiskSpaceMetrics() { - return new DiskSpaceMetrics(new File(System.getProperty("user.dir"))); - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfigurationTests.java index 880a58aa5e..687b967708 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfigurationTests.java @@ -16,6 +16,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics; +import java.io.File; + +import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics; import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; import io.micrometer.core.instrument.binder.system.ProcessorMetrics; import io.micrometer.core.instrument.binder.system.UptimeMetrics; @@ -34,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson * @author Stephane Nicoll + * @author Chris Bono */ class SystemMetricsAutoConfigurationTests { @@ -75,6 +79,18 @@ class SystemMetricsAutoConfigurationTests { .hasBean("customFileDescriptorMetrics")); } + @Test + void autoConfiguresDiskSpaceMetrics() { + this.contextRunner.run((context) -> assertThat(context).hasSingleBean(DiskSpaceMetrics.class)); + } + + @Test + void allowsCustomDiskSpaceMetricsToBeUsed() { + this.contextRunner.withUserConfiguration(CustomDiskSpaceMetricsConfiguration.class) + .run((context) -> assertThat(context).hasSingleBean(DiskSpaceMetrics.class) + .hasBean("customDiskSpaceMetrics")); + } + @Configuration(proxyBeanMethods = false) static class CustomUptimeMetricsConfiguration { @@ -105,4 +121,14 @@ class SystemMetricsAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomDiskSpaceMetricsConfiguration { + + @Bean + DiskSpaceMetrics customDiskSpaceMetrics() { + return new DiskSpaceMetrics(new File(System.getProperty("user.dir"))); + } + + } + } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc index bac1fbd914..a0a1e6e6cc 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc @@ -624,7 +624,7 @@ In most situations, the out-of-the-box defaults will provide sensible metrics th [[actuator.metrics.supported.jvm]] ==== JVM Metrics Auto-configuration will enable JVM Metrics using core Micrometer classes. -JVM metrics are published under the `jvm.` and `disk.` meter names. +JVM metrics are published under the `jvm.` meter name. The following JVM metrics are provided: @@ -632,20 +632,20 @@ The following JVM metrics are provided: * Statistics related to garbage collection * Threads utilization * The Number of classes loaded/unloaded -* Disk space available [[actuator.metrics.supported.system]] ==== System Metrics Auto-configuration will enable system metrics using core Micrometer classes. -System metrics are published under the `system.` and `process.` meter names. +System metrics are published under the `system.`, `process.`, and `disk.` meter names. The following system metrics are provided: * CPU metrics * File descriptor metrics * Uptime metrics (both the amount of time the application has been running as well as a fixed gauge of the absolute start time) +* Disk space available