最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Spring Cloud 斷路器集群監(jiān)控(Turbine)

 更新時間:2018年05月02日 09:49:07   作者:嵩園  
這篇文章主要介紹了詳解Spring Cloud 斷路器集群監(jiān)控(Turbine),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

一. 簡介

上一篇文章我們已經(jīng)實(shí)現(xiàn)了對單個服務(wù)實(shí)例的監(jiān)控,當(dāng)然在實(shí)際應(yīng)用中,單個實(shí)例的監(jiān)控數(shù)據(jù)沒有多大的價值,我們更需要的是一個集群系統(tǒng)的監(jiān)控信息,這時我們就需要引入Turbine。Turbine能夠匯集監(jiān)控信息,并將聚合后的信息提供給Hystrix Dashboard來集中展示和監(jiān)控。

二. 構(gòu)建監(jiān)控局和服務(wù)

2.1 整體結(jié)構(gòu)與準(zhǔn)備

本文的工程實(shí)現(xiàn)是基于上一篇文章的工程,通過引入Turbine來聚合service-ribbon服務(wù)的監(jiān)控信息,并輸出給Hystrix Dashboard來進(jìn)行展示。因為我們需要多個服務(wù)的Dashboard,所以我們將構(gòu)建service-ribbon集群,同時需要新建一個service-turbine工程,用于聚合信息并展示。最終整體架構(gòu)如下:


2.2 創(chuàng)建service-turbine

新建一個Spring Boot工程,命名為service-turbine,在pom.xml中導(dǎo)入必要的依賴:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  <modelVersion>4.0.0</modelVersion> 
 
  <groupId>com.dan</groupId> 
  <artifactId>service-turbine</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 
 
  <name>service-turbine</name> 
  <description>Demo project for Spring Boot</description> 
 
  <parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.9.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
  </parent> 
 
  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
    <spring-cloud.version>Edgware.SR1</spring-cloud.version> 
  </properties> 
 
  <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> 
 
  <dependencyManagement> 
    <dependencies> 
      <dependency> 
        <groupId>org.springframework.cloud</groupId> 
        <artifactId>spring-cloud-dependencies</artifactId> 
        <version>${spring-cloud.version}</version> 
        <type>pom</type> 
        <scope>import</scope> 
      </dependency> 
    </dependencies> 
  </dependencyManagement> 
 
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
    </plugins> 
  </build> 
</project> 

在工程啟動類上加上@EnableTurbine注解,開啟Turbine,該注解已經(jīng)包含了@EnableDiscoveryClient注解,即已開啟了注冊服務(wù):

@SpringBootApplication 
@EnableTurbine 
public class ServiceTurbineApplication { 
 
  public static void main(String[] args) { 
    SpringApplication.run(ServiceTurbineApplication.class, args); 
  } 
} 

在application.properties中加入Eureka和Turbine的相關(guān)配置,具體如下:

spring.application.name=service-turbine 
server.port=8766 
security.basic.enabled=false 
 
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka 
 
turbine.aggregator.cluster-config=default 
turbine.app-config=service-ribbon 
turbine.cluster-name-expression="default" 
turbine.combine-host-port=true 

上面的配置中,turbine.app-config參數(shù)配置Eureka中的serviceId列表,表明監(jiān)控哪些服務(wù);turbine.cluster-name-expression參數(shù)指定了集群名稱為default,當(dāng)服務(wù)數(shù)量非常多的時候,可以啟動多個Turbine服務(wù)來構(gòu)建不同的聚合集群,而該參數(shù)可以用來區(qū)分這些不同的聚合集群,同時該參數(shù)值可以再Hystrix儀表盤中用來定位不同的聚合集群,只需在Hystrix Stream的URL中通過cluster參數(shù)來指定;turbine.combine-host-port參數(shù)設(shè)置為true,可以讓同一主機(jī)上的服務(wù)通過主機(jī)名與端口號的組合來進(jìn)行區(qū)分,默認(rèn)情況下會以host來區(qū)分不同的服務(wù),這會使得在本機(jī)調(diào)試的時候,本機(jī)上的不同服務(wù)聚合成一個服務(wù)來統(tǒng)計。

