SpringBoot整合Actuator进行健康监控

  一、Actuator介绍

  SpringBoot自带监控功能Actuator,通过 restful api 请求来监管、审计、收集应用的运行情况,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等。

  二、引入Actuator

  在pom.xml中引入spring-boot-starter-actuator标签。

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>    

  在浏览器中打开http://localhost:8080/actuator/,可以看到所有支持的链接。

   有关Actuator的接口API如:/info,/health,/beans,/env,/mappings,/trace,/dump,/shutdown等,可以访问spring官网进行查看:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints

  三、配置文件

  在application.properties文件中重新配置Actuator端口为8081,此时访问Actuator流需要用8081端口访问,关于Actuator是大量配置项,可以在spring中查看。

   很明显,Springboot中整合了Actuator后可以通过API访问并获取程序的运行状况,此时我们自己可以根据API自己开发可视化页面,更好的监测系统的运行。另外,spring给我提供了对应的监控平台,

我们只需要在项目中引入SpringAdmin依赖,就可以搭建一个完整的监控平台,下一篇,胜金就写一下搭建SpringAdmin的过程。

原文地址:https://www.cnblogs.com/JohanChan/p/13546375.html