SpringBoot-使用Actuator监控

前言

Actuator 是 Spring Boot 提供的对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息,例如自动化配置信息、创建的Spring beans以及一些环境属性等。

pom.xml文件

引入web和actuator依赖,web依赖是必须引入的,否则不能启动。

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

配置文件

info:
  app:
    name: spring-boot-actuator-test
    version: 1.0.0
    test: test

management:
  endpoints:
    web:
      #Actuator 默认所有的监控点路径都在/actuator/*,当然如果有需要这个路径也支持定制。
      base-path: /monitor
      #Actuator 默认只开放了两个端点 /actuator/health 和 /actuator/info
      exposure:
        #打开所有的监控点
        include: '*'
        #屏蔽env,beans监控点
        exclude: env,beans

  endpoint:
    health:
      #详细显示health信息
      show-details: always
    #启用接口关闭 Spring Boot (post请求)
    shutdown:
      enabled: true

  health:
    #可以在配置文件中关闭特定的健康检查指标,比如关闭 redis 的健康检查(或者MongoDB)
    redis:
      enabled: false

测试

  1. 访问 http://localhost:8080/monitor 。默认路径为/actuator/*,配置中已经修改为base-path: /monitor。image.png
  2. 访问http://localhost:8080/monitor/info 。 返回配置文件中info的内容。
    image.png
  3. 访问http://localhost:8080/monitor/health 。显示 health 的细节。
    image.png
  4. 访问http://localhost:8080/monitor/shutdown (post请求)。关闭 Spring Boot。
    image.png

参考内容

使用 Spring Boot Actuator 监控应用

Spring Boot Actuator 使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值