0
votes

I'm trying to implement actuator in spring boot 2.0.2.RELEASE.

Dependency in pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <scope>compile</scope>
    </dependency>

application.properties

management.server.port = 8082
management.endpoint.health.enabled=true

Custom healthcheck class

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class HealthCheck implements HealthIndicator {
@Override
public Health health() {
    int errorCode = check(); // perform some specific health check
    if (errorCode != 0) {
        return Health.down()
          .withDetail("Error Code", errorCode).build();
    }
    return Health.up().build();
}

public int check() {
    // Our logic to check health
    return 0;
}
}

When I hit http://localhost:8082/actuator/health in the brower, I'm getting {"status":"UP"}

I expected to get

{
status: "UP",
diskSpace: {
status: "UP",
total: 240721588224,
free: 42078715904,
threshold: 10485760
}
}
2

2 Answers

1
votes

Add the following in application.yml

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      enabled: true
      show-details: always
    info:
      enabled: true
    metrics:
      enabled: true
    threaddump:
      enabled: true
0
votes

With the below config, we can enable details for all the components.

management:
    endpoint: 
        health:
          show-details: always 

To get the memory details alone, you can speicy the component.

 curl -i localhost:8082/actuator/health/diskSpace
    {
  "status": "UP",
  "details": {
    "total": 131574468608,
    "free": 47974543360,
    "threshold": 10485760
  }
}