添加Actuator功能
Spring Boot Actuator可以帮助程序员监控和管理SpringBoot应用,比如健康检查、内存使用情况统计、线程使用情况统计等。我们在SpringBoot项目中添加Actuator功能,即可使用Actuator监控
项目,用法如下:
在被监控的项目中添加Actuator起步依赖
org.springframework.boot spring-boot-starter-actuator在配置文件中开启所有监控端点
#开启所有监控端点
management.endpoints.web.exposure.include=*
测试:
访问项目:http://localhost:8080/actuator
图片
可以看到有很多json格式的字符串,这些都是该路径下的相关资源信息,并且通过URL可以调用actuator的功能:
图片
例如查询日志信息数据,访问localhost:8080/actuator/loggers
图片
SpringBoot指标监控 Spring Boot Admin
Actuator使用JSON格式展示了大量指标数据,不利于我们查看,我们可以使用可视化工具Spring Boot Admin查看actuator生成指标数据。Spring Boot Admin是一个独立的项目,我们需要创建并运
行该项目。
- 创建Spring Boot Admin服务端项目
创建SpringBoot项目,添加SpringMVC和Spring Boot Admin服务端起步依赖
org.springframework.boot
spring-boot-starter-web
de.codecentric
spring-boot-admin-start