Spring boot actuator端点启用和暴露

1.启用端点

默认情况下,除了shutdown端点是关闭的,其它的都是启用的。配置一个端点的启用,使用management.endpoint..enabled属性,下面的例子是启用shutdown端点:

management.endpoint.shutdown.enabled=true

如果你个人更喜欢自定义端点的启用和关闭,可以使用如下属性

management.endpoints.enabled-by-default=false

关闭所有端点启用情况,个人可以单独的通过设置enabled属性启用端点;下面的示例示关闭所有的端点,并且请用info端点:

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

禁用端点端点会被从ApplicationContext上下文中删除,如果只是想从技术上更改端点的暴露,可以使用include和exclude属性替代。

2.暴露端点

由于端点可能包含敏感信息,应该仔细的考虑什么时候暴露它们,下面的表格展示了内置端点的暴露情况:

IDJMXWeb
auditeventsYesNo
beansYesNo
cachesYesNo
conditionsYesNo
configpropsYesNo
envYesNo
flywayYesNo
healthYesYes
heapdumpN/ANo
httptraceYesNo
infoYesYes
integrationgraphYesNo
jolokiaN/ANo
logfileN/ANo
loggersYesNo
liquibaseYesNo
metricsYesNo
mappingsYesNo
prometheusN/ANo
scheduledtasksYesNo
sessionsYesNo
shutdownYesNo
threaddumpYesNo

去改变将那个端点暴露出来,可以使用特定的技术include和exclude属性:

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

include属性列出暴露端点的IDS,exclude属性列出不应该暴露端点的IDS;exclude属性的优先级高于include属性,include和exclude属性都可以使用端点列表来配置IDS.

例如:停止公开所有在JMX上公开的端点,只公开info和health两个端点,使用如下属性:

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

* 可以用来表示所有的端点,例如,通过HTTP公开所有的端点,除了env和beans端点,使用如下的属性:

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

* 在YAML中有特殊的含义,所以如果想使用include或者exclude包含所有的端点时要加上双引号,如下示例:

management:
  endpoints:
    web:
      exposure:
        include: "*"

如果你要暴露你的端点为public,我们强烈的建议你使用加密。
如果暴露端点的时候想实现在自己的策略,你可以注册一个EndpointFilter bean。

参考:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值