spring cloud构建互联网分布式微服务云平台-断路器聚合监控(Hystrix Turbine)
一、Hystrix Turbine簡介
看單個(gè)的Hystrix Dashboard的數(shù)據(jù)并沒有什么多大的價(jià)值,要想看這個(gè)系統(tǒng)的Hystrix Dashboard數(shù)據(jù)就需要用到Hystrix Turbine。Hystrix Turbine將每個(gè)服務(wù)Hystrix Dashboard數(shù)據(jù)進(jìn)行了整合。Hystrix Turbine的使用非常簡單,只需要引入相應(yīng)的依賴和加上注解和配置就可以了。愿意了解源碼的朋友直接求求交流分享技術(shù) 一七九一七四三三八零
二、準(zhǔn)備工作
本文使用的工程為上一篇文章的工程,在此基礎(chǔ)上進(jìn)行改造。因?yàn)槲覀冃枰鄠€(gè)服務(wù)的Dashboard,所以需要再建一個(gè)服務(wù),取名為service-lucy,它的基本配置同service-hi,具體見源碼,在這里就不詳細(xì)說明。
三、創(chuàng)建service-turbine
引入相應(yīng)的依賴:
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-turbine</artifactId></dependency></dependencies>復(fù)制代碼在其入口類ServiceTurbineApplication加上注解@EnableTurbine,開啟turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即開啟了注冊服務(wù)。
@SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient @RestController @EnableHystrix @EnableHystrixDashboard @EnableCircuitBreaker @EnableTurbine public class ServiceTurbineApplication {/*** http://localhost:8764/turbine.stream*/public static void main(String[] args) {SpringApplication.run( ServiceTurbineApplication.class, args );} }復(fù)制代碼配置文件application.yml:
spring:application.name: service-turbine server:port: 8769 security.basic.enabled: false turbine:aggregator:clusterConfig: default # 指定聚合哪些集群,多個(gè)使用","分割,默認(rèn)為default。可使用http://.../turbine.stream?cluster={clusterConfig之一}訪問appConfig: service-hi,service-la ### 配置Eureka中的serviceId列表,表明監(jiān)控哪些服務(wù)clusterNameExpression: new String("default")# 1. clusterNameExpression指定集群名稱,默認(rèn)表達(dá)式appName;此時(shí):turbine.aggregator.clusterConfig需要配置想要監(jiān)控的應(yīng)用名稱# 2. 當(dāng)clusterNameExpression: default時(shí),turbine.aggregator.clusterConfig可以不寫,因?yàn)槟J(rèn)就是default# 3. 當(dāng)clusterNameExpression: metadata['cluster']時(shí),假設(shè)想要監(jiān)控的應(yīng)用配置了eureka.instance.metadata-map.cluster: ABC,則需要配置,同時(shí)turbine.aggregator.clusterConfig: ABC eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/復(fù)制代碼配置文件注解寫的很清楚。
Turbine演示
依次開啟server、service-hi、service-la、service-turbine工程。 打開瀏覽器輸入:http://localhost:8769/turbine.stream,
依次請求:
http://localhost:8762/hi?name=whhttp://localhost:8763/hi?name=wh 復(fù)制代碼打開:http://localhost:8763/hystrix,輸入監(jiān)控流http://localhost:8769/turbine.stream
可以看到這個(gè)頁面聚合了2個(gè)service的hystrix dashbord數(shù)據(jù)。
與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的spring cloud构建互联网分布式微服务云平台-断路器聚合监控(Hystrix Turbine)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++入门课程系列:基础知识篇(1)
- 下一篇: Will it finally: 关于