SpringBoot中集成Actuator实现监控系统运行状态
场景
假设一个SpringBoot项目开发完毕部署到生产环境中,刚好出现线上问题,而运维希望能提供一些工具
帮助定位问题。
再假设应用部署成功,但是发现运行方式与预期不一致,通过查看日志,发现加载的Bean自动配置有误,
在生产环境中没法直接调试,用什么办法来解决问题。
SpringBoot提供了Actuator来支持这类需求。
若依前后端分离版手把手教你本地搭建环境并运行项目:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/108465662
在上面的基础上搭建起来项目。
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
1、添加Actuator依赖
org.springframework.boot spring-boot-starter-actuator
2、修改application.yml,修改端口号为9999(如果有必要,默认是8080)
#Actuator配置 management: server: #配置端口 port: 9999
3、启动项目访问
http://localhost:9999/actuator/
默认只开启这几个端点。
如果在若依框架中访问时提示无法访问,需要放开鉴权
7、同时还支持接口优雅关闭,默认是关闭的,需要配置开启
#Actuator配置 management: server: #配置端口 port: 9999 #开放endpoints endpoints: web: exposure: #开放所有 include: '*' #查看详细的健康信息 endpoint: health: show-details: always #开启接口优雅关闭 shutdown: enabled: true
然后使用POST请求方式访问接口
http://localhost:9999/actuator/shutdown