一、Actuator简介
1、监控组件作用
在生产环境中,需要实时或定期监控服务的可用性。Spring Boot的actuator(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看、相关功能统计等。
2、监控分类
Actuator 提供Rest接口,展示监控信息。
接口分为三大类:
- 应用配置类
获取应用程序中加载的应用配置、环境变量、自动化配置报告等与SpringBoot应用相关的配置类信息。
- 度量指标类
获取应用程序运行过程中用于监控的度量指标,比如:内存信息、线程池信息、HTTP请求统计等。
- 操作控制类
提供了对应用的关闭等操作类功能。
二、与SpringBoot2整合
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:
# 通过指定接口关闭 Spr