Spring Boot 2 : actuator/health endpoint is taking more time

标签 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>

使用的Spring boot版本: 2.0.3.RELEASE

谢谢, 哈里

最佳答案

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

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

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

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

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

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

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

management.health.elasticsearch.enabled = false

关于 Spring Boot 2 : actuator/health endpoint is taking more time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63665192/

相关文章:

Spring Boot - DevTools - RestController 在重建项目时并不总是映射

java - 我们请求长时间运行,UI 在响应准备好时超时

java - 如何在 Spring Boot 中将自定义 AbstractHealthIndicator 设置为不敏感,以便显示 for/health 端点?

java - Spring Boot REST API 的指标收集

java - Spring 单例范围

Java Spring : Web Service REST producing double backslash at JSON

java - MyBatis: boolean 参数:MyBatis 正在使用 Getter

java - Swagger2 > 记录一个 SpringBoot MvcEndpoint

java - 由于 Solr 依赖性,Spring Actuator 状态下降

java - 一个应用程序是否可以使用 Spring 框架的任何功能来检查另一个应用程序的运行状况?