版权声明:本文为博主原创文章,欢迎转载,转载请注明作者、原文超链接 ,博主地址:http://blog.csdn.net/forezp。 http://blog.csdn.net/forezp/article/details/70233227

 

目录(?)[+]

 

转载请标明出处: 
http://blog.csdn.net/forezp/article/details/70233227 
本文出自方志朋的博客

上一篇文章讲述了如何利用Hystrix Dashboard去监控断路器的Hystrix command。当我们有很多个服务的时候,这就需要聚合所以服务的Hystrix Dashboard的数据了。这就需要用到Spring Cloud的另一个组件了,即Hystrix Turbine。

一、Hystrix Turbine简介

看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务Hystrix Dashboard数据进行了整合。Hystrix Turbine的使用非常简单,只需要引入相应的依赖和加上注解和配置就可以了。

二、准备工作

本文使用的工程为上一篇文章的工程,在此基础上进行改造。因为我们需要多个服务的Dashboard,所以需要再建一个服务,取名为service-lucy,它的基本配置同service-hi,具体见源码,在这里就不详细说明。

三、创建service-turbine

引入相应的依赖:

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

在其入口类ServiceTurbineApplication加上注解@EnableTurbine,开启turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即开启了注册服务。


@SpringBootApplication
@EnableTurbine
public class ServiceTurbineApplication { public static void main(String[] args) { new SpringApplicationBuilder(ServiceTurbineApplication.class).web(true).run(args);
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

配置文件application.yml:

spring:
application.name: service-turbine
server:
port: 8769
security.basic.enabled: false
turbine:
aggregator:
clusterConfig: default # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问
appConfig: service-hi,service-lucy ### 配置Eureka中的serviceId列表,表明监控哪些服务
clusterNameExpression: new String("default")
# 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称
# 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
# 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

配置文件注解写的很清楚。

四、Turbine演示

依次开启eureka-server、service-hi、service-lucy、service-turbine工程。

打开浏览器输入:http://localhost:8769/turbine.stream,界面如下:

依次请求:

http://localhost:8762/hi?name=forezp

http://localhost:8763/hi?name=forezp

打开:http://localhost:8763/hystrix,输入监控流http://localhost:8769/turbine.stream

点击monitor stream 进入页面:

可以看到这个页面聚合了2个service的hystrix dashbord数据

最新文章

  1. 关于在线编辑器的选择:tinymce - nilcms
  2. 扩展GridView控件——为内容项添加拖放及分组功能
  3. javascript中,如何判断input中输入的为纯数字
  4. AVL树(二)之 C++的实现
  5. iOS相机操作笔记
  6. 【锋利的JQuery-学习笔记】Tab选项卡的实现
  7. 区域生长算法的一种C++实现
  8. Android开发之BroadcastReceiver的使用
  9. [swustoj 764] 校门外的树 Plus Plus
  10. Restart-ServiceEx.psm1
  11. React.js终探(七)(完)
  12. Stack-overflow, how to answer
  13. Android系统--输入系统(十一)Reader线程_简单处理
  14. 转 Caffe学习系列(2):数据层及参数
  15. 20175324 2018-2019-2 《Java程序设计》第5周学习总结
  16. babel-polyfill使用与性能优化
  17. 【分享】Asp.net Core相关教程及开源项目
  18. git(转载谢谢)
  19. Spark LR逻辑回归中RDD转DF中VectorUDT设置
  20. DDD领域模型实现依赖注入(六)

热门文章

  1. C/C++中的输出对齐设置
  2. s5_day1作业
  3. List集合的ForEach扩展
  4. JavaScript:关闭当前页面(微信、电脑)
  5. MongoDB win32-bit 安装
  6. linux命令(6/11)--修改文件的用户组chgrp和文件所有者chown
  7. 存在单点故障的namenode宕机恢复测试
  8. jdbc封装代码
  9. JavaWeb HTTP
  10. 六款常见的Linux操作系统推荐