简体   繁体   中英

Do not show diskspace and db for Spring Boot Actuator /health endpoint

I am running Spring Boot v1.5.2.RELEASE.

When I do curl localhost:8080/health i get:

{
    "status": "UP",
    "test": {
        "status": "UNKNOWN",
        "hello": "test123"
    },
    "diskSpace": {
        "status": "UP",
        "total": 999234207744,
        "free": 806942392320,
        "threshold": 10485760
    },
    "db": {
        "status": "UP",
        "database": "MySQL",
        "hello": 1
    }
}

Here is my code below for TestHealthIndicator.java:

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.stereotype.Component;

@Component
public class TestHealthIndicator extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        builder.withDetail("hello", "test123");
    }
}

I also have this in my pom.xml :

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

Question : How do I get /health to return something like below without the db and diskspace information?

{
    "status": "UP",
    "test": {
        "status": "UNKNOWN",
        "hello": "test123"
    }
}

根据文档,您可以使用以下属性禁用所有自定义HealthIndicator Bean:

management.health.defaults.enabled=false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM