Spring Boot 执行器运行状况端点 [英] Spring boot actuator health endpoint
问题描述
我创建了一个像这样的 PostgreSQL 健康指标:
@Component公共类 PostgresHealthIndicator 扩展 AbstractHealthIndicator {@自动连线数据源 postgresDataSource;公共数据源健康指标 dbHealthIndicator() {DataSourceHealthIndicator 指标 = new DataSourceHealthIndicator(postgresDataSource);返回指标;}@覆盖protected void doHealthCheck(Health.Builder builder) 抛出异常 {健康 h = dbHealthIndicator().health();状态 status = h.getStatus();if (status != null && "DOWN".equals(status.getCode())) {builder.down();}其他{builder.up();}}}
在我的 Application.java 中,我正在为这个组件扫描这个包:
@ComponentScan({"com.bp.health"})
在我的 application.properties 中,我有以下设置:
endpoints.health.sensitive=falseendpoints.health.id=healthendpoints.health.enabled=true
当我点击 {url}/health 我看到:
<块引用>{"status":"DOWN"}
我需要做什么才能显示自定义运行状况指示器?
您需要通过身份验证才能查看所有详细信息.或者你可以设置
management.security.enabled=falseendpoints.health.sensitive=false
查看未经身份验证的完整内容
可以在此处找到有关此的更多信息:生产就绪监控>
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?
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
这篇关于Spring Boot 执行器运行状况端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!