前言:

  上一节中,我们使用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

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

最新文章

  1. HTML5的postMessage使用记要
  2. Dynamics AX 2012 R2 AIF 内部异常
  3. Ionic发布成android
  4. ModernUI教程:定义一个Logo
  5. python日常-int和float
  6. RegExp类型,单体内置对象
  7. C++头文件的组织
  8. javascript 简繁转换
  9. Socket之UDP发送文件
  10. STM32之DMA
  11. 1.document.write(&quot;&quot;); 输出语句
  12. xml入门视频
  13. 分布式版本库——Windows下Git的环境部署以及在GitHub上开源自己的项目
  14. VB洗牌算法产生随机数组
  15. 多线程、互斥锁、异步、GIL
  16. css选择器的优先级算法
  17. 发布webservice之后调用不通
  18. 数据库索引和SQL语句使用经验
  19. Web标准:三、二列和三列布局
  20. JQuery和Servlet来实现跨域请求

热门文章

  1. Android蓝牙2.0连接以及数据接收发送
  2. listview添加的头部布局超过一屏头部内容显示不全
  3. PHP单词表
  4. JS使用三元运算符判断三个数中最大的数
  5. jQuery中的DatePicker今天按钮不起作用
  6. 三、frpc 完整配置文件
  7. Myeclipse关闭JS等文件的验证
  8. java内存管理之垃圾回收及JVM调优
  9. SQL SERVER-union
  10. 使用Modernizr检测支持CSS3