SpringBoot configures Actuator component to realize system monitoring
- 2021-09-24 22:10:03
- OfStack
1. Core depends on Jar package 2. Yml configuration file 3. Detailed explanation of monitoring interface
1. Info interface
2. Health interface
3. Beans interface
4. Conditions interface
5. HeapDump interface
6. Mappings interface
7. ThreadDump interface
8. ShutDown interface
4. Source code address
1. Introduction to Actuator
Monitoring classification
Actuator provides Rest interface to display monitoring information. Interfaces fall into three broad categories: Application configuration class: Obtain configuration class information related to SpringBoot application, such as application configuration, environment variables and automatic configuration report loaded in application program. Metrics class: Obtain metrics used for monitoring during application running, such as memory information, thread pool information, HTTP request statistics, etc. Operation control class: It provides operation class functions such as closing applications.
2. Integration with SpringBoot 2.0
1. Core depends on Jar package
<!-- Monitor dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. Yml configuration file
# Port
server:
port: 8016
spring:
application:
# Application name
name: node16-boot-actuator
management:
endpoints:
web:
exposure:
# Open all monitoring points
include: "*"
# Custom Monitoring Path monitor
# Default value: http://localhost:8016/actuator/*
# After configuration: http://localhost:8016/monitor/*
base-path: /monitor
endpoint:
health:
show-details: always
shutdown:
# Close by specifying the interface SpringBoot
enabled: true
# You can customize ports
# server:
# port: 8089
# Describe the basic information of the project
info:
app:
name: node16-boot-actuator
port: 8016
version: 1.0.0
author: cicada
3. Detailed explanation of monitoring interface
1. Info interface
Basic project information configured in the Yml file
Path: http://localhost:8016/monitor/info
Output:
{
"app": {
"name": "node16-boot-actuator",
"port": 8016,
"version": "1.0.0",
"author": "cicada"
}
}
2. Health interface
health is mainly used to check the running status of applications
Path: http://localhost:8016/monitor/health
Output:
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 185496236032,
"free": 140944084992,
"threshold": 10485760
}
}
}
}
3. Beans interface
It shows the type of bean, single case and multiple cases, alias, full path of class, dependence on Jar and so on.
Path: http://localhost:8016/monitor/beans
Output:
{
"contexts": {
"node16-boot-actuator": {
"beans": {
"endpointCachingOperationInvokerAdvisor": {
"aliases": [],
"scope": "singleton",
"type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor",
"resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]",
"dependencies": ["environment"]
}
}
}
}
4. Conditions interface
See under what conditions the configuration works, or why automatic configuration does not work.
Path: http://localhost:8016/monitor/conditions
Output:
{
"contexts": {
"node16-boot-actuator": {
"positiveMatches": {
"AuditAutoConfiguration#auditListener": [{
"condition": "OnBeanCondition",
"message": "@ConditionalOnMissingBean"
}],
}
}
5. HeapDump interface
Automatically generates the heap dump file HeapDump for Jvm, which can be opened to view a memory snapshot using the monitoring tool VisualVM.
Path: http://localhost:8016/monitor/heapdump
6. Mappings interface
Describe the mapping relationship between URI path and controller
Path: http://localhost:8016/monitor/mappings
Output:
{
"contexts": {
"node16-boot-actuator": {
"mappings": {
"dispatcherServlets": {
"dispatcherServlet": [ {
"handler": "Actuator web endpoint 'auditevents'",
"predicate": "{GET /monitor/auditevents || application/json]}",
"details": {
"handlerMethod": {
"className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat
"name": "handle",
"descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;"
},
"requestMappingConditions": {
"consumes": [],
"headers": [],
"methods": ["GET"],
"params": [],
"patterns": ["/monitor/auditevents"],
"produces": [{
"mediaType": "application/vnd.spring-boot.actuator.v2+json",
"negated": false
}, {
"mediaType": "application/json",
"negated": false
}]
}
}
}
}
}
}
7. ThreadDump interface
Shows thread name, thread ID, whether to wait for lock, thread state, thread lock and other related information.
Path: http://localhost:8016/monitor/threaddump
Output:
{
"threads": [{
"threadName": "DestroyJavaVM",
"threadId": 34,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 0,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "RUNNABLE",
"stackTrace": [],
"lockedMonitors": [],
"lockedSynchronizers": [],
"lockInfo": null
}
]
}
8. ShutDown interface
Elegantly close the Spring Boot application, and only support POST requests by default.
Path: http://localhost:8016/monitor/shutdown
4. Source code address
GitHub Address: Cicada 1 Smile
https://github.com/cicadasmile/spring-boot-base
Code Cloud Address: Cicada 1 Smile
https://gitee.com/cicadasmile/spring-boot-base
The above is SpringBoot configuration Actuator components, the implementation of system monitoring details, more information about SpringBoot configuration Actuator please pay attention to other related articles on this site!