spring boot 2:执行器/健康端点需要更多时间

Har*_*hna 1 spring spring-boot-actuator

在我的服务 /actuator/health 端点之一中,需要更多时间(大约 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>
Run Code Online (Sandbox Code Playgroud)

使用的 Spring Boot 版本: 2.0.3.RELEASE

谢谢,哈里

Mar*_*nik 5

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

每个健康指标负责提供一个子系统的健康信息(此类子系统的示例有:磁盘、postgres、mongo 等),spring boot 自带一些预定义的健康指标。

这样当health端点被调用时,它会遍历这个列表并获取有关每个子系统的信息,然后构造答案。

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

如果您正在寻找 HTTP 入口点 - 调用时调用的代码http://<host-port>/health(可能因您的设置而异,但您明白了)`,可以在此处找到

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

例如,如果您有一个 elastricsearch 并想禁用它,请在以下内容中使用application.properties

management.health.elasticsearch.enabled = false
Run Code Online (Sandbox Code Playgroud)