Turbine概述
Turbine真正做的,就是将每一个(指定)服务的Hystrix/stream中的状态信息取出,并集中处理(计算与展示),应该说,它是具有自己独立的调度的,服务(实例)发现,服务连接,数据聚合,数据输出,共四个过程。
如上图: Turbine首先通过
InstanceDiscovery
模块获取所有的实例信息(定期更新获取),
ConnectionManager
负责连接到实例,连接上实例后,便会有源源不断的数据流发送给聚合器
Aggregator
之后,再传送给需要的地方。
使用Turbine聚合监控
在使用HystrixDashboard组件监控服务的熔断器状况时,每个服务都有一个HystrixDashboard主页,当服务数量很多时,监控非常不方便。为了同时监控多个服务的熔断器的状况,Netflix 开源了Hystrix 的另一个组件Turbine。Turbine 用于聚合多个Hystrix Dashboard,将多个Hystrix Dashboard组件的数据放在一个页面 上展示,进行集中监控。
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
配置:
spring:
application:
name: service-turbine
server:
port: 8769
turbine:
aggregator:
clusterConfig: default #指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig}访问
app-config: eureka-ribbon-client,eureka-feign-client #配置Eureka中的serveceId列表,表明监控哪些服务
cluster-name-expression: new String("default")
# 1. ClusterNameExpression:指定集群名称,默认表达式appName;此时trubine.aggregatro.clusterConfig需要配置想要监控的应用名称
# 2. 当ClusterNameExpression:default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
# 3. 当ClusterNameExpression:metadata['cluster']时,假设想要监控的应用配置了
# eureka.instance.metadata-map.cluster:ABC,则需要配置,同时turbine.aggregator.clusterConfig:ABC
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
- turbine.aggregator.clusterConfig配置了需要监控的服务名
- clusterNameExpression默认为服务名的集群,此时用默认的即可
- turbine.aggregator.clusterConfig默认就是default
示例:
turbine:
aggregator:
clusterConfig:CLOUD_SIMPLE_SERVICE
appConfig:cloud-simple-service
clusterNameExpression:metadata['cluster']
在hystrix dashboard的监控url中就应该输入:
http://localhost:port/turbine.stream?cluster=CLOUD-SIMPLE-SERVICE
cluster对应clusterConfig中的名称
开启turbine
@SpringBootApplication
@EnableTurbine//开启trubine
public class EurekaMonitorClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaMonitorClientApplication.class, args);
}
}
启动工程eureka-server、eureka-client、 eureka-ribbon-client 和eureka-monitor -client。
在浏览器上访问
http://localhost:8764hi?name-forezp和ht:/calhost:8765/hi?name=forezpo
在浏览器上打开网址htp://localhost:8765/hystrix,这个界面为Hystrix Dashboard界面。
在界面上依次输入监控流的Url地址
htp://localhost:8769/turbine.stream
、监控时间间隔2000毫秒和title,单击“monitor”,可以看到如图
这个页面聚合了eureka-ribbon-client和eureka-feign-client的Hystrix Dashboard数据。