弹簧启动执行器健康终点

Thy*_*els 1 spring spring-boot spring-boot-actuator actuator

我已经创建了一个像这样的PostgreSQL运行状况指示器:

@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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的Application.java中,我正在为此组件扫描此包:

@ComponentScan({"com.bp.health"})
Run Code Online (Sandbox Code Playgroud)

在我的application.properties中,我有以下设置:

endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true
Run Code Online (Sandbox Code Playgroud)

当我点击{url}/health时,我看到:

{ "地位": "DOWN"}

我需要做什么才能显示自定义健康指标?

Jan*_*nar 8

您需要通过身份验证才能查看所有详细信息.或者你可以设置

management.security.enabled=false
endpoints.health.sensitive=false
Run Code Online (Sandbox Code Playgroud)

查看未经身份验证的完整内容

有关这方面的更多信息,请访问: 生产就绪监控