如何監控springboot的健康狀況
SpringBoot1.5.19.RELEASE
一、使用Actuator檢查與監控
actuaotr是spring boot專案中非常強大的一個功能,有助于對應用程式進行監控和管理,通過restful api請求來監管、審計、收集應用的運行情況,針對微服務而言它是必不可少的一個環節,
-
在pom檔案中添加Actuator坐標
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> -
在全域組態檔中設定關閉安全限制
management.security.enabled=false -
運行,會發現控制臺列印資訊變多了

- 直接訪問
eg: http://localhost:8080/health http://localhost:8080/dump http://localhost:8080/beans 等
具體可參考:https://www.cnblogs.com/baidawei/p/9183531.html
二、Spring Boot Admin
Spring Boot Admin 提供了很多功能,如顯示 name、id 和 version,顯示在線狀態,Loggers 的日志級別管理,Threads 執行緒管理,Environment 管理等,
-
訪問spring boot admin的github頁面:https://github.com/codecentric/spring-boot-admin
-------以下內容在服務端操作:
-
在pom檔案中添加spring boot admin 坐標
<dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>1.5.7</version> </dependency> </dependencies> -
在啟動類中增加注解:@EnableAdminServer
@SpringBootApplication @EnableAdminServer public class SpringbootHelloworldApplication { public static void main(String[] args) { SpringApplication.run(SpringbootHelloworldApplication.class, args); } }-------以下內容在客戶端操作:
-
在客戶端(另一個專案)pom檔案添加依賴
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.7</version> </dependency> -
修改properties檔案
#服務端的ip地址和埠 spring.boot.admin.url: http://localhost:8383 management.security.enabled=false -
此時客戶端的埠是:8080 ; 服務端的埠是8383
-
先啟動服務端,打開網頁:http://localhost:8383 (什么都沒有,因為客戶端還沒啟動)

- 啟動客戶端

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/65100.html
標籤:Java
上一篇:HTTP與TCP的區別和聯系
