通过Turbine可以汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控。
这里盗个图,当我们使用Turbine和Hystrix Dashboard整合时,系统架构是这样的:
Turbine集群监控
第一步,创建标准的Spring Boot过程,命名turbine-vFinchley.RC2,勾选如下依赖:
此时的pom文件
org.springframework.cloud
spring-cloud-starter-netflix-turbine
第二步:修改应用主类,添加@EnableTurbine注解开启Turbine。
@EnableTurbine
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
第三步,在 application.yml 加入 Eureka 和 Turbine 的相关配置
#应用名称
spring:
application:
name: turbine #为服务命名
server:
port: 3336
management:
port: 8081
eureka:
client:
service-url:
defaultZone: http://localhost:1111/eureka/ #指定服务注册中心位置
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
turbine:
app-config: hystrix #多个逗号隔开
cluster-name-expression: new String("default")
combine-host-port: true
参数说明:
注意:new String("default")这个一定要用 String 来包一下,否则启动的时候会抛出异常:
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo' - maybe not public or not valid?
测试
启动项目依次为
eureka-server-vFinchley.Rc2
eureka-client-vFinchley.Rc2
hystrix-vFinchley.Rc2
hystrix-dashboard-vFinchley.RC2
turbine-vFinchley.RC2
先调用hystrix-vFinchley.Rc2的helloAPI打开Hystrix Dashboard首页,输入http://localhost:3336/turbine.stream
解释一下,我这里hystrix只启动了一个实例,如果你启动了两个(通过指定不同端口),会发现Hosts变成2,但是依然只有一个监控图,是由于两个实例是属于同一个服务的,而对于集群来说我们关注的是服务集群的高可用性,所以Turbine会将相同服务作为一个整体来看,并汇总成一个监控图。当然你如果就想分为两个监控图展示,可以为其设置一个新的spring.application.name,此时就会有两个监控图了。
这里就成功整合了Turbine集群监控。
关于Turbine整合消息代理,等到日后我学习了RabbitMQ再来更新。。。