三. 集群監(jiān)控

啟動eureka-server工程,端口號為8761;

啟動eureka-client工程,端口號為8762和8763;

啟動service-ribbon工程,端口號為8764和8765;

啟動service-turbine工程,端口號為8766。

訪問http://localhost:8766/turbine.stream看到:


     

訪問http://localhost:8765/hystrix,輸入監(jiān)控流http://localhost:8766/turbine.stream看到:


在圖中可以看到,雖然我們啟動了兩個service-ribbon,但是監(jiān)控頁面中依然只是展示了一個監(jiān)控圖。不過我們可以發(fā)現(xiàn),圖中集群報告區(qū)域中的Hosts屬性與之前嘗試單機(jī)監(jiān)控時已有不同,只是因為這兩個實(shí)例是同一個服務(wù),而對于集群來說我們關(guān)注的是服務(wù)集群的高可用性,所以Turbine會將相同服務(wù)作為整體來看待,并匯總成一個監(jiān)控圖。

當(dāng)然啦,如果你真想看到兩個監(jiān)控圖,可以把service-ribbon其中的一個實(shí)例的spring.application.name設(shè)置成別的名稱,這樣運(yùn)行起來后就會出現(xiàn)兩個不同的監(jiān)控圖。

四. 與消息代理結(jié)合

Spring Cloud在封裝Turbine的時候,還封裝了基于消息代理的收集實(shí)現(xiàn)。所以,我們可以將所有需要收集的監(jiān)控信息都輸出到消息代理中,然后Turbine服務(wù)再從消息代理中異步獲取這些監(jiān)控信息,最后將這些監(jiān)控信息聚合并輸出到Hystrix Dashboard中。通過引入消息代理,我們的Turbine和Hystrix Dashboard實(shí)現(xiàn)的監(jiān)控架構(gòu)可以改成如下圖所示的結(jié)構(gòu):


首先新建一個Spring Boot工程,命名為service-turbine-amqp,引入spring-cloud-starter-turbine-amqp和spring-boot-starter-actuator依賴。看到這里只是引入這兩個依賴,因為spring-cloud-starter-turbine-amqp實(shí)際上包裝了spring-cloud-starter-turbine-stream和spring-cloud-starter-stream-rabbit。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  <modelVersion>4.0.0</modelVersion> 
 
  <groupId>com.dan</groupId> 
  <artifactId>service-turbine-amqp</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 
 
  <name>service-turbine-amqp</name> 
  <description>Demo project for Spring Boot</description> 
 
  <parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.9.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
  </parent> 
 
  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
    <spring-cloud.version>Edgware.SR1</spring-cloud.version> 
  </properties> 
 
  <dependencies> 
    <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-turbine-amqp</artifactId> 
    </dependency> 
 
    <dependency>       <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
      <scope>test</scope> 
    </dependency> 
  </dependencies> 
 
  <dependencyManagement> 
    <dependencies> 
      <dependency> 
        <groupId>org.springframework.cloud</groupId> 
        <artifactId>spring-cloud-dependencies</artifactId> 
        <version>${spring-cloud.version}</version> 
        <type>pom</type> 
        <scope>import</scope> 
      </dependency> 
    </dependencies> 
  </dependencyManagement> 
 
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
    </plugins> 
  </build> 
</project> 

在主類中使用@EnableTurbineStream注解來啟用Turbine Stream的配置:

@SpringBootApplication 
@EnableTurbineStream 
@EnableDiscoveryClient 
public class ServiceTurbineAmqpApplication { 
 
  public static void main(String[] args) { 
    SpringApplication.run(ServiceTurbineAmqpApplication.class, args); 
  } 
} 

接著配置application.properties文件:

spring.application.name=service-turbine-amqp 
server.port=8766 
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka 

對于Turbine的配置已經(jīng)完成了,下面需要對service-ribbon做一些修改,使其監(jiān)控信息能夠輸出到RabbitMQ上。這個修改也非常簡單,只需在pom.xml中增加對spring-cloud-netflix-hystrix-amqp的依賴,具體如下:

<dependency> 
  <groupId>org.springframework.cloud</groupId> 
  <artifactId>spring-cloud-netflix-hystrix-amqp</artifactId> 
</dependency> 

完成上面的配置后,同樣啟動所有需要的工程,同樣訪問http://localhost:8765/hystrix,輸入監(jiān)控流http://localhost:8766/turbine.stream,我們可以看到跟之前同樣的結(jié)果,只是這里的監(jiān)控信息收集是通過消息代理異步實(shí)現(xiàn)的。

源碼下載:https://github.com/lingd3/SpringCloudLearning/tree/master/chapter8

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot 如何讀取pom.xml中的值

    SpringBoot 如何讀取pom.xml中的值

    這篇文章主要介紹了SpringBoot 如何讀取pom.xml中的值,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • 解析WeakHashMap與HashMap的區(qū)別詳解

    解析WeakHashMap與HashMap的區(qū)別詳解

    本篇文章是對WeakHashMap與HashMap的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • 使用spring boot 整合kafka,延遲啟動消費(fèi)者

    使用spring boot 整合kafka,延遲啟動消費(fèi)者

    這篇文章主要介紹了使用spring boot 整合kafka,延遲啟動消費(fèi)者的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • 詳解Java中static關(guān)鍵字和內(nèi)部類的使用

    詳解Java中static關(guān)鍵字和內(nèi)部類的使用

    這篇文章主要為大家詳細(xì)介紹了Java中static關(guān)鍵字和內(nèi)部類的使用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-08-08
  • Java static方法用法實(shí)戰(zhàn)案例總結(jié)

    Java static方法用法實(shí)戰(zhàn)案例總結(jié)

    這篇文章主要介紹了Java static方法用法,結(jié)合具體案例形式總結(jié)分析了java static方法功能、使用方法及相關(guān)操作注意事項,需要的朋友可以參考下
    2019-09-09
  • SpringBoot中調(diào)用通用URL的實(shí)現(xiàn)

    SpringBoot中調(diào)用通用URL的實(shí)現(xiàn)

    在 Spring Boot 應(yīng)用程序中,有時候我們需要調(diào)用一些通用的 URL 接口,本文主要介紹了SpringBoot中調(diào)用通用URL的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • spring-redis-session 自定義 key 和過期時間

    spring-redis-session 自定義 key 和過期時間

    這篇文章主要介紹了spring-redis-session 自定義 key 和過期時間,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Java Predicate接口定義詳解

    Java Predicate接口定義詳解

    Predicate是Java中的一個函數(shù)式接口,它代表一個判斷邏輯,接收一個輸入?yún)?shù),返回一個布爾值,這篇文章主要介紹了Java Predicate接口的定義及示例代碼,需要的朋友可以參考下
    2025-04-04
  • java ArrayList中的remove方法介紹

    java ArrayList中的remove方法介紹

    大家好,本篇文章主要講的是java ArrayList中的remove方法介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01
  • springboot 通過代碼自動生成pid的方法

    springboot 通過代碼自動生成pid的方法

    這篇文章主要介紹了springboot 通過代碼自動生成pid的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07

最新評論

兰西县| 灵璧县| 河曲县| 蓝山县| 大悟县| 大同县| 萨嘎县| 六安市| 丹巴县| 镇沅| 丽江市| 东明县| 堆龙德庆县| 灯塔市| 赤水市| 革吉县| 台中县| 磴口县| 伊金霍洛旗| 泌阳县| 新津县| 称多县| 乌海市| 长海县| 迁安市| 民丰县| 永德县| 龙海市| 霍林郭勒市| 常山县| 巴马| 张家界市| 鄂托克旗| 花莲市| 平果县| 禹城市| 松桃| 罗田县| 澎湖县| 定南县| 中阳县|