spring-boot-starter-actuator主要用于Springboot工程项目的健康指标数据的监控,接上面第2部分的内容,我们接入指标监控模块。
1.pom.xml文件增加相关依赖
<!-- 应用监控检测 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.application.properties配置文件增加如下配置
#健康检查,从pom中获取工程名,描述,版本
info.application.name="@project.name@"
info.application.description="@project.description@"
info.application.version="@project.version@"
#指定访问端口
management.server.port=52001
#启动所有监控点
management.endpoints.web.exposure.include=*
#info默认是关闭的,需要打开
management.info.env.enabled=true
#/actuator/xxx路徑,都变成/manage/xxx
#management.endpoints.web.base-path=/manage
配置好以上配置,启动springboot应用。通过浏览器可以访问http://localhost:52001/actuator/health,http://localhost:52001/actuator/info。得到如下结果
涉及到的常用监控内容反馈有这些
GET /actuator 查看有哪些 Actuator endpoint 是开放的,和对应的路径
GET /actuator/beans 查看容器中的 bean
GET /actuator/health 查看当前应用指标情况,实现HealthIndicator可以自定义指标项
GET /actuator/loggers 查看当前应用日志级别情况,可以运行时调整
GET /actuator/info 应用信息展示
GET /actuator/threaddump 当前应用线程栈dump,同 jstack
应用程序的范例在这里下载 链接: https://pan.baidu.com/s/1i1z3FbWVobXxyyiiE_oTYQ 提取码: 2yc3