Spring Boot Actuator 健康检查

Spring Boot Actuator 健康检查

介绍

Actuator 是Spring Boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、健康检查、相关功能统计等

实现

  • 加依赖

    	<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-actuator</artifactId>
    	</dependency>
    
  • 在application.properties配置文件中指定端口
    如果不指定,其使用端口和服务端口一致

    #服务端口
    server.port=9000
    #web项目访问的上下文路径
    server.servlet.context-path=/springboot-web
    
    #actuator端口
    management.server.port=9100
    #actuator监控的接口上下文路径
    management.server.servlet.context-path=/springboot-actuator
    #默认只开启了health和info,设置为*,则包含所有的web监控入口端点都可以访问(上面两个如果不配置则默认使用web项目的配置)
    management.endpoints.web.exposure.include=*
    

    例如:
    http://localhost:9100/springboot-actuator/actuator/health
    http://localhost:9100/springboot-actuator/actuator/info

功能及注意

  • actuator提供的主要功能

  • HTTP方法路径描述是否为wen入口
    GET/configprops查看配置属性,包括默认配置true
    GET/beans查看bean及其关系列表true
    GET/env查看所有环境变量true
    GET/health查看应用健康指标false
    GET/info查看应用信息false
    GET/mappings查看所有url映射true
    GET/metrics查看应用基本指标true
    GET/metrics/{name}查看具体指标true
    JMX/shutdown关闭应用true
  • 注意

    • /info需要自己在application.properties文件中添加信息:
      info.contact.name=张三
      info.contact.age=20
      info.contact.phone=123456789012
      
    • /shutdown需要在配置文件中开启才能生效
      	management.endpoint.shutdown.enabled=true
      
      JMX是Java管理拓展,需要用jdk的一个应用去操作
      jdk安装路径------->bin------>jcosole.exe双击
      在这里插入图片描述
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值