Spring Boot application monitoring in practice

Profile


Overview

I talked about the visual monitoring of Docker containers before , that is, monitoring the operation of containers, including a series of information such as CPU usage, memory usage, network status, and disk space. When using SpringBoot as the instantiation technology selection of the microservice unit, an inevitable problem we have to face is how to monitor the running status data of the application in real time, such as: health, running indicators, log information, thread status, etc. . This article explores this issue a bit and records the test process.


Getting Started: Actuator Plugin

The Actuator plugin is a service provided natively by SpringBoot, which can be used to output many endpoint . Let's fight it!

  • Add dependencies to pom.xml:
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

After starting the Spring Boot application, you can get some state information of the application by simply entering the endpoint information in the browser.

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

  • /info Basic application information
  • /health health information
  • /metrics Running metrics
  • /env environment variable information
  • /loggers log related
  • /dump thread related information
  • /trace Request call trace

Of course, only the /healthand /infoendpoints can be used at this time, and the others cannot be accessed due to permission issues. If you want to access the specified endpoint, you can add relevant configuration items in the yml configuration. For example, /metricsthe endpoint needs to be configured:

endpoints:
  metrics:
    sensitive: false

At this point the browser accesses the /metrics endpoint to get information such as the following:

{
	"mem": 71529,
	"mem.free": 15073,
	"processors": 4,
	"instance.uptime": 6376,
	"uptime": 9447,
	"systemload.average": -1.0,
	"heap.committed": 48024,
	"heap.init": 16384,
	"heap.used": 32950,
	"heap": 506816,
	"nonheap.committed": 23840,
	"nonheap.init": 160,
	"nonheap.used": 23506,
	"nonheap": 0,
	"threads.peak": 25,
	"threads.daemon": 23,
	"threads.totalStarted": 28,
	"threads": 25,
	"classes": 6129,
	"classes.loaded": 6129,
	"classes.unloaded": 0,
	"gc.copy.count": 74,
	"gc.copy.time": 173,
	"gc.marksweepcompact.count": 3,
	"gc.marksweepcompact.time": 88,
	"httpsessions.max": -1,
	"httpsessions.active": 0
}

Of course, you can also open all endpoint permissions, just configure the following:

endpoints:
  sensitive: false

Since the monitoring capabilities provided by the Actuator plug-in are limited and the UI is relatively simple, a more mature tool is needed


Spring Boot Admin Monitoring System

SBA is a further evolution based on Actuator, which is a monitoring tool for UI beautification and encapsulation of Actuator interfaces. Let's experiment.

  • First, create a Spring Boot Admin Server project as a server

Add the following dependencies to pom.xml:

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

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-server-ui</artifactId>
	<version>1.5.7</version>
</dependency>

Then enable Spring Boot Admin by annotating the main class of the application

@EnableAdminServer
@SpringBootApplication
public class SpringbtAdminServerApplication {

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

Start the program, and the browser opens to localhost:8081view Spring Boot Admin main page:

Spring Boot Admin main page

At this time, the Application column is empty, waiting for the application to be monitored to join

  • Create a Spring Boot application to monitor

Add the following dependencies to pom.xml

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

Then add the following configuration to the yml configuration to register the application to the Admin server:

spring:
  boot:
    admin:
      url: http://localhost:8081
      client:
        name: AdminTest

As soon as the Client application starts, the Admin service immediately pushes a message, telling you that AdminTest is online:

App launch push message

At this point, go to the Admin main interface and find that the Client application has indeed been registered:

Client application has been registered

  • View Details

Detail information

  • View Metrics

Metrics information

  • View Environment

Environment Information

  • View JMX

JMX information

  • View Threads

Threads information

  • View Trace and Details

Trace information

Click JOURNAL at the top, and you will see the event changes of the monitored application:

Application event change information

It can be clearly seen from the figure that the application jumps from the state of REGISTRATION → UNKNOWN → UP .

This will try all the endpoint information provided by the Actuator plugin in SBA.


references


postscript

More original articles by the author: In Open Source China

Some of the author's other articles on containerized applications:



CodeSheep

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325251867&siteId=291194637