Spring Boot application monitoring

Keywords: Java Spring

When a Spring Boot application is running, developers need to monitor the Spring Boot application in real time to get the alarm demand of the project. Spring Boot provides the actor to help developers get the data of the application at runtime.

Endpoint Configuration

Adding endpoint configuration to Spring Boot is quite simple.
Just add spring boot starter actor
Add related dependencies

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

Common endpoints are as follows:

Common endpoints are listed as follows, which can be tried in detail one by one:

/info application basic information
/health information
/metrics operation index
/env environment variable information
/loggers log related
/dump thread related information
/Trace request call trace

Most of these endpoints are enabled by default. If you want to enable an endpoint, you need to configure the following in the configuration file.

endpoints:
  metrics:
    sensitive: false

At this time, sensitivity is turned off.

for instance:
Here's an example of how to access an online interface

localhost:8080/actuator/health

The output of the browser is:

Endpoint response cache

Some endpoints without parameters will be cached.

management:
  endpoint:
    auditevents:
      cache:
        time-to-live: 100s

The above configuration shows that the cache reaches 100s

Path mapping

The access path can be mapped.

management:
  endpoints:
    web:
      base-path: /
      path-mapping: 
        health: healthcheck

At this time, the access path is changed from the original localhost:8080/actuator/health Change to localhost:8080/healthcheck

CORS

Perform cross domain operations.
You can quickly open CORS support through configuration files.

management:
  endpoints:
    web:
      cors:
        allowed-origins: http://localhost:8091
        allowed-methods: *

In the top, allow processing from http://localhost : any request of 8091, any method allowed.

Visualization of configuration information

Add related dependencies.

        <!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-server -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.2.3</version>
        </dependency>

Add related comments on the startup class:

package com.example.demo;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

After the configuration is complete, enter the link for access.

http://localhost:8080/index.html

Add client side again

<!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-client -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.2.3</version>
</dependency>

Write profile

spring:
  boot:
    admin:
      client:
        url: http://localhost:8080

View admin at this time


Check their health

The official account of WeChat:

Posted by damic on Tue, 16 Jun 2020 01:18:49 -0700