Supriya C S
Supriya C S

Reputation: 133

customise spring boot actuator health status

When I access the /health endpoint from my Spring Boot application it is returning a status of UP:

{
  "status": "UP"
}

But I want to customize my status like this:

{
  "status": "success"
}

How can I customize the status?

Upvotes: 3

Views: 9137

Answers (1)

Sully
Sully

Reputation: 14943

Create a new health builder status and return it.

Status

@JsonProperty("status")
public String getCode() {
    return this.code;
}

if implementing HealthIndicator

@Component
public class HealthChecker implements HealthIndicator {

    @Override
    public Health health() {
        // Do checks ..
        // if no issues
        return Health.status("success").build();
    }   
}

if extending AbstractHealthIndicator

@Component
public class HealthIndicator extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        builder.status("success").build();
    }
}

Severity Order

to make this work, you have to update the order of status severity by replacing UP with success or moving it before UP

application.properties

management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, success

or

management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, success, UP

Upvotes: 16

Related Questions