學習完整課程請移步 互聯(lián)網(wǎng) Java 全棧工程師
概述
隨著開發(fā)周期的推移,項目會不斷變大,切分出的服務也會越來越多汪茧,這時一個個的微服務構成了錯綜復雜的系統(tǒng)。對于各個微服務系統(tǒng)的健康狀態(tài)限番、會話數(shù)量舱污、并發(fā)數(shù)、服務資源弥虐、延遲等度量信息的收集就成為了一個挑戰(zhàn)扩灯。Spring Boot Admin 應運而生媚赖,它正式基于這些需求開發(fā)出的一套功能強大的監(jiān)控管理系統(tǒng)。
Spring Boot Admin 有兩個角色組成珠插,一個是 Spring Boot Admin Server惧磺,一個是 Spring Boot Admin Client,本章節(jié)將帶領大家實現(xiàn) Spring Boot Admin 的搭建丧失。
Spring Boot Admin 服務端
本節(jié)視頻
創(chuàng)建 Spring Boot Admin Server
創(chuàng)建一個工程名為 hello-spring-cloud-admin
的項目豺妓,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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.funtl</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../hello-spring-cloud-dependencies/pom.xml</relativePath>
</parent>
<artifactId>hello-spring-cloud-admin</artifactId>
<packaging>jar</packaging>
<name>hello-spring-cloud-admin</name>
<url>http://www.funtl.com</url>
<inceptionYear>2018-Now</inceptionYear>
<dependencies>
<!-- Spring Boot Begin -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<!-- Spring Boot End -->
<!-- Spring Cloud Begin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- Spring Cloud End -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.funtl.hello.spring.cloud.admin.AdminApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
主要增加了 2 個依賴,org.jolokia:jolokia-core
布讹、de.codecentric:spring-boot-admin-starter-server
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
其中 spring-boot-admin-starter-server
的版本號為:2.0.0
琳拭,這里沒寫版本號是因為我已將版本號托管到 dependencies
項目中
Application
通過 @EnableAdminServer
注解開啟 Admin 功能
package com.funtl.hello.spring.cloud.admin;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
@EnableAdminServer
public class AdminApplication {
public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}
}
application.yml
設置端口號為:8084
spring:
application:
name: hello-spring-cloud-admin
zipkin:
base-url: http://localhost:9411
server:
port: 8084
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
# 注意:此處在視頻里是 include: ["health", "info"] 但已無效了,請修改
include: health,info
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
主要增加了 Spring Boot Admin Server 的相關配置
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
# 注意:此處在視頻里是 include: ["health", "info"] 但已無效了描验,請修改
include: health,info
測試訪問監(jiān)控中心
打開瀏覽器訪問:http://localhost:8084 會出現(xiàn)以下界面