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

编程知识 更新时间:2023-04-05 04:45:20

一、简介

        所有的应用开发完成之后,其最终目的都是为了上线运行,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的简单理解及应用

本文发布于:2023-04-05 04:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/15fbe76ecaf0f42a075ad39af6e669ae.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   boot   spring   actuator   starter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44842文章数
  • 14阅读数
  • 0评论数