【SpringCloud】第十二篇: 斷路器監控(Hystrix Turbine)


前言:

必需學會SpringBoot基礎知識

簡介:

spring cloud 為開發人員提供了快速構建分布式系統的一些工具,包括配置管理、服務發現、斷路器、路由、微代理、事件總線、全局鎖、決策競選、分布式會話等等。它運行環境簡單,可以在開發人員的電腦上跑。

工具:

JDK8

apache-maven-3.5.2

IntelliJ IDEA 2017.3 x64

 

一、Hystrix Turbine簡介

看單個的Hystrix Dashboard的數據並沒有什么多大的價值,要想看這個系統的Hystrix Dashboard數據就需要用到Hystrix Turbine。Hystrix Turbine將每個服務Hystrix Dashboard數據進行了整合。Hystrix Turbine的使用非常簡單,只需要引入相應的依賴和加上注解和配置就可以了。

 

二、准備工作

本文使用的工程為上一篇文章的工程,在此基礎上進行改造。需要添加兩個服務項目, 本章節共需要四個項目, 3 and 4 是追加的

  1. eureka-server-hystrix-dashboard
  2. eureka-client-hystrix-dashboard
  3. eureka-client-hystrix-dashboard2 (仿照 2 改造*yml,需要修改名稱加載順序)
  4. eureka-client-hystrix-turbine

 

三、創建 eureka-client-hystrix-turbine

引入相應的依賴:

<?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.lwc</groupId>
    <artifactId>eureka-client-hystrix-turbine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>eureka-client-hystrix-turbine</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Edgware.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</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>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>


</project>

配置文件application.yml:

spring:
  application.name: eureka-client-hystrix-turbine
server:
  port: 8769
security.basic.enabled: false
turbine:
  aggregator:
    clusterConfig: default
  appConfig: eureka-client-hystrix-dashboard,eureka-client-hystrix-dashboard2
  clusterNameExpression: new String("default")
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

配置文件, 具體我也是看百度在修改. 其實也無什么, 看API也有!

四、Turbine演示

依次開啟工程:

  1. eureka-server-hystrix-dashboard
  2. eureka-client-hystrix-dashboard
  3. eureka-client-hystrix-dashboard2
  4. eureka-client-hystrix-turbine

打開瀏覽器輸入: http://localhost:8761/ 查看注冊中心界面如下:

image

打開瀏覽器輸入:http://localhost:8769/turbine.stream,界面如下:

image

請求 (如果不依次, 你可能會感覺出問題, 因為WEB無數據)

http://localhost:8762/eureka/client?name=eddie

http://localhost:8763/eureka/client?name=eddie

打開:http://localhost:8763/hystrix,輸入監控流http://localhost:8769/turbine.stream

image

點擊monitor stream 進入頁面:

image

可以看到這個頁面聚合了2個service的hystrix dashbord數據。

 

提醒: 如果WEB UI 沒有數據, 建議你把全部服務重啟在試試!

 

五、源碼下載:

標簽 12-1

https://github.com/eddie-code/SpringCloudDemo


免責聲明!

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



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