Spring Boot Actuator 提供了運行狀態監控的功能 Actuator 監控數據可以通過阻REST
遠程 shell 和JMX方式獲得。我 首先來介紹通過 REST 方式查看 Actuator 的節點的方法,這
種是最常見且簡單的方法。
通過執行器端點,您可以監控應用程序並與之交互。Spring Boot包含許多內置端點,允許您
添加自己的端點。例如, health
端點提供基本的應用程序健康信息。
可以啟用或禁用每個端點。它控制是否創建端點並且其bean存在於應用程序上下文中。要進行
遠程訪問,還必須通過JMX或HTTP公開端點 。大多數應用程序選擇HTTP,其中端點的ID
以及前綴/actuator
映射到URL。例如,默認情況下,health
端點映射到/actuator/health
。
官方文檔地址:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
1、新建工程添加依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2.springboot2.x的配置
server.port=8009 management.server.port=8083
#開放所有頁面節點 默認只開啟了health、info兩個節點
management.endpoints.web.exposure.include=* #actuator端口 #修改訪問路徑 2.0之前默認是/ 2.0默認是 /actuator 可以通過這個屬性值修改 #management.endpoints.web.base-path: /actuator #顯示健康具體信息 默認不會顯示詳細信息 management.endpoint.health.show-details:ALWAYS
啟動項目!!
3、訪問http://localhost:8083/actuator
除了shutdown請求為post,其他的皆為GET請求
可以使用以下與技術無關的端點:
應用程序是Web應用程序(Spring MVC,Spring WebFlux或Jersey)
則可以使用以下附加端點:
Actuator 端口信息
啟用端點
默認情況下,shutdown
啟用除除以外的所有端點。要配置端點的啟用,請使用其
management.endpoint.<id>.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
3、個別接口的使用:
health
http://localhost:8083/actuator/health
{ "status": "UP", "details": { "diskSpace": { "status": "UP", "details": { "total": 248793526272, "free": 194452439040, "threshold": 10485760 } } } }
/health API 接口提供的信息是由 個或多個健康指示器提供的健康信息的組合結果
Spring Boot 自帶的健康指示器
具體看官網...........