当我们的应用程序使用了hystrix后,每个具体的hystrixCommand命令执行后都会产生一堆的监控数据,比如:成功数,失败数,超时数以及与之关联的线程池信息等。既然有了这些监控数据数据,那么我们应该如何进行查看呢?答案当然是通过hystrix dashboard 来进行查看,但hystrix dashboard只能查看单个应用内的服务信息,这个显然是不够的,因此我们需要一个能够将系统内多个服务的监控数据汇总到hystrix dashboard上,这个时候就应该使用turbine.

实现功能

假设我们存在服务消费方  product-consumerorder-consumer,且都使用了hystrix
    1、查看单个服务的 hystrix dashboard 信息

|- 即 product-consumer 只部署在一台机器上
    2、查看单个集群的 hystrix dashboard 信息

|- 即 product-consumer 部署在了多台机器上
    3、查看多个集群的 hystrix dashboard 信息

|- 即 product-consumer 和 order-consumer 都部署在了 1台~多台 机器上
    4、查看所有集群的 hystrix dashboard 信息
          |- 查看这个注册中心中所有的服务消费者的监控数据

前置条件

hystrix dashboard url 的格式

监控图标的指标信息

一、查看单个服务的 hystrix dashboard 的信息

1、代码结构:

2、hystrix dashboard程序的编写 ,注册中心、提供者和消费者略

   1、引入依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-test</artifactId>
  13. <scope>test</scope>
  14. </dependency>
  15. </dependencies>

主要是引入  spring-cloud-starter-netflix-hystrix-dashboard  这个依赖

2、启动上增加  @EnableHystrixDashboard 注解

  1. @SpringBootApplication
  2. @EnableDiscoveryClient
  3. @EnableHystrixDashboard
  4. public class ProductHystrixDashboard8097Application {
  5. public static void main(String[] args) {
  6. SpringApplication.run(ProductHystrixDashboard8097Application.class, args);
  7. }
  8. }

3、配置文件(application.yml)没有什么需要注意的,注册到eureka上即可。

4、运行结果

二、查看单个集群的 hystrix dashboard 信息

1、代码结构

2、服务提供者和注册中心略

3、服务消费者

1、java代码就是一个简单的调用远程服务(略)

2、配置文件的写法

  1. server:
  2. port: 8100
  3.  
  4. eureka:
  5. client:
  6. service-url:
  7. defaultZone : http://${security.user.name}:${security.user.password}@localhost:8761/eureka/
  8. instance:
  9. prefer-ip-address: true
  10. instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}
  11. lease-renewal-interval-in-seconds: 3
  12. lease-expiration-duration-in-seconds: 9
  13. metadata-map:
  14. cluster: PRODUCT
  15.  
  16. security:
  17. user:
  18. name: root
  19. password: admin
  20. spring:
  21. application:
  22. name: product-consumer

    需要注意: eureka.instance.metadata-map.cluster 的值,在 turbine 工程中这个值被使用到了

4、turbine 工程的写法

1、引入依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.cloud</groupId>
  12. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
  13. </dependency>
  14. <dependency>
  15. <groupId>org.springframework.boot</groupId>
  16. <artifactId>spring-boot-starter-actuator</artifactId>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.springframework.boot</groupId>
  20. <artifactId>spring-boot-starter-test</artifactId>
  21. <scope>test</scope>
  22. </dependency>
  23. </dependencies>

2、增加 @EnableHystrixDashboard @EnableTurbine 注解

  1. @SpringBootApplication
  2. @EnableDiscoveryClient
  3. @EnableHystrixDashboard
  4. @EnableTurbine
  5. public class ProductHystrixDashboard8101Application {
  6. public static void main(String[] args) {
  7. SpringApplication.run(ProductHystrixDashboard8101Application.class, args);
  8. }
  9. }

3、配置文件的写法

  1. server:
  2. port: 8101
  3. eureka:
  4. client:
  5. service-url:
  6. defaultZone : http://${security.user.name}:${security.user.password}@localhost:8761/eureka/
  7. instance:
  8. prefer-ip-address: true
  9. instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}
  10. security:
  11. user:
  12. name: root
  13. password: admin
  14. spring:
  15. application:
  16. name: product-hystrix-turbine-dashboard-8101
  17. logging:
  18. level:
  19. org.hibernate : info
  20. org.hibernate.type.descriptor.sql.BasicBinder : trace
  21. org.hibernate.type.descriptor.sql.BasicExtraator : trace
  22. info:
  23. app:
  24. name: "product-hystrix-turbine-dashboard-8101"
  25. description: "product-hystrix-turbine-dashboard-8101程序"
  26. version: "0.0.1"
  27. turbine:
  28. app-config: product-consumer
  29. aggregator:
  30. cluster-config: PRODUCT
  31. combine-host-port: true
  32. cluster-name-expression: metadata['cluster']

注意:

1、主要最后一段配置是和turbine相关,即 turbine 开头的配置

            2、turbine.app-config: 后方写的是服务名,即存在hystrim的服务的spring.application.name的值

            3、turbine.aggregator.cluster-config: 需要聚合的集群的名字列表,和服务消费者里面的eureka.instance.metadata-map.cluster的值一致

           4、turbine.cluster-name-expression: 获取集群名称的表达式,此处指的是获取元数据cluster的值。

   5、 turbine.combine-host-port: 为true 表示可以让同一主机上的服务通过主机名和端口号的组合来进行区分

5、整体代码架构

需要理清上面各个线的对应关系。

6、运行结果



 

三、查看多个集群的 hystrix dashboard 信息

服务注册中心、服务提供者、服务消费者和单个集群的配置是一样的。

turbine 工程中的yml配置

  1. turbine:
  2. app-config: product-consumer,order-consumer
  3. aggregator:
  4. cluster-config: PRODUCT
  5. combine-host-port: true
  6. cluster-name-expression: metadata['cluster']

app-config: 如果有多个,中间以逗号分隔

         cluster-config:如果有多个,中间以都好分隔

         hystrix dashboard页面上的访问路径: http://turbine:port/turbine.stream?cluster=[cluster-config中的值]

四、查看所有集群的 hystrxi dashboard 监控信息

服务注册中心、服务提供者、服务消费者和单个集群的配置是一样的。

  服务消费者工程不需要 eureka.instance.metadata-map.cluster的配置了。

  turbine 工程中的yml配置

  1. turbine:
  2. app-config: product-consumer,order-consumer
  3. combine-host-port: true
  4. cluster-name-expression: "'default'"

    app-config:需要聚合的服务名,有多个中间以 逗号 分开

    cluster-name-expression 的值修改成  default

    hystrix dashboard页面上的访问路径: http://turbine:port/turbine.stream

完整代码

上方四个工程的完整代码如下: https://gitee.com/huan1993/spring-cloud-parent/tree/master/hystrix-dashboard-turbine

hystrix的dashboard和turbine监控的更多相关文章

  1. Spring Cloud 入门教程(八): 断路器指标数据监控Hystrix Dashboard 和 Turbine

    1. Hystrix Dashboard (断路器:hystrix 仪表盘)  Hystrix一个很重要的功能是,可以通过HystrixCommand收集相关数据指标. Hystrix Dashboa ...

  2. spring cloud Hystrix监控面板Hystrix Dashboard和Turbine

    我们提到断路器是根据一段时间窗内的请求情况来判断并操作断路器的打开和关闭状态的.而这些请求情况的指标信息都是HystrixCommand和HystrixObservableCommand实例在执行过程 ...

  3. 跟我学SpringCloud | 第五篇:熔断监控Hystrix Dashboard和Turbine

    SpringCloud系列教程 | 第五篇:熔断监控Hystrix Dashboard和Turbine Springboot: 2.1.6.RELEASE SpringCloud: Greenwich ...

  4. 微服务SpringCloud之熔断监控Hystrix Dashboard和Turbine

    Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...

  5. Hystrix之Dashboard的常见问题

    Hystrix Dashboard (断路器:Hystrix 仪表盘)只监控一个实例,而Turbine监控多个实例,要使用Turbine必须使用Hystrix,因为Turbine是为了监控断路器的状态 ...

  6. springcloud(五):熔断监控Hystrix Dashboard和Turbine

    Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...

  7. spring cloud(五)熔断监控Hystrix Dashboard和Turbine

    Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...

  8. Spring Cloud(五):熔断监控Hystrix Dashboard和Turbine

    Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数 ...

  9. springcloud-熔断监控Hystrix Dashboard和Turbine

    作者:纯洁的微笑出处:http://www.ityouknow.com/ 版权归作者所有,转载请注明出处 Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystri ...

随机推荐

  1. 查询同一张表符合条件的某些数据的id拼接成一个字段返回

    同一张表存在类似多级菜单的上下级关系的数据,查询出符合条件的某些数据的id拼接成一个字段返回: SELECT CONCAT(a.pid, ',', b.subid) AS studentIDS FRO ...

  2. [CVE-2020-1956] Apache Kylin远程命令执行漏洞复现

    Apache Kylin是一个开源的.分布式的分析型数据仓库,提供Hadoop/Spark之上的 SQL 查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由 eBay 开发并贡献至开源社区. ...

  3. 机器学*——K*邻算法(KNN)

    1 前言 Kjin邻法(k-nearest neighbors,KNN)是一种基本的机器学*方法,采用类似"物以类聚,人以群分"的思想.比如,判断一个人的人品,只需观察他来往最密切 ...

  4. Dapr实战(三)状态管理

    状态管理解决了什么 分布式应用程序中的状态可能很有挑战性. 例如: 应用程序可能需要不同类型的数据存储. 访问和更新数据可能需要不同的一致性级别. 多个用户可以同时更新数据,这需要解决冲突. 服务必须 ...

  5. Linux系类(8) - 文件搜索命令locate

    文件搜索命令locate 命令格式 locate [文件名] 在后台数据库中按文件名搜索,搜索速度更快,而find.which是遍历所有目录去查找:后台数据库在/var/lib/mlocate (保存 ...

  6. Pycharm 使用问题一览

    1. I'm not sure if it is the problem of Pycharm or any other IDE. 需要从本地文件中导入文件,但总是出现波浪线,按ctril点进去发现是 ...

  7. html正文提取工具goose的安装及简单使用Demo

    1.git clone https://github.com/grangier/python-goose.git 2.cd python-goose 3.sudo pip install -r req ...

  8. AT3945-[ARC092D]Two Faced Edges【dfs】

    正题 题目链接:https://www.luogu.com.cn/problem/AT3945 题目大意 \(n\)个点\(m\)条边的一张图,对于每条边求它翻转后强连通分量数量是否变化. \(1\l ...

  9. mybatis中#{}与${}取值的区别

    1. 首先对于一个接口 Employee getEmpByIdAndName(@Param("id") Integer id,@Param("empName") ...

  10. 感恩笔记之SQL语句操纵数据集基本功能模板

    SQL查询_基本功能 一 SQL语句整体架构 SELECT --1 查询数据表 INTO --2 新建数据表 FROM --3 查询数据表 WHERE --4 筛选数据表 ORDER BY --5 排 ...