代码已添加至Github,有兴趣的同学可以下载来看看:https://github.com/ylw-github/SpringBoot-Monitor-Demo
1. Actuator监控应用Actuator 是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管、审计、收集应用的运行情况,特别对于微服务管理十分有意义。
但是Actuator也有缺点:没有可视化界面。
下面我们来看看如何使用Actuator:
步骤一:添加maven依赖
org.springframework.boot
spring-boot-starter-parent
2.0.0.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
2.在/src/main/resources/目录下新增application.yml
###通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;
management:
endpoints:
web:
exposure:
include: "*"
spring:
profiles:
active: prod
3.运行程序,通过actuator/+端点名就可以获取相应的信息 例如访问http://localhost:8080/actuator/env,可以看到陈列了所有的环境变量:
从上面的讲解,我们知道可以通过actuator/+端点名就可以获取相应的信息。
路径作用/actuator/beans显示应用程序中所有Spring bean的完整列表。/actuator/configprops显示所有配置信息。/actuator/env陈列所有的环境变量。/actuator/mappings显示所有@RequestMapping的url整理列表。/actuator/health显示应用程序运行状况信息 up表示成功 down失败/actuator/info查看应用信息比如现在想查看应用的信息,可以在application.yml新增info,如下: 运行http://localhost:8080/actuator/info: