Spring Boot application monitoring, early detection

Services need to be monitored. In the SpringBoot project, which monitoring modules do you commonly use? actuator?admin?

When a Spring Boot application is running, the developer needs to monitor the Spring Boot application in real time to obtain the alarm requirements of the project. Spring Boot provides an actuator to help the developer obtain the runtime data of the application.

Adding endpoint configuration in Spring Boot is quite simple. Just add
spring-boot-starter-actuator to add related dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.3.1.RELEASE</version></dependency>

The commonly used endpoints are as follows:

Common endpoints are listed as follows, you can try them in detail one by one:

/info Application basic information/health health information/metrics running indicators/env environment variable information/loggers log related information/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 sensitive is closed.

For example: here is an example, whether to access the online interface

localhost:8080/actuator/health

The output of the browser at this time is:

Spring Boot application monitoring, early detection


Endpoint response cache

Some endpoints without parameters will be cached. Search for the official account: MarkerHub, follow the reply [vue] to get the introductory tutorial for the front and back ends!

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

The configuration above 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 to
localhost:8080/healthcheck

CORS

Perform cross-domain operations. You can quickly enable CORS support through the configuration file.

management:  endpoints:    web:      cors:        allowed-origins: http:        allowed-methods: *

In the upper part, processing is allowed, any request from http://localhost:8091, and the allowed method is arbitrary.

Add related dependencies.

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.2.3</version></dependency>

Add relevant annotations to 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@EnableAdminServerpublic class DemoApplication {    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

配置完成以后,输入链接,进行访问。

http:

Spring Boot application monitoring, early detection


再次添加 client 端

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.2.3</version></dependency>

书写配置文件

spring:  boot:    admin:      client:        url: http:

此时查看 admin

Spring Boot application monitoring, early detection


Spring Boot application monitoring, early detection


查看其健康度

Spring Boot application monitoring, early detection

[Disclaimer: The pictures and text information in this article are all reprinted from the Internet by Qianfeng Chongqing Java Training Editor. They are intended to be shared and read. The copyright belongs to the original author. If there is any infringement, please contact us to delete.

Guess you like

Origin blog.51cto.com/15128443/2663749