Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.
我们在熔断示例项目spring-cloud-consumer-hystrix的基础上更改,重新命名为:spring-cloud-consumer-hystrix-dashboard。
这三个包必须添加
启动类添加启用Hystrix Dashboard和熔断器
图中会有一些提示:
大概意思就是如果查看默认集群使用第一个url,查看指定集群使用第二个url,单个应用的监控使用最后一个,我们暂时只演示单个应用的所以在输入框中输入:
如果没有请求会先显示<code>Loading ...</code>,访问http://localhost:9001/hystrix.stream 也会不断的显示ping。
请求服务http://localhost:9001/hello/neo,就可以看到监控的效果了,首先访问http://localhost:9001/hystrix.stream,显示如下:
说明已经返回了监控的各项结果
到监控页面就会显示如下图:
其实就是http://localhost:9001/hystrix.stream返回结果的图形化显示,Hystrix Dashboard Wiki上详细说明了图上每个指标的含义,如下图:
到此单个应用的熔断监控已经完成。
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。
<code>turbine.appConfig</code> :配置Eureka中的serviceId列表,表明监控哪些服务
<code>turbine.aggregator.clusterConfig</code> :指定聚合哪些集群,多个使用","分割,默认为default。可使用<code>http://.../turbine.stream?cluster={clusterConfig之一}</code>访问
<code>turbine.clusterNameExpression</code> : 1. clusterNameExpression指定集群名称,默认表达式appName;此时:<code>turbine.aggregator.clusterConfig</code>需要配置想要监控的应用名称;2. 当clusterNameExpression: default时,<code>turbine.aggregator.clusterConfig</code>可以不写,因为默认就是default;3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了<code>eureka.instance.metadata-map.cluster: ABC</code>,则需要配置,同时<code>turbine.aggregator.clusterConfig: ABC</code>
启动类添加<code>@EnableTurbine</code>,激活对Turbine的支持
到此Turbine(hystrix-dashboard-turbine)配置完成
在示例项目spring-cloud-consumer-hystrix基础上修改为两个服务的调用者spring-cloud-consumer-node1和spring-cloud-consumer-node2
spring-cloud-consumer-node1项目改动如下:
application.properties文件内容
spring-cloud-consumer-node2项目改动如下:
HelloRemote类修改:
对应的<code>HelloRemoteHystrix</code>和<code>ConsumerController</code>类跟随修改,具体查看代码
修改完毕后,依次启动spring-cloud-eureka、spring-cloud-consumer-node1、spring-cloud-consumer-node1、hystrix-dashboard-turbine(Turbine)
打开eureka后台可以看到注册了三个服务:
返回:
<a href="https://github.com/ityouknow/spring-cloud-starter">示例代码</a>
参考:
<a href="https://www.gitbook.com/book/eacdy/spring-cloud-book/details">使用Spring Cloud与Docker实战微服务</a>
http://www.cnblogs.com/ityouknow/p/6889059.html