十六、断路器-Turbine 的使用

来源:互联网 发布:刘氏哈蜜椴树白蜜 知乎 编辑:程序博客网 时间:2024/06/03 03:06

前言:
上一节里面,我们使用 Hystrix Dashboard, 只能看到单个应用内的服务信息。在生产环境下,我们经常是集群状态,所以我们就要用到 Turbine 这个应用。
作用:汇总系统内多个服务的数据并显示到 Hystrix Dashboard 上。
一、 新建项目 spring-cloud-turbine
1、 添加 jar

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

2、 配置文件:application.properties

# server server.port=9999 # spring spring.application.name=spring-cloud-turbine # eureka #eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ eureka.client.serviceUrl.defaultZone=http://drunck:123456@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

3、 创建主类,添加 @EnableTurbine 注解

package com.drunck.education; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.turbine.EnableTurbine; @EnableTurbine @SpringBootApplication public class TurbineApplication {  public static void main(String[] args) {   SpringApplication.run(TurbineApplication.class, args);  } } 

二、 测试:如何监控一个集群应用
1、 启动应用,SPRING-CLOUD-CONSUMER 启动 2 个(8888,8889),注意端口冲突(去除 devtools 依赖)
2、 访问:http://localhost:8761/hystrix
同时要监控 8888 和 8889 端口
方法一:
分别加入:
http://localhost:8888/hystrix.stream 和 http://localhost:8889/hystrix.stream
方法二:
加入:http://localhost:9999/turbine.stream?cluster=SPRING-CLOUD-CONSUMER
说明:其中 cluster 对应配置文件中 clusterConfig 中的名称
3、 访问:http://localhost:8888/user/1 和 http://localhost:8889/user/1

三、 测试:如何监控多个集群应用
1、spring-cloud-turbine 的 application.properties 添加配置:(注销之前的配置)

turbine.aggregator.clusterConfig=drunck turbine.app-config=spring-cloud-consumer,spring-cloud-consumer2 turbine.cluster-name-expression=metadata['cluster'] turbine.combine-host-port=true # 默认为 true,让同一个主机上面的服务通过主机名与端口号的组合来区分 

2、spring-cloud-consumer 的 application.properties 添加配置:

eureka.instance.metadata-map.cluster=DRUNCK

(这个时候,需要在 spring-cloud-consumer,spring-cloud-consumer2 配置)

3、在 http://localhost:8761/hystrix 加入:http://localhost:9999/turbine.stream?cluster=DRUNCK

四、 测试:监控全部应用
1、 spring-cloud-turbine 的 application.properties 修改配置: 保留:

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

修改:

turbine.cluster-name-expression='default' 

禁用:

 # turbine.aggregator.clusterConfig=DRUNCK 

2、 在 http://localhost:8761/hystrix 加入:http://localhost:9999/turbine.stream

阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 汽车大灯里面起雾水怎么办 二级重伤对方法庭拒绝赔偿怎么办? 在麦当劳工作收到假钞怎么办 东西湖小学分配太远怎么办 农行k令过期了怎么办 穿军训的鞋捂坏了怎么办 联通手机号销户话费怎么办 建行员工所持有的原始股怎么办 孕妇喝了午时茶怎么办 苹果6id被锁了怎么办 苹果手机app密码忘了怎么办 好哥们借钱手上没钱怎么办 武汉ca证书u盾怎么办 判了刑发现还有漏案没判怎么办 高铁旅客漏乘怎么办 水库里面要养殖小龙虾最好怎么办 点读机的笔丢了怎么办 皮肤晒的很黑怎么办 电脑wifi连接受限制怎么办 高中孩子班管理松怎么办 脱式计算有余数怎么办 手机被别人绑定微信怎么办 饿了么入职查不到学历怎么办 高中没考上家人让打工怎么办 一建证书丢了怎么办 自考大专证书丢了怎么办 护士学分卡丢了怎么办 公司电脑只能用内网怎么办 遇见素质低的人怎么办 被素质低的人骂怎么办 对素质差的人怎么办 碰到素质低的人怎么办 和韩国人结婚后工作怎么办 大连明珠卡坏了怎么办 护肤品酒精含量太高怎么办 父母出国三年想孩子怎么办 孩子高考不理想想出国怎么办 交大附中创新班剩余孩子怎么办 棋牌开发公司倒闭了怎么办 7月1日本地流量怎么办 装电池的弹簧生锈了怎么办