我已经创建了一个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(); } } }
在我的Application.java中,我正在扫描此软件包中的该组件:
@ComponentScan({"com.bp.health"})
在我的application.properties中,我进行了以下设置:
endpoints.health.sensitive=false endpoints.health.id=health endpoints.health.enabled=true
当我点击{url} / health时,我看到:
{“状态”:“ DOWN”}
我需要怎么做才能显示自定义健康指标?
您需要进行身份验证才能查看所有详细信息。或者,您可以设置
management.security.enabled=false endpoints.health.sensitive=false
查看未认证的完整内容
有关此的更多信息,请参见: 生产就绪监控