前言:

  上一节中,我们使用Hystrix Dashboard,只能看到单个应用内的服务信息。在生产环境中,我们经常是集群状态,所以我们需要用到Turbine这一应用。

  作用:汇总系统内的多个服务的数据并显示到Hystrix Dashboard上。

1. 新建Turbine项目

  添加依赖,pom文件

 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

2. 配置文件

  

# server
server.port=9998 # spring
spring.application.name=spring-cloud-turbine # eureka
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ # info自定义
info.build.name=@project.name@
info.build.description=@project.description@
info.build.groupId=@project.groupId@
info.build.artifact=@project.artifactId@
info.build.version=@project.version@ eureka.instance.status-page-url-path=/info
eureka.instance.instanceId=${spring.application.name}:${random.value}
eureka.instance.prefer-ip-address=true #设置拉取服务注册信息时间,默认60s
eureka.client.registry-fetch-interval-seconds=30 #指定续约更新频率,默认是30s
eureka.instance.lease-renewal-interval-in-seconds=15 #设置过期剔除时间,默认90s
eureka.instance.lease-expiration-duration-in-seconds=45 # turbine(说明:注意必须为大写,因为eureka返回的值都是大写的)
turbine.aggregator.clusterConfig=SPRING-CLOUD-CONSUMER
turbine.app-config=spring-cloud-consumer

在项目启动类中添加@EnableTurbine注解。

3. 修改消费者servlet的映射路径

  在2.x中,所有监控都会带上actuator根路径,所以我们需要修改消费者中HystrixMetricsStreamServlet注册时的映射路径,如下:

  将原来的/hystrix.stream修改为/actuator/hystrix.stream即可

 /**
* 配置Hystrix.stream的servlet
* @return
*/
@Bean
public ServletRegistrationBean registrationBean() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}

4. 测试:如何监控一个集群应用

  1. 启动三个不同端口的SPRING-CLOUD-CONSUMER.

  2. 访问http://localhost:9999/hystrix

    同时要监控9996,9997,9999三个端口

    方法一:

      分别加入http://localhost:9996/actuator/hystrix.stream,http://localhost:9997/actuator/hystrix.stream,http://localhost:9999/actuator/hystrix.stream三个路径。

    方法二:

      加入:http://localhost:9998/turbine.stream?cluster=SPRING-CLOUD-CONSUMER

        说明:其中cluster对应配置文件中的clusterConfig的名称

  3. 访问三个端口对应的服务,查看dashboard如下

  

  这里有一个服务的断路器策略是线程池熔断策略,所以会显示线程池的信息。

5. 如何监控多个集群

  1.在turbine中注释掉之前的配置,添加新的配置

turbine.aggregator.clusterConfig=WANGX
turbine.app-config=spring-cloud-consumer,spring-cloud-consumer2
turbine.cluster-name-expression=metadata['cluster']
turbine.combine-host-port=true

  2. 在消费者中添加配置

  eureka.instance.metadata-map.cluster=WANGX

  在http://localhost:9999/hystrix中加入http://localhost:9998/turbine.stream?cluster=WANGX

  此时会检测所有添加了数据源cluster的服务

6. 测试:监控全部应用

  1. 在turbine中添加修改配置

  保留 

turbine.app-config=spring-cloud-consumer,spring-cloud-consumer2

  修改

turbine.cluster-name-expression="default"

  注释掉turbine.aggregator.clusterConfig=WANGX

#turbine.aggregator.clusterConfig=WANGX

  在http://localhost:9999/hystrix中添加http://localhost:9998/turbine.stream

这样就可以对全部应用进行监控

