SpringBoot-Actuator

摘要

本文介绍如何使用Actuator。
Actuator提供了HTTP和JMX接口便于查看程序运行时的某些信息,如:容器中的bean信息、自动配置类匹配信息等。

本文内容来自SpringBoot参考手册
https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#production-ready

使用

  • 加入依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • 配置端点启用及暴露

SpringBoot2.0默认启用shutdown以外的端点,但并不暴露。

启用端点

management.endpoint.<id>.enabled

// 示例:启用shutdown端点
management.endpoint.shutdown.enable=true

暴露端点

// 通过jmx暴露或隐藏端点
management.endpoints.jmx.exposure.exclude 
management.endpoints.jmx.exposure.include 默认*
// 通过http暴露或隐藏端点
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.include 默认:info,health

// 示例:暴露beans端点
management.endpoints.web.exposure.include=beans
  • 启动程序查看控制台

可以看到输出的启用端点

2018-06-26 18:49:56.563 |-INFO  [restartedMain] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping [87] -| Mapped "{[/actuator/beans],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-06-26 18:49:56.565 |-INFO  [restartedMain] org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping [87] -| Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
  • 常用端点
端点请求方式说明
autoconfigGET自动配置类匹配信息
beansGET容器中所有的bean
configpropsGET@ConfigurationProperties配置类属性
dumpGET线程活动信息
envGET环境变量
healthGET健康指数
infoGET应用信息。可以自定义info.*定义info公开的数据
mappingsGET所有的URL路径
metricsGET系统的度量指数
shutdownPOST关闭应用。默认不开启
traceGET默认显示最近100个请求的跟踪信息
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值