Overview
The core of Spring Boot monitoring is spring-boot-starter-actuator dependency. After adding dependencies, Spring Boot will configure some general monitoring by default, such as jvm monitoring, class loading, health monitoring, etc.
We have talked about visual monitoring of Docker containers before, that is, monitoring the operation of the container, including CPU usage, memory usage, network status, disk space and other information. When selecting SpringBoot as the instantiation technology of microservice units, one of the inevitable problems we have to face is how to monitor the application's health status data in real time, such as: health, operation indicators, log information, thread status, etc. This article explores the problem and records the experimental process.
Getting started with: Actuator plugin
Actuator plug-in is a service natively provided by SpringBoot. It can be used to output many endpoint information in the application by exposing endpoint routes. Take a practical battle!
Add dependencies in 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 status information of the application by simply entering the endpoint information in the browser.
Common endpoints are listed as follows, you can try them in detail:
Of course, only /health and /info endpoints can be used at this time, and other endpoints 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, if you need to configure the /metrics endpoint:
endpoints: metrics: sensitive: false
At this time, the browser accesses the /metrics endpoint and can get information such as shown below:
{ "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.unloaded": 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 enable all endpoint permissions, just configure them as follows:
endpoints: sensitive: false
Since the monitoring capabilities provided by the Actuator plug-in are limited after all, and the UI is relatively simple, it requires a more mature tool.
Spring Boot Admin Monitoring System
SBA has been further evolved based on Actuator, which is a monitoring tool for UI beautification and packaging for Actuator interface. Let's experiment.
First, create a Spring Boot Admin Server project as the 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 adding annotations on the application main class
@EnableAdminServer@SpringBootApplicationpublic class SpringbtAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringbtAdminServerApplication.class, args); }}Start the program and open localhost:8081 in the browser to view the Spring Boot Admin main page:
Spring Boot Admin Home Page
At this time, the Application column is empty, waiting for the application to be monitored to join
Create a Spring Boot app 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 in the yml configuration and register the application to the Admin server:
spring: boot: admin: url: http://localhost:8081 client: name: AdminTest
As soon as the Client application was started, the Admin service immediately pushed a message, telling you that AdminTest is online:
App to push messages online
At this time, go to the main Admin interface to check and find that the Client application has indeed been registered:
Client application has been registered
View Detail
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 on the top JOURNAL and you will see the event changes of the monitored application:
Application event change information
It can be clearly seen in the figure that the application jumps from the status of REGISTRATION → UNKNOWN → UP.
This will try all the endpoint information provided by the Actuator plug-in in the SBA.
References
http://codecentric.github.io/spring-boot-admin/1.5.7/
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support to Wulin.com.