Spring boot actuator health endpoint

蹲街弑〆低调 提交于 2019-12-23 01:54:15

问题


I have create a PostgreSQL health indicator like this:

@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    DataSource postgresDataSource;

    public DataSourceHealthIndicator dbHealthIndicator() {
        DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
        return indicator;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Health h = dbHealthIndicator().health();
        Status status = h.getStatus();
        if (status != null && "DOWN".equals(status.getCode())) {
            builder.down();
        } else {
            builder.up();
        }
    }
}

In my Application.java I am scanning this package for this component:

@ComponentScan({"com.bp.health"})

In my application.properties I have the following set:

endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true

when I hit {url}/health I see:

{"status":"DOWN"}

what do I need to do to get the custom health indicator to show?


回答1:


You need to be authenticated to see all the details. Alternatively you could set

management.security.enabled=false
endpoints.health.sensitive=false

to see full content unauthenticated

More information about that can be found here: Production ready monitoring




回答2:


Why would you want to do all that? That code doesn't even compile and Spring Boot does check your data sources by default already. If you only see the status, that's because you're not authenticated, check this table in the doc for more details.



来源:https://stackoverflow.com/questions/36918868/spring-boot-actuator-health-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!