Spring Boot and monitoring management

Posted by codygoodman on Sat, 08 Jan 2022 20:26:47 +0100

1, Monitoring management

By introducing Spring Boot starter actor, we can use the application monitoring and management functions in the quasi production environment provided by Spring Boot. We can operate through HTTP, JMX and SSH protocols to automatically obtain audit, health and index information.


1. Introduce spring boot starter actuator



2. Access the monitoring endpoint through http

Create the project, introduce the actor, and start the project

Project POM XML configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>





Start project:


After using the actor, many mappings will be automatically added, which are the request information for monitoring and management.


2, Monitoring and managing endpoints

Monitoring and managing endpoints:



By default, these accesses are protected and cannot be accessed directly. They can be accessed in application You can access it by setting the following properties in properties.




(1) health: monitor the health status of the application



(2) auditevents: audit events



(3) beans: information of all beans



(4) info: current application information


It can be found in application Configure info information in properties


You can also configure git information (you can refer to GitProperties class)

Create GIT Properties and configuration information;

git.commit.time=2022-01-08 12:12:56


(5) dump: thread status information in the application



(6) autoconfig: all autoconfig information





(7) heapdump: download the current memory snapshot


(8) trace: tracking information (latest http request)



(9) mappings: apply @ RequestMapping mapping mapping path, which Controller handles it



(10) metrics: applied indicators



(11) env: current environmental information



(12) loggers: log related information



(13) configprops: all configuration attributes



(14) shutdown: remotely close the current application (closed by default)

In application Enable this function in properties: (shutdown and POST submission can be performed, and this endpoint is closed by default)

#To close the application remotely, you need to send a post request


You can use Postman to send a POST} request to test:




3, Custom endpoint information

Custom endpoints are generally set through endpoints + endpoint name + attribute name

Modify Endpoints  id(endpoints.beans.id=mybeans)
Enable remote application shutdown function( endpoints.shutdown.enabled=true)
Close endpoint( endpoints.beans.enabled=false)


#Customized endpoint information. Only one id and path can take effect
#Disable endpoint information


Custom endpoint access root path:

#Custom endpoint access root path

The endpoint access path is http://localhost:8080/manage/beans .

This allows permission control in combination with Spring Security.


Access port of custom endpoint:

#Customize the access port of the endpoint. If it is - 1, it means that the endpoint access is closed


Close all endpoints and start endpoints on demand:

#Close all endpoints and start endpoints on demand



4, Customize HealthIndicator

1. health endpoint


By default, there is only the health status of components in the current application. Spring Boot also provides some good component health status by default.



2. Take Redis as an example

(1) add Redis scenario initiator



(2) Redis configuration information

#Configure the host address of redis (the configuration is wrong)


(3) start service



You can see that the Redis connection is abnormal.

SpringBoot provides the RedisHealthIndicator class to check the connection status of Redis.


3. Custom health status indicator

(1) steps to customize the health status indicator:

1,To write an indicator, you must implement HealthIndicator Interface
2,The name of the indicator  xxxHealthIndicator
3,Add to container


(2) custom health status indicator:

public class MyAppHealthIndicator implements HealthIndicator {

    public Health health() {
        //Custom check method

        //Health.up().build(); Represents application health
        Health build = Health.down().withDetail("msg", "Service exception").build();

        return build;



















Topics: Spring Boot