Home >Java >javaTutorial >How to solve the problem if SpringBoot actuator health check fails

How to solve the problem if SpringBoot actuator health check fails

王林
王林forward
2023-05-10 16:04:062811browse

SpringBoot actuator health check failed

Today I encountered a service that could be registered successfully, but the health check failed. I accessed the health check url through the browser, and Chrome's network kept showing pending, indicating that this request Submitted, but got no response and got stuck.

I originally thought that health check is to check whether the /health request under the service port can return normally, but it is not.

The so-called health check has many check items. Springboot inherits the AbstractHealthIndicator class, such as DataSourceHealthIndicator RedisHealthIndicator, etc. Springboot will automatically configure it. For example, if mysql's datasouce is used, the doHealthCheck of DataSourceHealthIndicator will be executed during the health check. (), if redis is used, doHealthCheck() of RedisHealthIndicator will be executed.

Solution:

First of all, you can determine whether these external data sources cannot be connected, causing the health check to fail. You can configure

management:
  health:
    db:
      enabled: false
    redis:
      enabled: false
    elasticsearch:
      enabled: false

to turn off health for all those used in the system. Check to see if the health check can pass normally. If you can troubleshoot the problem one by one by opening it one by one.

Finally, I found that the above pending situation is due to the incorrect url configuration of mysql, such as wrong port, or insufficient permissions of the mysql user. , DataSourceHealthIndicator's doHealthCheck() will connect to mysql but the connection is unsuccessful, and it will get stuck in connecting to mysql.

Configure the correct URL, enable permissions, and solve the problem.

Spring Boot health check related configuration and organization

1. What is Spring Boot health check and what is it used for?

Spring Boot provides health checks for multiple components, which is helpful for monitoring the running status of each component. However, sometimes developers will fail to start, report errors, etc., and need to configure it appropriately.

2. What checks are there in the Spring Boot project, and how to configure related checks:

2.1 First, the package introduced by the health check is

<dependency>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-actuator</artifactid>
</dependency>

2.2 Related health check related Indicator

  • CassandraHealthIndicator Check whether Cassandra is available

  • DiskSpaceHealthIndicator Check if there is insufficient disk space

  • DataSourceHealthIndicator Check whether the link can be obtained from DataSource

  • ElasticsearchHealthIndicator Check if the Elasticsearch cluster is available

  • JmsHealthIndicator Check if the JMS broker is available

  • MailHealthIndicator Check if the mail server is available

  • ##MongoHealthIndicator Check if the Mongo database is available

  • RabbitHealthIndicator Check Whether the Rabbit server is available

  • RedisHealthIndicator Check whether the Redis server is available

  • SolrHealthIndicator Check the Solr server Is it available?

You can see that there are checks for various external services. Please browse the official documentation for details. No more details here

2.3 How to close /Open health check

Explicitly set in application.properties

//如禁止es的健康检查如下,默认均为开启状态
management.health.elasticsearch.enabled=false

You can also use *Disable all

management.health.*.enabled=false

The above is the detailed content of How to solve the problem if SpringBoot actuator health check fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete