javascript
史上最简单的SpringCloud教程 | 第十三篇: 断路器聚合监控(Hystrix Turbine)
轉(zhuǎn):https://blog.csdn.net/forezp/article/details/70233227
上一篇文章講述了如何利用Hystrix Dashboard去監(jiān)控斷路器的Hystrix command。當(dāng)我們有很多個服務(wù)的時候,這就需要聚合所以服務(wù)的Hystrix Dashboard的數(shù)據(jù)了。這就需要用到Spring Cloud的另一個組件了,即Hystrix Turbine。
一、Hystrix Turbine簡介
看單個的Hystrix Dashboard的數(shù)據(jù)并沒有什么多大的價值,要想看這個系統(tǒng)的Hystrix Dashboard數(shù)據(jù)就需要用到Hystrix Turbine。Hystrix Turbine將每個服務(wù)Hystrix Dashboard數(shù)據(jù)進行了整合。Hystrix Turbine的使用非常簡單,只需要引入相應(yīng)的依賴和加上注解和配置就可以了。
二、準(zhǔn)備工作
本文使用的工程為上一篇文章的工程,在此基礎(chǔ)上進行改造。因為我們需要多個服務(wù)的Dashboard,所以需要再建一個服務(wù),取名為service-lucy,它的基本配置同service-hi,具體見源碼(https://github.com/forezp/SpringCloudLearning/tree/master/chapter13),在這里就不詳細說明。
三、創(chuàng)建service-turbine
引入相應(yīng)的依賴:
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-turbine</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-netflix-turbine</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>在其入口類ServiceTurbineApplication加上注解@EnableTurbine,開啟turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即開啟了注冊服務(wù)。
@SpringBootApplication @EnableTurbine public class ServiceTurbineApplication {public static void main(String[] args) {new SpringApplicationBuilder(ServiceTurbineApplication.class).web(true).run(args);} }配置文件application.yml:
spring:application.name: service-turbine server:port: 8769 security.basic.enabled: false turbine:aggregator:clusterConfig: default # 指定聚合哪些集群,多個使用","分割,默認為default。可使用http://.../turbine.stream?cluster={clusterConfig之一}訪問appConfig: service-hi,service-lucy ### 配置Eureka中的serviceId列表,表明監(jiān)控哪些服務(wù)clusterNameExpression: new String("default")# 1. clusterNameExpression指定集群名稱,默認表達式appName;此時:turbine.aggregator.clusterConfig需要配置想要監(jiān)控的應(yīng)用名稱# 2. 當(dāng)clusterNameExpression: default時,turbine.aggregator.clusterConfig可以不寫,因為默認就是default# 3. 當(dāng)clusterNameExpression: metadata['cluster']時,假設(shè)想要監(jiān)控的應(yīng)用配置了eureka.instance.metadata-map.cluster: ABC,則需要配置,同時turbine.aggregator.clusterConfig: ABC eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/配置文件注解寫的很清楚。
四、Turbine演示
依次開啟eureka-server、service-hi、service-lucy、service-turbine工程。
打開瀏覽器輸入:http://localhost:8769/turbine.stream,界面如下:
依次請求:
http://localhost:8762/hi?name=forezphttp://localhost:8763/hi?name=forezp打開:http://localhost:8763/hystrix,輸入監(jiān)控流http://localhost:8769/turbine.stream
點擊monitor stream 進入頁面:
可以看到這個頁面聚合了2個service的hystrix dashbord數(shù)據(jù)。
源碼下載:
https://github.com/forezp/SpringCloudLearning/tree/master/chapter13
五、參考文獻
hystrix_dashboard : http://projects.spring.io/spring-cloud/spring-cloud.html#_circuit_breaker_hystrix_dashboard
turbine :http://projects.spring.io/spring-cloud/spring-cloud.html#_turbine
總結(jié)
以上是生活随笔為你收集整理的史上最简单的SpringCloud教程 | 第十三篇: 断路器聚合监控(Hystrix Turbine)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 史上最简单的SpringCloud教程
- 下一篇: 烤南瓜为什么都是水?