当我们的应用程序使用了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、引入依赖

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

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

2、启动上增加  @EnableHystrixDashboard 注解

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

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

4、运行结果

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

1、代码结构

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

3、服务消费者

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

2、配置文件的写法

server:
port: 8100 eureka:
client:
service-url:
defaultZone : http://${security.user.name}:${security.user.password}@localhost:8761/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}
lease-renewal-interval-in-seconds: 3
lease-expiration-duration-in-seconds: 9
metadata-map:
cluster: PRODUCT security:
user:
name: root
password: admin
spring:
application:
name: product-consumer

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

4、turbine 工程的写法

1、引入依赖

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</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>

2、增加 @EnableHystrixDashboard @EnableTurbine 注解

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

3、配置文件的写法

server:
port: 8101 eureka:
client:
service-url:
defaultZone : http://${security.user.name}:${security.user.password}@localhost:8761/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port} security:
user:
name: root
password: admin
spring:
application:
name: product-hystrix-turbine-dashboard-8101 logging:
level:
org.hibernate : info
org.hibernate.type.descriptor.sql.BasicBinder : trace
org.hibernate.type.descriptor.sql.BasicExtraator : trace info:
app:
name: "product-hystrix-turbine-dashboard-8101"
description: "product-hystrix-turbine-dashboard-8101程序"
version: "0.0.1" turbine:
app-config: product-consumer
aggregator:
cluster-config: PRODUCT
combine-host-port: true
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配置

turbine:
app-config: product-consumer,order-consumer
aggregator:
cluster-config: PRODUCT
combine-host-port: true
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配置

turbine:
app-config: product-consumer,order-consumer
combine-host-port: true
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. Golang入门学习(四):常用的函数汇总

    文章目录 2.4 常用的内置函数 2.4.1 字符串常用内置函数 2.4.2 常用的时间和日期相关函数 2.4.3 内置函数 2.4 常用的内置函数 2.4.1 字符串常用内置函数 https://g ...

  2. 使用 elementUI 树形控件Tree 编辑数据

    操作新增/编辑功能时初始化数据: 应用属性 default-checked-keys 给Tree节点赋默认值(赋值数据为节点数组Arr)前,应先清空数组Arr,并且配合使用 this.$refs.tr ...

  3. Java集合:HashMap

    Hashmap是一个存储key-value的映射表. 优点: 索引数据快,查找一个数据对的时间复杂度是O(1) 增加.删除一个数据的时间复杂度是O(1) key不能重复,可以存储一个null值 存储: ...

  4. Django学习day07随堂笔记

    今日考题 """ 今日考题 1.必知必会N条都有哪些,每个都是干啥使的 2.简述神奇的双下划线查询都有哪些方法,作用是什么 3.针对多对多外键字段的增删改查方法有哪些,各 ...

  5. Matlab使用随记

    Matlab 2020 想要看图像每一点的值大小 工具--->数据提示 想要导出的分辨率提高 导出设置--->渲染--->600dpi Matlab 2017b 程序运行后,画出图, ...

  6. SonarQube汉化

    SonarQube安装后默认是英文,如果不习惯看英文,可以进行汉化,官方提供了汉化插件. 登录后,汉化步骤如下: 需要点击了解风险,不然查询到插件后没有install按钮 搜索Chinese,找到插件 ...

  7. ❤️❤️爆肝3万字整理小白快速入门分布式版本管理软件:Git,图文并茂(建议收藏)--已码一万字❤️❤️

    @ 目录 什么是Git SVN VS Git 什么是版本控制 安装Git 谁在操作? Git本地仓库 本地仓库构造 重点 Git基本操作 git add git commit git diff git ...

  8. ch_nginx.sh

    #!/bin/bash counter=`ps -ef |grep nginx |grep -v grep | wc -l` if [ $counter = 0 ];then service ngin ...

  9. mysql创建库

    建库 GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; UTF8: CREATE DATABAS ...

  10. PGSLQ并发控制

    并发控制简介 PostgreSQL提供了多种方式以控制对数据的并发访问.在数据库内部,数据的一致性使用多版本模式(多版本并发控制(Multiversion Concurrency Control),即 ...