当前位置:   article > 正文

Spring Actuator介绍及使用_actuator spring

actuator spring

Spring Actuator

介绍

我们的微服务在云上部署以后都需要对其进行监控、追踪、审计、控制等。SpringBoot就抽取了Actuator场景,使得我们每个微服务快速引用即可获得生产级别的应用监控、审计等功能。

各种端点可以提供项目的运行情况,可以通过配置文件设置include对外开放的端点。

        <!--添加actuator依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
# 开启所有端点
management:
  endpoints:
    web:
      exposure:
        include: '*'
        #如果添加下面一条,则表示除了health节点外都开启
        #exclude: health
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
# 开启指定
management:
  endpoints:
    web:
      exposure:
        include: health,info
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

可以自定义Actuator

可以为info端口设置自定义的信息(InfoContributor接口的contribute方法,传递到builder中即可),或者通过@Endpoint、@ReadOperation 等实现自定义端口。

Actuator就是通过为类添加@Endpoint注解来实现的。

常用的端点:

localhost:8080/actuator/info(显示数据由应用开发者自行设置)

localhost:8080/actuator/health(应用的健康状态)

localhost:8080/actuator/metrics(应用的各种度量指标,包括内存、处理器、垃圾收集和HTTP请求)

localhost:8080/actuator/metrics/http.server.request(包括http请求的各种数据,比如请求总数、总耗时、处理单个请求最大耗时)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/334102
推荐阅读
相关标签
  

闽ICP备14008679号