主要是完成微服務的監控,完成監控治理。能夠查看微服務間的數據處理和調用,當它們之間出現了異常,就能夠快速定位到出現問題的地方。php
maven 項目 在 pom.xml
文件中加入 actuator 的依賴:css
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
使用 Gradle 構建:html
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
}
須要注意的是 Spring Boot 2.0 相對於上個版本, Actuator 發生不少變化,git
舊的屬性 | 新的屬性 |
---|---|
endpoints.<id>.* |
management.endpoint.<id>.* |
endpoints.cors.* |
management.endpoints.web.cors.* |
endpoints.jmx.* |
management.endpoints.jmx.* |
management.address |
management.server.address |
management.context-path |
management.server.servlet.context-path |
management.ssl.* |
management.server.ssl.* |
management.port |
management.server.port |
全部 endpoints 默認狀況下都已移至 /actuator
。就是多了跟路徑 actuator
;github
上個版本中的 management/context-path:
和 management/port:
改成 :web
management:
server:
port: 8004
servlet:
context-path: /xxx # 只有在設置了 management.server.port 時纔有效
另外,您還可使用新的單獨屬性 management.endpoints.web.base-path
爲管理端點設置基本路徑。spring
例如,若是你設置management.server.servlet.context-path=/management
和management.endpoints.web.base-path=/application
,你就能夠在下面的路徑到達終點健康:/management/application/health
。api
若是你想恢復 1.x 的行爲(即具備/health
代替/actuator/health
),設置如下屬性:management.endpoints.web.base-path=/
springboot
1.X 的時候屬性:markdown
HTTP 方法 | 路徑 | 描述 |
---|---|---|
GET | /autoconfig | 提供了一份自動配置報告,記錄哪些自動配置條件經過了,哪些沒經過 |
GET | /configprops | 描述配置屬性(包含默認值)如何注入Bean |
GET | /beans | 描述應用程序上下文裏所有的Bean,以及它們的關係 |
GET | /dump | 獲取線程活動的快照 |
GET | /env | 獲取所有環境屬性 |
GET | /env/{name} | 根據名稱獲取特定的環境屬性值 |
GET | /health | 報告應用程序的健康指標,這些值由HealthIndicator的實現類提供 |
GET | /info | 獲取應用程序的定製信息,這些信息由info打頭的屬性提供 |
GET | /mappings | 描述所有的URI路徑,以及它們和控制器(包含Actuator端點)的映射關係 |
GET | /metrics | 報告各類應用程序度量信息,好比內存用量和HTTP請求計數 |
GET | /metrics/{name} | 報告指定名稱的應用程序度量值 |
POST | /shutdown | 關閉應用程序,要求endpoints.shutdown.enabled設置爲true |
GET | /trace | 提供基本的HTTP請求跟蹤信息(時間戳、HTTP頭等) |
2.0 部分更改:
1.x 端點 | 2.0 端點(改變) |
---|---|
/actuator |
再也不可用。 可是,在 management.endpoints.web.base-path 的根目錄中有一個映射,它提供了到全部暴露端點的連接。 |
/auditevents |
該after 參數再也不須要 |
/autoconfig |
重命名爲 /conditions |
/docs |
再也不可用 |
/health |
如今有一個 management.endpoint.health.show-details 選項 never , always , when-authenticated ,而不是依靠 sensitive 標誌來肯定 health 端點是否必須顯示所有細節。 默認狀況下,/actuator/health 公開而且不顯示細節。 |
/trace |
重命名爲 /httptrace |
默認端點 path 前面多了一級 /actuator
。
同時注意只有端點/health
和/info
端點是暴露的。
Property | Default |
---|---|
management.endpoints.jmx.exposure.exclude |
|
management.endpoints.jmx.exposure.include |
* |
management.endpoints.web.exposure.exclude |
|
management.endpoints.web.exposure.include |
info, health |
1. 您能夠按以下方式公開全部端點:management.endpoints.web.exposure.include=*
2. 您能夠經過如下方式顯式啓用/shutdown
端點:management.endpoint.shutdown.enabled=true
3. 要公開全部(已啓用)網絡端點除env
端點以外:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env
例如:
我如今開啓全部的端點:
management:
endpoints:
web:
exposure:
include: "*" # * 在yaml 文件屬於關鍵字
執行 localhost:${port}/actuator
,能夠看到全部能夠執行查看的端點監控的 Url,而後咱們嘗試執行關閉應用進程的指令:shutdown
:
/actuator/mappings
端點大改變
JSON 格式已經更改成如今正確地包含有關上下文層次結構,多個DispatcherServlets,
部署的 Servlet 和 Servlet 過濾器的信息。詳情請參閱#9979。
Actuator API 文檔的相關部分提供了一個示例文檔。
/actuator/httptrace
端點大改變
響應的結構已通過改進,以反映端點關注跟蹤 HTTP 請求 - 響應交換的狀況。
主要是 Spring Boot 2.0 版本升級在 Actuator 上面有許多改動,須要記錄下。