SpringBoot系列:五、SpringBoot使用Actuator

Actuator为springboot提供了运行状态监控的功能

通过集成它我们可以试试获取到应用程序的运行信息

首先,在pom.xml中引入起步依赖

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

然后在配置文件中添加配置节点,注意如果有多个配置文件需要添加在application.yml中
并且把actuator端口设置为其他端口,如果不设置的话会和程序共享一个端口,可以通过endpoint
来制定不通配置节点的特殊配置,例如我们这里开启了可以通过actuator来关闭应用程序
设置可以访问的节点  * 为全部
management:
  endpoints:
    web:
      exposure:
        include: "*"

  endpoint:
    health:
      show-details: always
    shutdown:
      enabled: true
  server:
    port: 9001

设置完成后启动程序,我们可以看到现在有两个端口正在被监听,一个是应用程序的端口一个是actuator的端口

 通过访问actuator的API可以获取目前应用程序的运行信息'

猜你喜欢

转载自www.cnblogs.com/Tassdar/p/11743519.html
今日推荐