【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

posted @ 2018-04-13 14:57  Eddie.Lee  阅读(2309)  评论(0编辑  收藏  举报