Spring Cloud系列(二十) Turbine集群监控(Finchley.RC2版本)

通过Turbine可以汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控。

这里盗个图,当我们使用Turbine和Hystrix Dashboard整合时,系统架构是这样的:

Turbine集群监控

第一步,创建标准的Spring Boot过程,命名turbine-vFinchley.RC2,勾选如下依赖:

此时的pom文件

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

第二步:修改应用主类,添加@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

参数说明:

  1. turbine.app-config参数指定了需要收集监控信息的服务名;
  2. turbine.cluster-name-expression 参数指定了集群名称为 default,当我们服务数量非常多的时候,可以启动多个 Turbine 服务来构建不同的聚合集群,而该参数可以用来区分这些不同的聚合集群,同时该参数值可以在 Hystrix 仪表盘中用来定位不同的聚合集群,只需要在 Hystrix Stream 的 URL 中通过 cluster 参数来指定;
  3. turbine.combine-host-port参数设置为true,可以让同一主机上的服务通过主机名与端口号的组合来进行区分,默认情况下会以 host 来区分不同的服务,这会使得在本地调试的时候,本机上的不同服务聚合成一个服务来统计。

注意: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再来更新。。。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值