SpringBoot actuator(监控)
SpringBoot actuator(监控)
1、Actuator 是什么?做什么用的?
是什么:它是SpringBoot 提供对,应用系统的监控和自查的集成功能
能做什么:查看应用配置信息、环境信息、对应用的控制和操作。
2、Actuator 监控分类
原生端点
应用配置 类 、度量指标类 、操作控制类
自定义端点
3、Actuator 的两个依赖
3.1
starter-web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
3.2
starter-actuator
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.3.7.RELEASE</version> </dependency>
4、初步的介绍与与使用
4.1 在应用的application.yml 配置开启端点,默认情况是只开启两个端点一个是info 一个health
可以配置开启全部端点
management: # endpoint: # shutdown: # enabled: true #最特殊的监控端点,它是操作控制端点 一般不会开启这个端点 endpoints: web: exposure: include: "*" #打开所有的监控端点
配置完毕之后,actuator默认是开启的。访问 前缀 + actuator 就可以访问
例如:这里的前缀是
/Springboot-caicai
那么访问地址是:
/Springboot-caicai/actuator
spring: # profiles: # active: prod application: name: caicai-spring-study server: port: 8080 servlet: context-path: /Springboot-caicai caicai: Springboot: name: speed-test_spring_boot version: 1.0.2
两个端点:
1、actuator/health
2、actuator/info
默认情况info信息是空的,需要我们自己定义
示例:
在application.yml 自定义info 信息
spring: # profiles: # active: prod application: name: caicai-spring-study server: port: 8080 servlet: context-path: /Springboot-caicai caicai: Springboot: name: speed-test_spring_boot version: 1.0.2 management: # endpoint: # shutdown: # enabled: true #最特殊的监控端点,它是操作控制端点 一般不会开启这个端点 endpoints: web: exposure: include: "*" #打开所有的监控端点 #/Springboot-caicai/actuator 前缀 info: app: name: caicai-spring-study groupid: com.caicai.springboot.study version: 1.0.0
5、应用配置类常用监控
- 自己配置info信息:/actuator/info
- 应用中的bean信息:/actuator/beans
- 应用中URL路径信息:/actuator/mappings
6、度量指标类常用监控
- 检查应用的运行状态:/actuator/health
- 当前线程活动快照:/actuator/threaddump
7、操作控制类常用监控
关闭应用(Post)方式:/actuator/shutdown
curl -X POST "http://localhost:8080/actuator/shutdown" 直接关闭应用,这是相当危险 的,一般情况都是关闭的。
开开心心,上班!
快快乐乐,游玩!
及时行乐!