Spring-boot-admin功能說明


http://blog.csdn.net/xingfulangren/article/details/52304413

***************************************************

1.      准備

1.1   介紹

spring-boot-admin的Github源碼地址:https://github.com/codecentric/spring-boot-admin

在Spring Boot Actuator的基礎上提供簡潔的可視化WEB UI,是用來管理 Spring Boot 應用程序的一個簡單的界面,提供如下功能:

顯示 name/id 和版本號

顯示在線狀態

Logging日志級別管理

JMX beans管理

Threads會話和線程管理

Trace應用請求跟蹤

應用運行參數信息,如:

Java 系統屬性

Java 環境變量屬性

內存信息

Spring 環境屬性


1.2組成部分

Spring-boot-admin由服務器端和客戶端組成

服務器端配置(gradle工程):

build.gradle:compile("de.codecentric:spring-boot-admin-server:1.4.1")

compile("de.codecentric:spring-boot-admin-server-ui:1.4.1")

application.properties:server.port= 8090  (自定義)

spring.application.name=Spring Boot Admin Web (自定義)

spring.boot.admin.url=http://localhost:${server.port}(自定義)

spring.jackson.serialization.indent_output=true

endpoints.health.sensitive=false

info.version=1.0.0(自定義)

啟動spring-boot項目時需要加上@SpringBootApplication和 @EnableAdminServer 標簽

客戶端配置(gradle工程):

build.gradle:compile("de.codecentric:spring-boot-admin-starter-client:1.4.1")

application.properties:spring.application.name=spring-boot-admin-client (自定義)

spring.boot.admin.url=http://localhost:8090(注冊到server)

server.port=8080(自定義)

info.version=1.0.0 (自定義)


spring-boot-admin-server:服務器后端處理邏輯代碼

spring-boot-admin-server-ui:前端界面展示

spring-boot-admin-starter-client:客戶端,需要添加到spring-boot項目中


2.      工作原理

2.1   客戶端注冊

客戶端啟動后會實例化RegistrationApplicationListener,listener默認會每隔10s到服務端去注冊下,如果已經存在,會refresh

具體代碼如下:


在跟服務器注冊之前,客戶端會先實例化Application信息,獲取相應的信息,然后通過restful http post請求跟服務器交互


服務端代碼邏輯:服務器端首先會根據客戶端的HealthUrl,通過SHA-1 算法得到客戶端的id值,借此區分不同的客戶端節點

獲取到客戶端id后,從服務端保存的ConcurrentHashMap 對象中,根據id獲取客戶端狀態信息,如果存在狀態信息,則refresh或者replace,否則往map中新加客戶端信息


2.2   路由

客戶端注冊到服務端,會由服務端維護一層路由映射,會在路徑上添加前綴、客戶端id和后綴,默認前綴為:/api/applications  后綴:/**

Mapped URL path [/api/applications/73abdba9/health/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/env/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/metrics/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/trace/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/dump/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/jolokia/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/info/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/activiti/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/logfile/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/refresh/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/flyway/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/liquibase/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]
Mapped URL path [/api/applications/73abdba9/heapdump/**] onto handler of type [class de.codecentric.boot.admin.zuul.OptionsDispatchingZuulController]

73abdba9 為客戶端的id

具體代碼如下:


 

具體的路由信息如下:

route matched=Route(id=73abdba9-health, fullPath=/api/applications/73abdba9/health/**,path=/**,location=http://pc-PC:8090/health,prefix=/api/applications/73abdba9/health, retryable=false, sensitiveHeaders=[],customSensitiveHeaders=false)

包含請求的路徑,以及具體節點的實際訪問路徑(location)

2.3 具體請求執行路徑

用戶觸發界面 -> 界面發起請求(帶有具體的客戶端id)  -> 經過服務器端路由映射-> 具體節點的訪問路徑 -> 調用Spring Boot Autuator 監控接口獲取數據返回

界面代碼:

經過測試發現health 接口,默認每隔20秒都會觸發一次,其它接口只有刷新后才會觸發接口調用,也許health被設計成心跳連接(猜測)

 

3.Spring Boot Autuator 監控

Spring boot autuator 提供很多的Endpoints 訪問

endpoints = { "env", "metrics","trace", "dump", "jolokia", "info","activiti", "logfile", "refresh","flyway", "liquibase", "heapdump" };

endpoints說明以及自定義:

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM