Spring Boot 2.0 之 Actuator

转载自:https://blog.csdn.net/alinyua/article/details/80009435

 spring boot 2.0 Actuator与之前版本有较大不同。上网查看了一圈,上篇文章比较靠谱。(英文差,不看官方文档,专走野路子)

下面是简捷说明:

1.开启Actuator:

按以下配置为Maven项目添加执行器:

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

2. 端点(Endpoints)

执行器端点(endpoints)可用于监控应用及与应用进行交互,Spring Boot包含很多内置的端点,你也可以添加自己的。例如,health端点提供了应用的基本健康信息。 
每个端点都可以启用或禁用。这控制着端点是否被创建,并且它的bean是否存在于应用程序上下文中。要远程访问端点,还必须通过JMX或HTTP进行暴露,大部分应用选择HTTP,端点的ID映射到一个带/actuator前缀的URL。例如,health端点默认映射到/actuator/health

注意: 
Spring Boot 2.0的端点基础路径由“/”调整到”/actuator”下,如:/info调整为/actuator/info 
可以通过以下配置改为和旧版本一致:

management.endpoints.web.base-path=/

 

2.1 启用端点

默认情况下,除shutdown以外的所有端点均已启用。要配置单个端点的启用,请使用management.endpoint.<id>.enabled属性。以下示例启用shutdown端点:

management.endpoint.shutdown.enabled=true

另外可以通过management.endpoints.enabled-by-default来修改全局端口默认配置,以下示例启用info端点并禁用所有其他端点:

management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true

2.2 暴露端点

由于端点可能包含敏感信息,因此应仔细考虑何时公开它们。下表显示了内置端点的默认曝光:

IDJMXWeb
auditeventsYesNo
beansYesNo
conditionsYesNo
configpropsYesNo
envYesNo
flywayYesNo
healthYesYes
heapdumpN/ANo
httptraceYesNo
infoYesYes
jolokiaYesNo
logfileYesNo
loggersYesNo
liquibaseYesNo
metricsYesNo
mappingsYesNo
prometheusN/ANo
scheduledtasksYesNo
sessionsYesNo
shutdownYesNo
threaddumpYesNo

要更改公开哪些端点,请使用以下技术特定的includeexclude属性:

PropertyDefault
management.endpoints.jmx.exposure.exclude*
management.endpoints.jmx.exposure.include*
management.endpoints.web.exposure.exclude*
management.endpoints.web.exposure.includeinfo, health

include属性列出了公开的端点的ID,exclude属性列出了不应该公开的端点的ID 
exclude属性优先于include属性。包含和排除属性都可以使用端点ID列表进行配置。

注意 
这里的优先级是指同一端点ID,同时出现在include属性表和exclude属性表里,exclude属性优先于include属性,即此端点没有暴露

例如,要停止通过JMX公开所有端点并仅公开healthinfo端点,请使用以下属性:

management.endpoints.jmx.exposure.include=health,info

*可以用来选择所有端点。例如,要通过HTTP公开除env和beans端点之外的所有内容,请使用以下属性:

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值