SpringCloud-Hystrix-Turbine

概述

Hystrix-Turbine

    我们使用 Hystrix Dashboard, 只能看到单个应用内的服务信息。在生产环境下,我们经常是集群状态,所以我们就要用到 Turbine 这个应用。
    作用:汇总系统内多个服务的数据并显示到 Hystrix Dashboard 上。


在Dashboard之前需要一个收集器Turbine



创建工程

microservice-hystrix-turbine


pom.xml

microservice-hystrix-turbine/pom.xml

<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.itmuch.cloud</groupId>
		<artifactId>microservice-spring-cloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<artifactId>microservice-hystrix-turbine</artifactId>
	<packaging>jar</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-turbine</artifactId>
		</dependency>
	</dependencies>

</project>

说明:

    1)需要增加spring-cloud-starter-turbine依赖;



application.yml

server:
  port: 8031
spring:
  application:
    name: microservice-hystrix-turbine
eureka:
  client:
    serviceUrl:
      defaultZone: http://user:password123@localhost:8761/eureka
  instance:
    prefer-ip-address: true
turbine:
  aggregator:
    clusterConfig: default
  appConfig: microservice-consumer-movie-ribbon-with-hystrix,microservice-consumer-movie-feign-with-hystrix
  clusterNameExpression: "'default'"

说明:

    1)turbine.appConfig :配置Eureka中的serviceId列表,表明监控哪些服务;

    2)turbine.aggregator.clusterConfig :指定聚合哪些集群,多个使用”,”分割,默认为default。

         可使用http://.../turbine.stream?cluster={clusterConfig之一}访问;

    3)turbine.clusterNameExpression :

  3.1)clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称;

         3.2)当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default;你需要一个文字表达式(使用单引号);

    3.3)当clusterNameExpression: metadata[‘cluster’]时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC

    4)记得将microservice-hystrix-turbine注册到microservice-hystrix-turbine中;




TurbineApplication

com.itmuch.cloud.TurbineApplication

package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@EnableTurbine
@SpringBootApplication
public class TurbineApplication {
  public static void main(String[] args) {
    SpringApplication.run(TurbineApplication.class, args);
  }
}

说明:

    1)添加 @EnableTurbine 注解,激活对Turbine的支持;










创建microservice-hystrix-dashboard工程



pom.xml

microservice-hystrix-dashboard/pom.xml

<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.itmuch.cloud</groupId>
		<artifactId>microservice-spring-cloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<artifactId>microservice-hystrix-dashboard</artifactId>
	<packaging>jar</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
		</dependency>
	</dependencies>

</project>


application.yml

server:
  port: 8030


EurekaApplication

com.itmuch.cloud.EurekaApplication

package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@EnableHystrixDashboard
@SpringBootApplication
public class EurekaApplication {
  public static void main(String[] args) {
    SpringApplication.run(EurekaApplication.class, args);
  }
}

说明:

    1)@EnableHystrixDashboard,在启动类中添加Hystrix Dashboard支持;









测试



启动工程

    1)microservice-discovery-eureka

    2)microservice-provider-user

    3)microservice-consumer-movie-ribbon-with-hystrix,

    4)microservice-consumer-movie-feign-with-hystrix

    5)microservice-hystrix-turbine

    6)microservice-hystrix-dashboard



访问http://localhost:8031/turbine.stream


说明:

    1)并且会不断刷新以获取实时的监控数据,说明和单个的监控类似,返回监控项目的信息。



图形化监控查看


http://localhost:8030/hystrix

说明:

    1)http://localhost:8031/turbine.stream

    2)microservice-hystrix-turbine


访问服务


http://localhost:7901/movie/1

http://localhost:8010/movie/1

访问后再看变化;


说明:

    1)实心圆:颜色代表健康度,(绿-黄-红-橙递减);大小代表并发量。

    2)曲线:请求量的变化

    3)其他主要参数间图红色字体部分。










==============================

QQ群:143522604

群里有相关资源

欢迎和大家一起学习、交流、提升!

==============================


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值