SpringBoot配置Actuator组件,实现系统监控
作者:知了一笑 时间:2021-10-27 07:46:48
目录
一、Actuator简介
二、与SpringBoot2.0整合
1、核心依赖Jar包
2、Yml配置文件
三、监控接口详解
1、Info接口
2、Health接口
3、Beans接口
4、Conditions接口
5、HeapDump接口
6、Mappings接口
7、ThreadDump接口
8、ShutDown接口
四、源代码地址
一、Actuator简介
监控分类
Actuator 提供Rest接口,展示监控信息。
接口分为三大类:
应用配置类:获取应用程序中加载的应用配置、环境变量、自动化配置报告等与SpringBoot应用相关的配置类信息。
度量指标类:获取应用程序运行过程中用于监控的度量指标,比如:内存信息、线程池信息、HTTP请求统计等。
操作控制类:提供了对应用的关闭等操作类功能。
二、与SpringBoot2.0整合
1、核心依赖Jar包
<!-- 监控依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、Yml配置文件
# 端口
server:
port: 8016
spring:
application:
# 应用名称
name: node16-boot-actuator
management:
endpoints:
web:
exposure:
# 打开所有的监控点
include: "*"
# 自定义监控路径 monitor
# 默认值:http://localhost:8016/actuator/*
# 配置后:http://localhost:8016/monitor/*
base-path: /monitor
endpoint:
health:
show-details: always
shutdown:
# 通过指定接口关闭 SpringBoot
enabled: true
# 可以自定义端口
# server:
# port: 8089
# 描述项目基础信息
info:
app:
name: node16-boot-actuator
port: 8016
version: 1.0.0
author: cicada
三、监控接口详解
1、Info接口
Yml文件中配置的项目基础信息
路径:http://localhost:8016/monitor/info
输出:
{
"app": {
"name": "node16-boot-actuator",
"port": 8016,
"version": "1.0.0",
"author": "cicada"
}
}
2、Health接口
health 主要用来检查应用的运行状态
路径:http://localhost:8016/monitor/health
输出:
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 185496236032,
"free": 140944084992,
"threshold": 10485760
}
}
}
}
3、Beans接口
展示了 bean 的类型、单例多例、别名、类的全路径、依赖Jar等内容。
路径:http://localhost:8016/monitor/beans
输出:
{
"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接口
查看配置在什么条件下有效,或者自动配置为什么无效。
路径:http://localhost:8016/monitor/conditions
输出:
{
"contexts": {
"node16-boot-actuator": {
"positiveMatches": {
"AuditAutoConfiguration#auditListener": [{
"condition": "OnBeanCondition",
"message": "@ConditionalOnMissingBean"
}],
}
}
5、HeapDump接口
自动生成Jvm的堆转储文件HeapDump,可以使用监控工具 VisualVM 打开此文件查看内存快照。
路径:http://localhost:8016/monitor/heapdump
6、Mappings接口
描述 URI 路径和控制器的映射关系
路径:http://localhost:8016/monitor/mappings
输出:
{
"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接口
展示线程名、线程ID、是否等待锁、线程的状态、线程锁等相关信息。
路径:http://localhost:8016/monitor/threaddump
输出:
{
"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接口
优雅关闭 Spring Boot 应用,默认只支持POST请求。
路径:http://localhost:8016/monitor/shutdown
四、源代码地址
GitHub地址:知了一笑
https://github.com/cicadasmile/spring-boot-base
码云地址:知了一笑
https://gitee.com/cicadasmile/spring-boot-base
来源:https://mp.weixin.qq.com/s/wFGN87uD9pPlny_1oYRzQQ
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#使用TextBox作数据输入方法
C#学习笔记整理_深入剖析构造函数、析构函数
Java聊天室之解决连接超时问题
![](https://img.aspxhome.com/file/2023/5/69115_0s.png)
c# 实现控件(ocx)中的事件详解
![](https://img.aspxhome.com/file/2023/5/88305_0s.jpg)
Android AutoCompleteTextView控件基本用法示例
MyBatis动态SQL标签用法实例详解
HttpClient 在Java项目中的使用详解
Java Web实现session过期后自动跳转到登陆页功能【基于过滤器】
在编码时如何使用\\r与\\n,两者的区别
如何修改FeginCilent定义的服务名到指定服务
C# Winform实现自定义漂亮的通知效果
Struts2通过自定义标签实现权限控制的方法
java多线程加锁以及Condition类的使用实例解析
![](https://img.aspxhome.com/file/2023/3/57713_0s.png)
3分钟纯 Java 注解搭个管理系统的示例代码
![](https://img.aspxhome.com/file/2023/7/65777_0s.jpg)
Spring Boot实现异步请求(Servlet 3.0)
Java CompletableFuture实现多线程异步编排
![](https://img.aspxhome.com/file/2023/0/57710_0s.jpg)
C语言实现学生信息管理系统
![](https://img.aspxhome.com/file/2023/8/129548_0s.jpg)
Android点击EditText文本框之外任何地方隐藏键盘的解决办法
基于idea Maven中的redis配置使用详解
unity通过Mesh网格绘制图形(三角形、正方体、圆柱)
![](https://img.aspxhome.com/file/2023/0/102270_0s.png)