Spring Boot 2:执行器/运行状况端点花费更多时间

问题描述

在我的服务/执行器/运行状况端点之一中,它花费了更多时间(约9秒)。我正在使用以下依赖项,如何调试呢?

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

使用的春季启动版本: 2.0.3.RELEASE

谢谢, 哈里

解决方法

基本上health端点是通过以下方式实现的:它包含实现接口HealthIndicator的所有Spring bean的列表。

每个运行状况指示器负责提供有关一个子系统的运行状况信息(此类子系统的示例包括:磁盘,postgres,mongo等),spring boot带有一些预定义的HealthIndicators。

因此,在调用health端点时,它将遍历此列表并获取有关每个子系统的信息,然后构造答案。

因此,您可以在相关的健康指标中放置一个断点(假设您知道检查了哪些子系统),然后看看会发生什么。

如果您正在寻找HTTP入口点-调用http://<host-port>/health时被调用的代码(可能会因设置而异,但您可以理解),可以找到{{3} }

我想到的另一种方法是禁用“可疑”健康检查,并通过消除进行缓慢检查。

例如,如果您进行了弹性搜索并希望将其禁用,请在application.properties中使用:

management.health.elasticsearch.enabled = false
,

在 Mark 的回答之上,在 application.properties / application.yml 中设置此属性

management.endpoint.health.show-details=always

将有助于确定哪些组件构成了健康检查, 因为 GET /actuator/health 会产生更多细节