6Hystrix Turbine · SpringCloud微服务实战 · 看云
6.Hystrix Turbine
导航
本节代码地址
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-feign
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-client/fw-cloud-client-eureka
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-dashboard
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-ribbon
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-turbine
6.1 Turbine是什么?
是Netflix提供了一个用来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示
从Hystrix Dashboard的监控首页中可以看出,集群的监控端点是http://turbine-hostname:port/turbine.stream,需要我们引入Trubine聚合服务,通过它来汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard,下面我们来看一下多个应用的监控。
6.2 新建项目
6.3 maven 配置
这里需要把spring-cloud-starter-netflix-turbine引入
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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>
</dependencies>
6.4 新建启动类
需要在启动类上添加 @EnableTurbine注解
@EnableTurbine
@EnableDiscoveryClient
@SpringBootApplication
public class FwTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(FwTurbineApplication.class, args);
}
}
6.5 应用配置
server:
port: 8678
spring:
application:
name: fw-hystrix-feign-dashboard
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
turbine:
app-config: fw-hystrix-ribbon, fw-hystrix-feign # 配置Eureka中的serviceId列表,表明监控哪些服务
aggregator:
cluster-config: default # 指定聚合哪些集群,多个使用","分割,默认为default。
cluster-name-expression: new String("default")
instanceUrlSuffix: actuator/hystrix.stream # turbine在收集时访问的后缀
cluster-name-expression的配置默认default
- clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称
- 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
- 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: cluster1,则需要配置,同时turbine.aggregator.clusterConfig: cluster1
6.6 启动项目
这里我们将fw-cloud-hystrix-ribbon、fw-cloud-hystrix-feign、fw-cloud-hystrix-dashboard都启动起来,用于测试
在dashboard中输入地址http://localhost:8678/turbine.stream
在Postman测试两个接口localhost:8676/feignInfo和localhost:8675/user/1
显示的结果如下,因为我们启动fw-cloud-ribbon-server项目,所以findUserById报了100%的错误,你也可以尝试启动fw-cloud-ribbon-server项目看看展示的效果。



