Spring Boot 2.0 運行狀態監控使用 Actuator /actuator/refresh

springboot的Actuator提供了運行狀態監控的功能,可以通過REST、遠程Shell和JMX方式來查看。 
   
  使用時倒入spring-boot-starter-actuator的依賴即可。 
  這裏說下springboot2.0的配置方法,因爲springboot2開始配置項與之前有了些差別: 
  這裏寫圖片描述 
  之前的配置項爲: 
  

management.port=9001
management.security.enabled=false
  • 1
  • 2

這兩個屬性可以發現已經改變了。

springboot2.0 的配置項爲:

#actuator端口 
management.server.port=9001
#修改訪問路徑  2.0之前默認是/   2.0默認是 /actuator  可以通過這個屬性值修改  
management.endpoints.web.base-path=/monitor
#開放所有頁面節點  默認只開啓了health、info兩個節點
management.endpoints.web.exposure.include=*
#顯示健康具體信息  默認不會顯示詳細信息  
management.endpoint.health.show-details=always

配置完成啓動項目後就可以通過postman或者直接在預覽器輸入路徑等方式來查看應用的運行狀態了。

例如使用postman發送 localhost:9001/monitor/health GET請求 (除了shutdown請求爲post,其他的皆爲GET請求) 
這裏寫圖片描述
可以看到redis沒有連接成功。

Actuator的api接口: 
actuator API這裏寫圖片描述

health的健康指示器: 
這裏寫圖片描述

官方文檔地址:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

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