gpt4 book ai didi

Spring Boot 执行器运行状况端点

转载 作者:行者123 更新时间:2023-12-04 16:45:35 25 4
gpt4 key购买 nike

我创建了一个像这样的 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 我看到:

{"status":"DOWN"}



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

最佳答案

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

management.security.enabled=false
endpoints.health.sensitive=false

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

可以在此处找到有关此的更多信息:
Production ready monitoring

关于Spring Boot 执行器运行状况端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36918868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com