Skip to content

Commit b626adf

Browse files
committed
Polish "Add support for configuring the path of disk space metrics"
See gh-27660
1 parent 08251b2 commit b626adf

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

+33-32
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import java.io.File;
2020
import java.time.Duration;
21-
import java.util.Arrays;
21+
import java.util.ArrayList;
22+
import java.util.Collections;
2223
import java.util.LinkedHashMap;
2324
import java.util.List;
2425
import java.util.Map;
@@ -89,14 +90,14 @@ public Data getData() {
8990
return this.data;
9091
}
9192

92-
public Distribution getDistribution() {
93-
return this.distribution;
94-
}
95-
9693
public System getSystem() {
9794
return this.system;
9895
}
9996

97+
public Distribution getDistribution() {
98+
return this.distribution;
99+
}
100+
100101
public static class Web {
101102

102103
private final Client client = new Client();
@@ -267,6 +268,33 @@ public AutoTimeProperties getAutotime() {
267268

268269
}
269270

271+
public static class System {
272+
273+
private final Diskspace diskspace = new Diskspace();
274+
275+
public Diskspace getDiskspace() {
276+
return this.diskspace;
277+
}
278+
279+
public static class Diskspace {
280+
281+
/**
282+
* Comma-separated list of paths to report disk metrics for.
283+
*/
284+
private List<File> paths = new ArrayList<>(Collections.singletonList(new File(".")));
285+
286+
public List<File> getPaths() {
287+
return this.paths;
288+
}
289+
290+
public void setPaths(List<File> paths) {
291+
this.paths = paths;
292+
}
293+
294+
}
295+
296+
}
297+
270298
public static class Distribution {
271299

272300
/**
@@ -352,31 +380,4 @@ public Map<String, Integer> getBufferLength() {
352380

353381
}
354382

355-
public static class System {
356-
357-
private final Diskspace diskspace = new Diskspace();
358-
359-
public Diskspace getDiskspace() {
360-
return this.diskspace;
361-
}
362-
363-
public static class Diskspace {
364-
365-
/**
366-
* Comma-separated list of paths to report disk metrics for.
367-
*/
368-
private List<File> paths = Arrays.asList(new File("."));
369-
370-
public List<File> getPaths() {
371-
return this.paths;
372-
}
373-
374-
public void setPaths(List<File> paths) {
375-
this.paths = paths;
376-
}
377-
378-
}
379-
380-
}
381-
382383
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/SystemMetricsAutoConfiguration.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics;
1818

19+
import java.io.File;
20+
import java.util.List;
21+
1922
import io.micrometer.core.instrument.MeterRegistry;
2023
import io.micrometer.core.instrument.Tags;
2124
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
@@ -28,6 +31,7 @@
2831
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2932
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3033
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
34+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3135
import org.springframework.context.annotation.Bean;
3236
import org.springframework.context.annotation.Configuration;
3337

@@ -42,14 +46,9 @@
4246
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
4347
@ConditionalOnClass(MeterRegistry.class)
4448
@ConditionalOnBean(MeterRegistry.class)
49+
@EnableConfigurationProperties(MetricsProperties.class)
4550
public class SystemMetricsAutoConfiguration {
4651

47-
private final MetricsProperties properties;
48-
49-
public SystemMetricsAutoConfiguration(MetricsProperties properties) {
50-
this.properties = properties;
51-
}
52-
5352
@Bean
5453
@ConditionalOnMissingBean
5554
public UptimeMetrics uptimeMetrics() {
@@ -70,8 +69,9 @@ public FileDescriptorMetrics fileDescriptorMetrics() {
7069

7170
@Bean
7271
@ConditionalOnMissingBean
73-
public DiskSpaceMetricsBinder diskSpaceMetrics() {
74-
return new DiskSpaceMetricsBinder(this.properties.getSystem().getDiskspace().getPaths(), Tags.empty());
72+
public DiskSpaceMetricsBinder diskSpaceMetrics(MetricsProperties properties) {
73+
List<File> paths = properties.getSystem().getDiskspace().getPaths();
74+
return new DiskSpaceMetricsBinder(paths, Tags.empty());
7575
}
7676

7777
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+7
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@
326326
"reason": "Instead, filter 'process.uptime' and 'process.start.time' metrics."
327327
}
328328
},
329+
{
330+
"name": "management.metrics.system.diskspace.paths",
331+
"type": "java.util.List<java.io.File>",
332+
"defaultValue": [
333+
"."
334+
]
335+
},
329336
{
330337
"name": "management.metrics.export.appoptics.num-threads",
331338
"type": "java.lang.Integer",

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/system/DiskSpaceMetricsBinder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.micrometer.core.instrument.MeterRegistry;
2323
import io.micrometer.core.instrument.Tag;
2424
import io.micrometer.core.instrument.binder.MeterBinder;
25-
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
25+
import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics;
2626

2727
import org.springframework.util.Assert;
2828

0 commit comments

Comments
 (0)