Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
cb4cdf4d
Commit
cb4cdf4d
authored
Mar 30, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'disk'
parents
96f390a5
ee3521b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
DiskSpaceHealthIndicator.java
...amework/boot/actuate/health/DiskSpaceHealthIndicator.java
+7
-3
DiskSpaceHealthIndicatorTests.java
...rk/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
+4
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicator.java
View file @
cb4cdf4d
...
...
@@ -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
());
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
View file @
cb4cdf4d
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment