Spring boot actuator MySQL database health check

Harshil picture Harshil · Sep 22, 2016 · Viewed 17.3k times · Source

I have designed one demo spring boot application CRUD operation with MySQL database. My application.properties file is as follow.

spring.boot.admin.url=http://localhost:8081
spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=admin
endpoints.health.sensitive=false
management.health.db.enabled=true
management.health.defaults.enabled=true
management.health.diskspace.enabled=true
spring.jpa.hibernate.ddl-auto=create-drop

POM.xml for the spring actuator is as follow.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>1.3.4</version>
</dependency>

When I try to hit the url "http://localhost:8080/health", I am getting {"status":"UP"} as response. I want to monitor my database (MySQL) with spring boot actuator. I want see my database status.

Can anyone please help ?

Answer

Stephane Nicoll picture Stephane Nicoll · Sep 22, 2016

I would check the documentation - Exposing the full details anonymously requires to disable the security of the actuator.

If that's not what you want, you can take full control of the security and write your own rules using Spring Security.