【问题标题】:Spring boot actuator health endpointSpring Boot 执行器健康端点
【发布时间】:2016-04-28 15:17:29
【问题描述】:

我已经创建了一个这样的 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"}

我需要做什么才能显示自定义运行状况指示器?

【问题讨论】:

    标签: spring spring-boot spring-boot-actuator actuator


    【解决方案1】:

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

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

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

    更多信息可以在这里找到: Production ready monitoring

    【讨论】:

      【解决方案2】:

      你为什么要这么做?该代码甚至没有编译,并且默认情况下 Spring Boot 确实会检查您的数据源。如果您只看到状态,那是因为您没有通过身份验证,请查看此表 in the doc 了解更多详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-10
        • 2015-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-24
        • 1970-01-01
        • 2015-12-14
        相关资源
        最近更新 更多