我创建了一个 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 我看到:
{“状态”:“下降”}
我需要做什么才能显示自定义运行状况指示器?