Springboot actuator health check failed
Today, I encountered a service that registered successfully but failed the health check. When I access the URL of the health check through the browser, the chrome network always displays pending, indicating that the request was submitted but could not be returned, so it was stuck.
Originally, I thought that health check was to check whether the / health request under the service port can return normally. In fact, it is not.
The so-called health check has many check items. Springboot inherits the class of abstracthealthindicator, such as datasourcehealthindicator redishealthindicator. Springboot will be automatically configured. For example, datasource using MySQL will execute dohealthcheck() of datasourcehealthindicator during health check. If redis is used, dohealthcheck() of redishealthindicator will be executed.
Solution:
First, you can determine whether these external data sources cannot be connected, which leads to the failure of health inspection. You can configure them
management:
health:
db:
enabled: false
redis:
enabled: false
elasticsearch:
enabled: false
Turn off the health check for everything used in the system to see if the health check can pass normally. If it can be opened one by one, eliminate the problems one by one
Finally, it is found that the above pending situation is due to the incorrect URL configuration of MySQL, such as port error, or insufficient permissions of MySQL users. Dohealthcheck() of datasourcehealthindicator will connect to MySQL. If the connection is unsuccessful, it is stuck in connecting to MySQL.
Configure the correct URL, open the permission and solve the problem.
Spring boot health check related configuration and sorting
1. What is the health check of spring boot? What’s the use?
Spring boot provides a number of component health checks, which is conducive to monitoring the operation of each component. However, sometimes developers will fail to start and report errors, which need to be configured reasonably.
2. What checks are there in spring boot project and how to configure related checks:
2.1 first, the package introduced by health examination is
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-actuator</artifactid>
</dependency>
2.2 relevant indicators of health examination
CassandraHealthIndicator
Check whether Cassandra is availableDiskSpaceHealthIndicator
Check for insufficient disk spaceDataSourceHealthIndicator
Check whether the link can be obtained from the datasourceElasticsearchHealthIndicator
Check whether elasticsearch cluste is availableJmsHealthIndicator
Check if JMS broker is availableMailHealthIndicator
Check if the mail server is availableMongoHealthIndicator
Check whether Mongo database is availableRabbitHealthIndicator
Check whether the rabbit server is availableRedisHealthIndicator
Check whether redis server is availableSolrHealthIndicator
Check if Solr server is available
It can be seen that there are various external service inspections. Please browse the official documents for details. There is no more detail here
2.3 how to turn health check off / on
application. Explicit setting in properties
//If the prohibited es health checks are as follows, they are on by default
management.health.elasticsearch.enabled=false
You can also use * prohibit all
management.health.*.enabled=false
The above is my personal experience. I hope I can give you a reference, and I hope you can support developpaer.