上一篇文章末尾我们已经实现了Hystrix Dashboard对单个服务实例的监控,在实际应用中,我们更需要的是一个集群系统的监控信息,这时我们就需要引入Turbine。Turbine能够汇集监控信息,并将聚合后的信息提供给Hystrix Dashboard来集中展示和监控。简单的说,就是Turbine是一个项目,把其他启用了Hystrix的项目信息配置进去启动起来,有一个访问地址还是复制上一篇文章末尾Hystrix Dashboard框框里面就可以监控所有的了。。。
demo下载地址:https://download.csdn.net/download/qq_22075041/10859685
我们先简单的来搭建一个简单应用,代码参考microservice-hystrix-turbine模块
先pom文件增弄进去:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
启动类上面来一个注解@EnableTurbine,在配置文件中这样加是对单个实例的监控
turbine:
aggregator:
clusterConfig: MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX #可以理解为别名的意思
appConfig: microservice-consumer-movie-ribbon-with-hystrix #这个是我们上一篇文章的一个应用项目
然后启动项目这样子访问ip:port/turbine.stream?cluster=MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX 就可以访问microservice-consumer-movie-ribbon-with-hystrix服务的监控了
=============================================================
turbine是为了监控多个啊,那多个该怎么配置呢?如下:
turbine:
aggregator:
clusterConfig: default
appConfig: microservice-consumer-movie-ribbon-with-hystrix,microservice-consumer-movie-feign-with-hystrix
clusterNameExpression: "'default'"
然后启动项目这样访问ip:port/turbine
====================================================================
假如我们的项目根路径不是/而是/ribbon,那我们怎么告诉eurake呢,这样写home-page-url-path: /ribbon,代码参考microservice-consumer-movie-ribbon-with-hystrix2模块
spring:
application:
name: microservice-consumer-movie-ribbon-with-hystrix2
server:
port: 8010
context-path: /ribbon
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance:
prefer-ip-address: true
home-page-url-path: /ribbon
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
这时候是不是也得告诉turbine呢,那么就要加一句(参考代码microservice-hystrix-turbine2模块):
# MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX2 是别名
turbine.instanceUrlSuffix.MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX2: /ribbon/hystrix.stream
====================================================================
那我就是不喜欢加home-page-url-path: /ribbon这一句呢,没关系,还可以这样玩(代码参考:microservice-consumer-movie-ribbon-with-hystrix3模块)
management: # spring-boot-starter-acturator
port: 8081 # 加了一个管理端口
spring:
application:
name: microservice-consumer-movie-ribbon-with-hystrix3
server:
port: 8010
context-path: /ribbon
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance:
prefer-ip-address: true
metadata-map: # 使用这个管理端口,并且去掉了home-page-url-path: /ribbon
management.port: 8081
然后在turbine项目中配置也去掉了MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX2的配置(代码参考microservice-hystrix-turbine3)
server:
port: 8031
spring:
application:
name: microservice-hystrix-turbine
eureka:
client:
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance:
prefer-ip-address: true
turbine:
aggregator:
clusterConfig: MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX3
appConfig: microservice-consumer-movie-ribbon-with-hystrix3
# turbine.instanceUrlSuffix.MICROSERVICE-CONSUMER-MOVIE-RIBBON-WITH-HYSTRIX2: /ribbon/hystrix.stream
logging:
level:
root: INFO
com.netflix.turbine.monitor: DEBUG