SpringBoot端點監控工具Actuator

SpringBoot actuator是一個對應用運行狀態監視的全方位的監控工具,actuator提供了很多可以被監視的端點(Endpoints),同時也支持自定義端點(Endpoint)
actuator提供了 API 的方式來監控各個端點的實時信息

1.在SpringBoot項目中pom.xml文件加入 actuator 的依賴

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

2.配置文件 application.properties 加入如下信息

server.port=8083

#安全起見,監控使用不同的端口
management.server.port=8090

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
info.author=ljq
[email protected]
info.version=1.0

3.啓動 SpringBoot 應用程序後訪問路由 http://localhost:8090/actuator/info
在這裏插入圖片描述

訪問路由 http://localhost:8090/actuator/health
在這裏插入圖片描述

其他端點監控的路由

- /actuator/autoconfig(/conditions) 應用的自動化配置報告 
- /actuator/beans 應用上下文創建的所有Bean 
- /actuator/configprops 應用中配置的屬性信息報告 
- /actuator/env 環境屬性報告 
- /actuator/mappings SpringMVC的控制器映射關係報告 
- /actuator/info 自定義的配置信息 
- /actuator/metrics 當前應用的各類重要度量指標 
- /actuator/health 應用的各類健康指標信息 
- /actuator/threaddump 用來暴露程序運行中的線程信息 
- /actuator/httptrace 顯示HTTP跟蹤信息(默認顯示最後100個HTTP請求) 
- /actuator/scheduledtasks 計劃任務 
- /actuator/shutdown 關閉應用程序(默認不開啓,需要修改配置文件) 

springboot 2.0及以上的版本將所有的端點都屏蔽了,所有 endpoints 默認情況下都已移至 /actuator下,所以路由中要加/actuator才能訪問到
Actuator只暴露了health和info端點。在SpringBoot的application.properties配置文件中加入如下配置暴露所有端點

management.endpoints.web.exposure.include=*

/actuator/autoconfig 會報錯404。因爲/autoconfig重命名爲/conditions

更多配置信息
在這裏插入圖片描述

在這裏插入圖片描述
更多屬性參數見官方文檔:
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html

爲了防止系統內部信息泄露,在配置文件中加入 management.server.port=8090,來和系統訪問端口隔離開來,防火牆屏蔽此類端口後,外部就訪問不到了。運用spring security安全框架配置用戶名和密碼也是一種安全措施。

關於springboot的監控的內容後續學習中繼續補充。

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