Relocate DiskSpace metrics to SystemMetricsAutoConfiguration

Closes gh-27688
pull/27698/head
Stephane Nicoll 3 years ago
parent 0d67a1af5c
commit b65cc4d62f

@ -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("."));
}
}

@ -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("."));
}
}

@ -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<AssertableApplicationContext> 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")));
}
}
}

@ -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")));
}
}
}

@ -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

Loading…
Cancel
Save