我已经创建了一个像这样的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"}
我需要做什么才能显示自定义健康指标?