SpringBoot整合Actuator進行健康監控

勝金發表於2020-08-22

  一、Actuator介紹

  SpringBoot自帶監控功能Actuator,通過 restful api 請求來監管、審計、收集應用的執行情況,可以幫助實現對程式內部執行情況監控,比如監控狀況、Bean載入情況、環境變數、日誌資訊、執行緒資訊等。

  二、引入Actuator

  在pom.xml中引入spring-boot-starter-actuator標籤。

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

  在瀏覽器中開啟http://localhost:8080/actuator/,可以看到所有支援的連結。

 

   有關Actuator的介面API如:/info,/health,/beans,/env,/mappings,/trace,/dump,/shutdown等,可以訪問spring官網進行檢視:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints

  三、配置檔案

  在application.properties檔案中重新配置Actuator埠為8081,此時訪問Actuator流需要用8081埠訪問,關於Actuator是大量配置項,可以在spring中檢視。

 

   很明顯,Springboot中整合了Actuator後可以通過API訪問並獲取程式的執行狀況,此時我們可以自己可以根據API自己開發視覺化頁面,更好的監測系統的執行。另外,spring給我提供了對應的監控平臺,

我們只需要在專案中引入SpringAdmin依賴,就可以搭建一個完整的監控平臺,下一篇,勝金就寫一下搭建SpringAdmin的過程。

 

相關文章