一、簡介
Spring Boot Admin 用於監控基於 Spring Boot 的應用,它是在 Spring Boot Actuator 的基礎上提供簡潔的可視化 WEB UI。
客戶端應用可以通過Spring Boot Admin Client或者注冊中心就可以注冊到Spring Boot Admin服務端進行監控。Spring Boot Admin 是在 Spring Boot Actuator 的基礎上提供簡潔的可視化 WEB UI。2.X版本使用Vue.js重寫了UI界面,簡潔。
二、服務端搭建實戰
1、項目結構
2、父pom.xml
定義Spring Boot 及 Spring Cloud 版本
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.microservice</groupId> <artifactId>microservice-minitor</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>microservice-monitor-server</module> </modules> <properties> <java.version>1.8</java.version> <spring-boot.version>2.2.4.RELEASE</spring-boot.version> <spring-cloud.version>Hoxton.SR1</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
3、microservice-monitor-server -> pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>microservice-minitor</artifactId> <groupId>com.microservice</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>microservice-monitor-server</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.0</version> </dependency> </dependencies> </project>
4、microservice-monitor-server -> MinitorServerApplication
package com.microservice.minitor; import de.codecentric.boot.admin.server.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableAdminServer public class MinitorServerApplication { public static void main(String[] args) { SpringApplication.run(MinitorServerApplication.class, args); } }
5、microservice-monitor-server -> application.yml
server: port: 8888 spring: application: name: SpringBootAdmin boot: admin: ui: title: SpringBootAdmin-Server
三、運行測試
打開瀏覽器:http://localhost:8888/applications
出現如下界面,就表示Spring Boot Admin 服務端搭建成功!