Polish "Add support for configuring the path of disk space metrics"

See gh-27660
pull/28064/head
Stephane Nicoll 3 years ago
parent 08251b26d0
commit b626adf1ee

@ -18,7 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics;
import java.io.File;
import java.time.Duration;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -89,14 +90,14 @@ public class MetricsProperties {
return this.data;
}
public Distribution getDistribution() {
return this.distribution;
}
public System getSystem() {
return this.system;
}
public Distribution getDistribution() {
return this.distribution;
}
public static class Web {
private final Client client = new Client();
@ -267,6 +268,33 @@ public class MetricsProperties {
}
public static class System {
private final Diskspace diskspace = new Diskspace();
public Diskspace getDiskspace() {
return this.diskspace;
}
public static class Diskspace {
/**
* Comma-separated list of paths to report disk metrics for.
*/
private List<File> paths = new ArrayList<>(Collections.singletonList(new File(".")));
public List<File> getPaths() {
return this.paths;
}
public void setPaths(List<File> paths) {
this.paths = paths;
}
}
}
public static class Distribution {
/**
@ -352,31 +380,4 @@ public class MetricsProperties {
}
public static class System {
private final Diskspace diskspace = new Diskspace();
public Diskspace getDiskspace() {
return this.diskspace;
}
public static class Diskspace {
/**
* Comma-separated list of paths to report disk metrics for.
*/
private List<File> paths = Arrays.asList(new File("."));
public List<File> getPaths() {
return this.paths;
}
public void setPaths(List<File> paths) {
this.paths = paths;
}
}
}
}

@ -16,6 +16,9 @@
package org.springframework.boot.actuate.autoconfigure.metrics;
import java.io.File;
import java.util.List;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
@ -28,6 +31,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -42,14 +46,9 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
@EnableConfigurationProperties(MetricsProperties.class)
public class SystemMetricsAutoConfiguration {
private final MetricsProperties properties;
public SystemMetricsAutoConfiguration(MetricsProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public UptimeMetrics uptimeMetrics() {
@ -70,8 +69,9 @@ public class SystemMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public DiskSpaceMetricsBinder diskSpaceMetrics() {
return new DiskSpaceMetricsBinder(this.properties.getSystem().getDiskspace().getPaths(), Tags.empty());
public DiskSpaceMetricsBinder diskSpaceMetrics(MetricsProperties properties) {
List<File> paths = properties.getSystem().getDiskspace().getPaths();
return new DiskSpaceMetricsBinder(paths, Tags.empty());
}
}

@ -326,6 +326,13 @@
"reason": "Instead, filter 'process.uptime' and 'process.start.time' metrics."
}
},
{
"name": "management.metrics.system.diskspace.paths",
"type": "java.util.List<java.io.File>",
"defaultValue": [
"."
]
},
{
"name": "management.metrics.export.appoptics.num-threads",
"type": "java.lang.Integer",

@ -22,7 +22,7 @@ import java.util.List;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics;
import org.springframework.util.Assert;

Loading…
Cancel
Save