Spring Boot Admin 服務追蹤

學習完整課程請移步 互聯(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)以下界面

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末白嘁,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子膘流,更是在濱河造成了極大的恐慌絮缅,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,084評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呼股,死亡現(xiàn)場離奇詭異耕魄,居然都是意外死亡,警方通過查閱死者的電腦和手機彭谁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評論 3 392
  • 文/潘曉璐 我一進店門吸奴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人缠局,你說我怎么就攤上這事则奥。” “怎么了狭园?”我有些...
    開封第一講書人閱讀 163,450評論 0 353
  • 文/不壞的土叔 我叫張陵读处,是天一觀的道長。 經(jīng)常有香客問我唱矛,道長罚舱,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,322評論 1 293
  • 正文 為了忘掉前任绎谦,我火速辦了婚禮管闷,結果婚禮上,老公的妹妹穿的比我還像新娘燥滑。我一直安慰自己渐北,他們只是感情好阿逃,可當我...
    茶點故事閱讀 67,370評論 6 390
  • 文/花漫 我一把揭開白布铭拧。 她就那樣靜靜地躺著赃蛛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪搀菩。 梳的紋絲不亂的頭發(fā)上呕臂,一...
    開封第一講書人閱讀 51,274評論 1 300
  • 那天,我揣著相機與錄音肪跋,去河邊找鬼歧蒋。 笑死,一個胖子當著我的面吹牛州既,可吹牛的內容都是我干的谜洽。 我是一名探鬼主播,決...
    沈念sama閱讀 40,126評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼吴叶,長吁一口氣:“原來是場噩夢啊……” “哼阐虚!你這毒婦竟也來了?” 一聲冷哼從身側響起蚌卤,我...
    開封第一講書人閱讀 38,980評論 0 275
  • 序言:老撾萬榮一對情侶失蹤实束,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后逊彭,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體咸灿,經(jīng)...
    沈念sama閱讀 45,414評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,599評論 3 334
  • 正文 我和宋清朗相戀三年侮叮,在試婚紗的時候發(fā)現(xiàn)自己被綠了避矢。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,773評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡签赃,死狀恐怖谷异,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情锦聊,我是刑警寧澤歹嘹,帶...
    沈念sama閱讀 35,470評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站孔庭,受9級特大地震影響尺上,放射性物質發(fā)生泄漏。R本人自食惡果不足惜圆到,卻給世界環(huán)境...
    茶點故事閱讀 41,080評論 3 327
  • 文/蒙蒙 一怎抛、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧芽淡,春花似錦马绝、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽掷邦。三九已至,卻和暖如春椭赋,著一層夾襖步出監(jiān)牢的瞬間抚岗,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評論 1 269
  • 我被黑心中介騙來泰國打工哪怔, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留宣蔚,地道東北人。 一個月前我還...
    沈念sama閱讀 47,865評論 2 370
  • 正文 我出身青樓认境,卻偏偏與公主長得像胚委,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子叉信,可洞房花燭夜當晚...
    茶點故事閱讀 44,689評論 2 354