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.暴露端點

由於端點可能包含敏感信息,應該仔細的考慮什麼時候暴露它們,下面的表格展示了內置端點的暴露情況:

ID JMX Web
auditevents Yes No
beans Yes No
caches Yes No
conditions Yes No
configprops Yes No
env Yes No
flyway Yes No
health Yes Yes
heapdump N/A No
httptrace Yes No
info Yes Yes
integrationgraph Yes No
jolokia N/A No
logfile N/A No
loggers Yes No
liquibase Yes No
metrics Yes No
mappings Yes No
prometheus N/A No
scheduledtasks Yes No
sessions Yes No
shutdown Yes No
threaddump Yes No

去改變將那個端點暴露出來,可以使用特定的技術include和exclude屬性:

Property Default
management.endpoints.jmx.exposure.exclude
management.endpoints.jmx.exposure.include *
management.endpoints.web.exposure.exclude
management.endpoints.web.exposure.include info, 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章