概述
在我之前的 《Spring Boot應用監控實戰》 一文中,講述瞭如何利用 Spring Boot Admin 1.5.X 版本來視覺化地監控 Spring Boot 應用。說時遲,那時快,現在 Spring Boot Admin 都更新到 2.0 版本了,並且可以對當下熱門的 Spring Boot 2.0 和 Spring Cloud Finchley.RELEASE 進行監控,因此本文就來了解並實踐一下!
注: 本文首發於 My 公眾號 CodeSheep ,可 長按 或 掃描 下面的 小心心 來訂閱 ↓ ↓ ↓

Spring Boot Admin 2.0新特性
Spring Boot Admin 2.0 變化還是挺多的,具體參考 官網說明,這裡列幾條主要的:
-
使用Vue.js重寫了UI介面,漂亮得不像實力派
-
直接整合了基於 spring security 的認證,無需引入第三方模組
-
加入 session endpoint 的監控支援
等等...
下面就實際試驗來操作感受一下!
搭建 Spring Boot Admin Server
- 建立一個 SpringBoot 2.0.3 RELEASE 工程並新增依賴
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
複製程式碼
- 應用主類新增註解
@SpringBootApplication
@EnableAdminServer
public class SbaServer20Application {
public static void main(String[] args) {
SpringApplication.run(SbaServer20Application.class, args);
}
}
複製程式碼
- 啟動 Spring Boot Admin Server
瀏覽器開啟 localhost:8080
,就可以看到小清新的頁面了

可以看到這個 UI 的變化和 1.5.X 時代的差距還是蠻大的,此時被監控的應用數目還為0。
接下來我們就來建立一個待監控的Spring Boot 2.0示例。
建立 Spring Boot Admin Client
此處我們依然建立一個 Spring Boot 2.0.3.RELEASE 的應用,然後加入到Spring Boot Admin之中進行監控
- pom.xml中新增依賴
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
複製程式碼
- 編輯配置檔案
server.port=8081
spring.application.name=Spring Boot Client
spring.boot.admin.client.url=http://localhost:8080
management.endpoints.web.exposure.include=*
複製程式碼
- 啟動 Spring Boot Admin Client 應用
此時 Spring Boot Admin的頁面上應用上線的訊息推送過來了:

實際實驗
被監控應用上線之後,我們進入 Spring Boot Admin頁面鼓搗看看
- Wallboard 有點小清新

- Applications 概覽

- Applications上線日誌一目瞭然

- Applications Details

- Metrics

- Environment

- JMX

- Threads

- Http Traces

後記
作者更多的SpringBt實踐文章在此:
- Spring Boot應用監控實戰
- SpringBoot應用部署於外接Tomcat容器
- ElasticSearch搜尋引擎在SpringBt中的實踐
- 初探Kotlin+SpringBoot聯合程式設計
- Spring Boot日誌框架實踐
- SpringBoot優雅編碼之:Lombok加持
如果有興趣,也可以抽點時間看看作者一些關於容器化、微服務化方面的文章:
- 利用K8S技術棧打造個人私有云 連載文章
- 從一份配置清單詳解Nginx伺服器配置
- Docker容器視覺化監控中心搭建
- 利用ELK搭建Docker容器化應用日誌中心
- RPC框架實踐之:Apache Thrift
- RPC框架實踐之:Google gRPC
- 微服務呼叫鏈追蹤中心搭建
- Docker容器跨主機通訊
- Docker Swarm叢集初探
- 高效編寫Dockerfile的幾條準則
