Solution of SpringBoot actuator Failure to Pass Health Check

  • 2021-11-02 01:15:22
  • OfStack

SpringBoot actuator health check failed

Today, I encountered a service that was successfully registered, but failed the health check. I accessed url of the health check through the browser, and network1 of chrome directly displayed pending, indicating that this request was submitted, but it could not be returned and was stuck.

It was thought that the health check was to check whether the request/health under the service port could return normally, but it was not.

The so-called health check has many check items. The classes inherited from AbstractHealthIndicator in springboot, such as DataSourceHealthIndicator RedisHealthIndicator, etc., springboot will be automatically configured, such as datasouce using mysql, doHealthCheck () of DataSourceHealthIndicator will be executed during health check, and doHealthCheck () of RedisHealthIndicator will be executed when redis is used.

Solution:

First, you can determine whether these external data sources cannot be connected, which leads to the failure of the health check. You can configure


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

Close all the health checks used in the system to see if the health checks can pass normally. If they can pass, open them one by one to eliminate problems one by one

Finally, it is found that the above pending situation is due to the incorrect configuration of url of mysql, such as wrong port, or insufficient permissions of mysql users, and doHealthCheck () of DataSourceHealthIndicator will connect to mysql without success, so it is stuck in connecting mysql.

Configure the correct url, open the authority and solve the problem.

Spring Boot Health Examination Related Configuration and Arrangement

1. What is the health examination of Spring Boot and what is the use?

Spring Boot provides a number of component health checks, which is conducive to monitoring the running status of each component. However, sometimes developers will start unsuccessfully and report errors, which requires reasonable configuration.

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

2.1 The first package to be introduced by the health check is


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

2.2 Indicator related to health examination

CassandraHealthIndicator Check whether Cassandra is available DiskSpaceHealthIndicator Check for insufficient disk space DataSourceHealthIndicator Check whether you can get links from DataSource ElasticsearchHealthIndicator Check whether Elasticsearch cluste is available JmsHealthIndicator Check whether JMS broker is available MailHealthIndicator Check whether mail server is available MongoHealthIndicator Check whether Mongo database is available RabbitHealthIndicator Check whether Rabbit server is available RedisHealthIndicator Check whether Redis server is available SolrHealthIndicator Check whether Solr server is available

As you can see, there are various external service inspections. Please browse the official documents for details, and there is no redundancy here

2.3 How to turn off/turn on health examination

Explicit settings in application. properties


// If prohibited es The health check of is as follows, and it is on by default 
management.health.elasticsearch.enabled=false

You can also use * ban all


management.health.*.enabled=false

Related articles: