1. 概述

为了更好的监控Hystrix的性能,Spring Cloud提供Hystrix dashboard和Turbin来达到这个目的。
Hystrix dashboard可以实时监控Hystrix的运行情况。但是Hystrix dashboard只能对单台进行监控。但是在实际系统中,通常不止一个服务,为了方便监控,我们需要将多个Hystrix dashboard的数据汇总在一个dashboard中展示出来, 这个工具就是Turbine。
本文演示Hystrix dashboard和Turbine的用法

2. Hystrix dashboard

Hystrix dashboard可以实时监控Hystrix的运行情况。但是Hystrix dashboard只能对单台进行监控。

2.1. 相关工程

相关的工程说明

  • cloud-registration-center:注册中心
  • cloud-service-hystrix: 作为服务方的工程
  • cloud-consumer-hystrix:通过Hystrix调用cloud-service-hystrix的接口

本节使用的工程和Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理相同
其中cloud-registration-center和cloud-service-hystrix完全相同,请参考上一篇文章

2.2. 配置Hystrix日志监控

以下的配置都在工程cloud-consumer-hystrix中。
为了在服务中添加Hystrix dashboard的支持,我们对cloud-consumer-hystrix进行改造(这个工程中在Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理中已经讲过,本节略),这里只列出变更的内容:

在pom.xml中增加Hystrix dashboard的依赖jar

<!-- hystrix dashboard -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- 如果提示 Unable to connect to Command Metric Stream. 则需要引入以下包 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

在启动类上增加@EnableCircuitBreaker注解,必须需要加上这个注解

@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient // 配置本应用将使用服务注册和服务发现
@EnableCircuitBreaker // 启动断路器,如果要监控hystrix的流必须开启此注解,即使fegin已经通过属性
public class HystrixFeignCloudConsumerApplication {….
}

测试
启动服务

  • 启动工程cloud-registration-center:

    • 配置中心地址:http://127.0.0.1:10761
  • 启动工程cloud-service-hystrix的HystrixCloudServiceApplication的启动类
  • 启动工程cloud-consumer-hystrix的HystrixFeignCloudConsumerApplication 的启动类

访问http://127.0.0.1:12082/hystrix.stream

会不断刷新如下信息

