一、简介

        所有的应用开发完成之后,其最终目的都是为了上线运行,SpringBoot 应用也不例外,而在应用运行的漫长生命周期内,为了保障其可以持续稳定的服务,我们通常需要对其进行监控,从而可以了解应用的运行状态,并根据情况决定是否需要对其运行状态进行调整。

        顺应需求,SpringBoot 框架提供了 spring-boot-starter-actuator 自动配置模块用于支持 SpringBoot 应用的监控。Actuator 这个词即使翻译过来也不是很容易理解(比如翻译成“制动器;传动装置;执行机构”等)。

二、应用

1.新建一个springboot项目,往pom文件中导入actuator对应的starter。因为需要浏览器端访问,也要导入web对应的starter

<!--健康监控-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--SpringMVC-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2.application.yml的配置如下。需要注意的是,虽然下面的配置已经开启了所有的监控点,但是spring-boot 2.6以后的info默认值是false,所有需手动开启

server:
  port: 8082  # 服务端口

#health:http://localhost:54001/actuator/health
#info:http://localhost:54001/actuator/info
info:
  application:
    name: "@project.name@" #从pom.xml中获取
    description: "@project.description@"
    version: "@project.version@"
management:
  server:
    port: 54001  # 指定监听端口,不指定则与server端口一直
  endpoints:  # 启动所有监控点
    web:
      exposure:
        include: '*'
  info: # spring-boot 2.6以后info默认值为false.需手动开启
    env:
      enabled: true

3.其他端点介绍

 

更多推荐

spring-boot-starter-actuator的简单理解及应用