SpringBoot随笔(一): spring-boot-starter-actuator 模块详解

一、简介
    spring-boot-starter-actuator模块是一个spring提供的监控模块。我们在开运行发过程中,需要实时和定时监控服务的各项状态和可用性。 Spring Boot的spring-boot-starter-actuator 模块(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看、相关功能统计等。
二、实现
    在maven的pom中引入:
<dependency>  
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-actuator</artifactId>  
</dependency>  
如果使用HTTP调用的方式,还需要这个依赖:
<dependency>  
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-web</artifactId>  
</dependency>  
三、配置
    1、health:配置
server:  
  port: 8082  // 服务端口
management:  
  port: 54001  // 指定监听端口,不指定则语server端口一直
  health:
    db:
      enabled: true
    mail:
      enabled: true
  security:
    enabled: false // 指定访问信息不进行用户验证
 访问: http://localhost:54001/health
status	"UP"
diskSpace	
    status	"UP"
    total	67548213248
    free	13226700800
    threshold	10485760
2、info:配置
info:
  app:
    name: "@project.name@" #从pom.xml中获取
    description: "@project.description@"
    version: "@project.version@"
    spring-boot-version: "@project.parent.version@"
访问: http://localhost:54001/info
{
    "app":{
        "name":"SpringBootStart Maven Webapp",
        "description":"Parent pom providing dependency and plugin management for applications built with Maven",
        "version":"1.0-SNAPSHOT",
        "spring-boot-version":"1.0-SNAPSHOT"
    }
}

四、自定义health指标
    实现 HealthIndicator接口,重写health方法,在此方法中输出相关信息即可。
{
    "status":"UP",
    "applicationStart":{
        "status":"UP",
        "hello":"world"
    },
    "diskSpace":{
        "status":"UP",
        "total":67548213248,
        "free":13226696704,
        "threshold":10485760}
}

五、其他端点介绍:
HTTP方法路径描述鉴权
GET/autoconfig查看自动配置的使用情况true
GET/configprops查看配置属性,包括默认配置true
GET/beans查看bean及其关系列表true
GET/dump打印线程栈true
GET/env查看所有环境变量true
GET/env/{name}查看具体变量值true
GET/health查看应用健康指标false
GET/info查看应用信息(需要自己在application.properties里头添加信息,比如info.contact.email=easonjim@163.com)false
GET/mappings查看所有url映射true
GET/metrics查看应用基本指标true
GET/metrics/{name}查看具体指标true
POST/shutdown关闭应用(要真正生效,得配置文件开启endpoints.shutdown.enabled: true)true
GET/trace查看基本追踪信息true

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值