SpringCloud学习笔记(16)----Spring Cloud Netflix之Hystrix Dashboard+Turbine集群监控的更多相关文章

  1. 断路器Hystrix与Turbine集群监控-Spring Cloud学习第三天(非原创)

    文章大纲 一.Hystrix基础介绍二.断路器Hystrix简单使用三.自定义Hystrix请求命令四.Hystrix的服务降级与异常处理五.Hystrix的请求缓存与请求合并六.Hystrix仪表盘 ...

  2. SpringCloud学习笔记(15)----Spring Cloud Netflix之Hystrix Dashboard的使用

    1. 引入依赖 在前面几节中的消费者中添加pom依赖. <dependency> <groupId>org.springframework.cloud</groupId& ...

  3. Spring Cloud Hystrix Dashboard熔断器-Turbine集群监控(六)

    序言 上一篇说啦hystrix的使用方法与配置还有工作流程及为何存在,我去,上一篇这么屌,去看看吧,没这么屌的话,我贴的有官方文档,好好仔细看看 hystrix除啦基本的熔断器功能之外,还可以对接口的 ...

  4. spring cloud: Hystrix(八):turbine集群监控(dashboard)

    turbine是聚合服务器发送事件流数据的一个工具,hystrix的监控中,只能监控单个节点,实际生产中都为集群, 因此可以通过turbine来监控集群下hystrix的metrics情况,通过eur ...

  5. Kubernetes 学习笔记(二):本地部署一个 kubernetes 集群

    前言 前面用到过的 minikube 只是一个单节点的 k8s 集群,这对于学习而言是不够的.我们需要有一个多节点集群,才能用到各种调度/监控功能.而且单节点只能是一个加引号的"集群&quo ...

  6. springCloud学习-消息总线(Spring Cloud Bus)

    1.简介 Spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来.它可以用于广播配置文件的更改或者服务之间的通讯,也可以用于监控.本文要讲述的是用Spring Cloud Bus实现 ...

  7. spring cloud:搭建基于consul的服务提供者集群(spring cloud hoxton sr8 / spring boot 2.3.4)

    一,搭建基于consul的服务提供者集群 1,consul集群,共3个实例: 2, 服务提供者集群:共2个实例: 3,服务消费者:一个实例即可 4,consul集群的搭建,请参考: https://w ...

  8. spring cloud(Greenwich.M2) hystrix dashboard 报/actuator/hystrix.stream 404 Not Found的问题

    consumer端不引用spring-boot-starter-actuator的情况 Consumer端会报Unable to connect to Command Metric Stream.新建 ...

  9. SpringCloud学习笔记(14)----Spring Cloud Netflix之Hystrix对Feign的支持

    1. Hystrix对Feign的支持 添加Feign中IUserBiz的实现类HystrixFallBack: package com.wangx.cloud.springcloud02consum ...

随机推荐

  1. Spinner默认选择问题

    1.需求中使用Spinner,不允许有默认选中,在网上查了好多,有设置 spinner.setSelection(-1,true); 也有设置如下: spinner.setOnItemSelected ...

  2. Android ListView getView()方法重复调用导致position错位

    问题现状:Android ListView getView()方法重复调用导致position错位 解决办法:把ListView布局文件的layout_height属性改为fill_parent或者m ...

  3. 【原创】java的反射机制

    什么是java的反射?java在运行期间可以动态的加载.解析和使用一些在编译阶段并不确定的类型,这一机制被称作反射.它可以加载只有运行时才能确定的数据类型,解析类的内部结构,获取其基本信息,如方法.属 ...

  4. stm8s103调试注意点

    外设时钟的配置,有次ADC就是不工作,查问题查了很久,总是怀疑ADC配置问题,然后利用库函数的例程,发现就可以,最后发现,外设时钟没开启,外设时钟如下配置 CLK->PCKENR1 = 0x00 ...

  5. 配置HTTPS加密的快速参考指南

    Nginx ssl_protocols TLSv1 TLSv1.1 TLSv1.2 阿帕奇 SSLProtocol All -SSLv2 -SSLv3 密码套房 选择密码套件可能很困难,它们的名称可能 ...

  6. [luogu2059 JLOI2013] 卡牌游戏 (概率dp)

    题目描述 N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X,则庄家首先把 ...

  7. ubuntu18.04crontab定时任务不执行

    环境介绍: 本人使用python写了一个自动化提交巡检的脚本放在服务器上,使用crontab去执行脚本的时候动作并没有执行,查看crontab日志时也不存在这个日志文件.如何如排查呢? 解决方案: 步 ...

  8. django-8-django模型系统

    <<<表关系实现>>> 1.OneToOne  models.OneToOneField('another_table', on_delete=models.CAS ...

  9. CSLA框架的codesmith模板改造

    一直有关注CSLA框架,最近闲来无事,折腾了下,在最新的r3054版本基础上修改了一些东西,以备自己用,有兴趣的园友可以下载共同研究 1.添加了默认的授权规则 如果是列表对象则生成列表权限,User的 ...

  10. Objective-C 和 Core Foundation 对象相互转换

    iOS同意Objective-C 和 Core Foundation 对象之间能够轻松的转换: CFStringRef aCFString = (CFStringRef)aNSString; NSSt ...