ping:
data: {"type":"HystrixCommand","name":"IMyHystrixClient#simpleHystrixClientCall(long)","group":"cloud-hystrix-service"….

如果没有以上打印信息,请先执行监控的URL,如本例中
http://127.0.0.1:12082//hystrix-feign/simple

2.3. 启动Hystrix-dashboard界面监控

上面的日志信息不够直观,借助Hystrix-dashboard可对监控进行图形化展示
@EnableHystrixDashboard
在启动类上增加@EnableHystrixDashboard,开启Hystrix dashboard功能

@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient // 配置本应用将使用服务注册和服务发现
@EnableCircuitBreaker // 启动断路器,如果要监控hystrix的流必须开启此注解,即使fegin已经通过属性
@EnableHystrixDashboard // 开启dashboard,通过图形化的方式监控: 查看 http://127.0.0.1:12082/hystrix.stream
public class HystrixFeignCloudConsumerApplication {…
}

测试
在浏览器中输入:http://127.0.0.1:12082//hystrix,此时会得到如下界面

在第一个空格中输入http://127.0.0.1:12082/hystrix.stream,点击”Monitor Stream”,进入监控界面
当前你不断刷新 http://127.0.0.1:12082//hystrix-feign/simple 时,以下界面也会相应变化出现

注意:如果进入这个界面没有数据,请刷新这个界面。
图中各个字段的意义参考官方图

3. Turbine

Hystrix dashboard实现单台服务的Hystrix监控。但是在实际系统中,通常不止一个服务,为了方便监控,我们需要将多个Hystrix dashboard的数据汇总在一个dashboard中展示出来, 这个工具就是Turbine.

3.1. 新工程:cloud-dashboard-hystrix

我们单独建立一个工程做为Turbine的服务

pom.xml
除了引入HystrixDashboard的jar,还需要引入Turbin的包

<!-- hystrix dashboard -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- 如果提示 Unable to connect to Command Metric Stream. 则需要引入以下包 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency><!-- turbine -->
<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>

属性配置-bootstrap-dashboard.yml:
把自己注册到服务中心

# port
server:port: 12086spring:application:# 本服务注册到注册到服务器的名称, 这个名称就是后面调用服务时的服务标识符name: cloud-dashboard-hystrix
eureka:client:serviceUrl:# 服务器注册/获取服务器的zonedefaultZone: http://127.0.0.1:10761/eureka/instance:prefer-ip-address: true

属性配置application-dashboard.yml
配置turbine的服务,指定要监控的服务CLOUD-CONSUMER-HYSTRIX和聚合集群

turbine:# 配置Eureka中的serviceId列表,表明监控哪些服务,多个服务用',"分隔appConfig: CLOUD-CONSUMER-HYSTRIXaggregator:# 指定聚合哪些集群,多个使用”,”分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问clusterConfig: defaultclusterNameExpression: new String("default")

启动类HystrixDashboardCloudApplication
@EnableTurbine:启动Turbine

@SpringBootApplication
@EnableEurekaClient // 配置本应用将使用服务注册和服务发现
@EnableHystrixDashboard
@EnableTurbine // http://127.0.0.1:12086/hystrix
public class HystrixDashboardCloudApplication {public static void main(String[] args) {args = new String[1];args[0] = "--spring.profiles.active=dashboard";SpringApplication.run(HystrixDashboardCloudApplication.class, args);}
}

3.2 测试

测试单个服务监控
进入界面:http://127.0.0.1:12086/hystrix

这个界面我们可以只监控单个服务,也可以监视集群。监视单个服务的服务的方法,只需要在url栏里输入服务的Hystrix的stream地址即可,如要监控上节的服务,只需要输入http://127.0.0.1:12082//hystrix.stream,点击监控即可

测试集群的监控
为了更方便说明turbin的用户,我们需要启动两个CLOUD-CONSUMER-HYSTRIX

修改工程:cloud-consumer-hystrix,在HystrixSimpleCloudConsumerApplication上加上@EnableEurekaClient 并启动,关于此类的说明请参考本文Spring cloud系列十 使用@HystrixCommand使用Hystrix组件及@EnableCircuitBreaker原理介绍。

然后我们重启HystrixDashboardCloudApplication 服务
然后我们在http://127.0.0.1:12086/hystrix界面输入对http://127.0.0.1:12086/turbine.stream进行监控

然后不断刷新:http://127.0.0.1:12082/hystrix-feign/simple和http://127.0.0.1:12083/hystrix/simple
此时监控界面同时展现两个服务的hystrix信息

4. 代码

以上的详细的代码见下面
github代码,请尽量使用tag v0.9,不要使用master,因为我不能保证master代码一直不变

Spring cloud系列十二 监控Hystrix界面:Hystrix dashboard 和 Turbine相关推荐

  1. Spring cloud系列十八 Spring Cloud 从Dalston.SR5到Greenwich.SR1 的升级记录

    背景 项目之前一直使用Spring Cloud Dalston.SR5,但是此版本2018年12月软件生命周期要结束,为了后续安全和维护的需要,需要将对版本进行升级.先从官网上分析D版本的后续版本的变 ...

  2. 【Spring Cloud 系列】 二、Spring Cloud Eureka 的第一印象

    Eureka : 翻译翻译,找到了!(惊讶语气) Spring CLoud 中的 Spring Cloud Eureka,用于 分布式项目中的服务治理.是对Netflix 套件中的Eureka 的二次 ...

  3. 干货实操:微服务Spring Cloud 系列(二) Eureka服务发现与服务注册(strand alone)

    此篇主要实操Eureka 服务端的服务注册,以及服务发现,并需要认证才能访问控制中心. 分五个部分说明: 一.  认识 Eureka 二.  Eureka  服务端开发 三.  Eureka 客户端开 ...

  4. Spring Cloud第十二篇:断路器监控(Hystrix Dashboard)

    在我的第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard. 一.Hystrix Dashboard简 ...

  5. Spring Cloud(十二):Spring Cloud Security

    主要内容 Spring Security 模块 使用 设置用户名密码 基于内存 基于UserDetailsService 接口 基于配置类WebSecurityConfigurerAdapter 基于 ...

  6. java小马哥百度网盘_小马哥spring boot和spring cloud系列

    资源内容: 小马哥spring boot和spring cloud系列|____小马哥 Java 微服务实践 - Spring Boot 系列          |____pptx           ...

  7. 小马哥java_小马哥 Java 微服务实践 - Spring Cloud 系列

    资源内容: 小马哥 Java 微服务实践 - Spring Cloud 系列|____Java 微服务实践 - Spring Cloud系列(四)服务发现注册.wmv|____Java 微服务实践 - ...

  8. 【小马哥】Spring Cloud系列讲座

    这里推荐一个不错的Spring Cloud系列讲座,讲师简介如下: 小马哥,阿里巴巴技术专家,从事十余年Java EE 开发,国内微服务技术讲师.目前主要负责微服务技术推广.架构设计.基础设施.迁移等 ...

  9. Spring Cloud 系列之 Netflix Zuul 服务网关(三)

    本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Netflix Zuul 服务网关(一) Spring Cloud 系列之 Netflix Zuul 服务网关(二) ...

最新文章

  1. 基于TerraDeveloper的三维GIS开发研究
  2. 操作系统实验报告16:CPU 调度
  3. 文本替换sed+字段处理cut,join+awk重新编排字段
  4. 为什么设计师创造的编程语言更受欢迎?
  5. Leetcode--145. 二叉树的后序遍历(迭代递归)
  6. JavaScript语言基础(一)
  7. [BAT] 执行xcopy命令后出现Invalid num of parameters错误的解决办法
  8. 硅谷经历 7 场面试,我是如何最终进入 Facebook 的
  9. 天津东软实训第八天------倒排索引
  10. Erstudio8.0怎么用?Erstudio8.0汉化版详细使用教程
  11. FPGA 20个例程篇:12.千兆网口实现MDIO接口读写
  12. vimpython配色_你认为最好看的 Vim 配色方案(color scheme)是哪款?
  13. 什么是差模干扰和共模干扰?
  14. Unity镜头光晕模拟开源库
  15. Web认证方法探视(1)
  16. 【公务员考试】结构化面试时间一般多长?
  17. 国外主机注册域名有什么需要注意的吗?
  18. python2.7打开webdriver打不开ie_18个提高效率改变生活的网站,为你打开新世界的大门...
  19. ios 判断手机角度_iOS 角度获取及旋转
  20. python中true_python中的true是什么

热门文章

  1. 2018世界杯用户行为新趋势洞察报告
  2. React中使用axios来获取json文件
  3. 过程还是结果? Teradata带你“超越分析,直通成果”
  4. pcb成型板aoi检测,6种PCB板常用的检测方法
  5. java中classpath_java中的classpath
  6. LTS分布式任务调度文档
  7. [Warning] implicit declaration of function ‘clrscr‘ [-Wimplicit-function-declaration]
  8. 理解前端的 Middleware 原理与实现
  9. 性保健产品行业调研报告 - 市场现状分析与发展前景预测
  10. 肝了一夜!我用Python打造了一款武林外传QQ聊天室