From e270a21b8275bc5d11c3a788238eba20151995cd Mon Sep 17 00:00:00 2001 From: izeye Date: Tue, 24 Mar 2015 13:57:26 +0900 Subject: [PATCH 1/2] Add total space to disk health information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, disk health information only included the amount of free space and the configured threshold. This commit adds the disk’s total space. See gh-2705 --- .../boot/actuate/health/DiskSpaceHealthIndicator.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicator.java index 293c44b617..e8c0f5ab4a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicator.java @@ -16,6 +16,8 @@ package org.springframework.boot.actuate.health; +import java.io.File; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +47,8 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator { @Override protected void doHealthCheck(Health.Builder builder) throws Exception { - long diskFreeInBytes = this.properties.getPath().getFreeSpace(); + File path = this.properties.getPath(); + long diskFreeInBytes = path.getFreeSpace(); if (diskFreeInBytes >= this.properties.getThreshold()) { builder.up(); } @@ -55,7 +58,8 @@ public class DiskSpaceHealthIndicator extends AbstractHealthIndicator { this.properties.getThreshold())); builder.down(); } - builder.withDetail("free", diskFreeInBytes).withDetail("threshold", - this.properties.getThreshold()); + builder.withDetail("total", path.getTotalSpace()) + .withDetail("free", diskFreeInBytes) + .withDetail("threshold", this.properties.getThreshold()); } } From ee3521b6a268ef11420277656ee9eafd70e0c0cb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 30 Mar 2015 13:40:16 +0100 Subject: [PATCH 2/2] Test that total space is included in disk health information Closes gh-2705 --- .../boot/actuate/health/DiskSpaceHealthIndicatorTests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java index 1846bc7f59..f651307efc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java @@ -58,19 +58,23 @@ public class DiskSpaceHealthIndicatorTests { @Test public void diskSpaceIsUp() throws Exception { given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10); + given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); Health health = this.healthIndicator.health(); assertEquals(Status.UP, health.getStatus()); assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); assertEquals(THRESHOLD_BYTES + 10, health.getDetails().get("free")); + assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); } @Test public void diskSpaceIsDown() throws Exception { given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10); + given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); Health health = this.healthIndicator.health(); assertEquals(Status.DOWN, health.getStatus()); assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); assertEquals(THRESHOLD_BYTES - 10, health.getDetails().get("free")); + assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); } private DiskSpaceHealthIndicatorProperties createProperties(File path, long threshold) {