java springcloud版b2b2c社交電商spring cloud分佈式微服務(十三)斷路器聚合監控(Hystrix Turbine)

Spring cloud b2b2c電子商務社交平臺源碼請加企鵝求求:一零三八七七四六二六。講述瞭如何利用Hystrix Dashboard去監控斷路器的Hystrix command。當咱們有不少個服務的時候,這就須要聚合因此服務的Hystrix Dashboard的數據了。這就須要用到Spring Cloud的另外一個組件了,即Hystrix Turbine。web

1、Hystrix Turbine簡介

看單個的Hystrix Dashboard的數據並無什麼多大的價值,要想看這個系統的Hystrix Dashboard數據就須要用到Hystrix Turbine。Hystrix Turbine將每一個服務Hystrix Dashboard數據進行了整合。Hystrix Turbine的使用很是簡單,只須要引入相應的依賴和加上註解和配置就能夠了。spring

2、準備工做

本文使用的工程爲上一篇文章的工程,在此基礎上進行改造。由於咱們須要多個服務的Dashboard,因此須要再建一個服務,取名爲service-lucy,它的基本配置同service-hi,在這裏就不詳細說明。瀏覽器

3、建立service-turbine

引入相應的依賴:bash

<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註解,即開啓了註冊服務。app

@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列表,代表監控哪些服務
  clusterNameExpression: new String("default")
  # 1. clusterNameExpression指定集羣名稱,默認表達式appName;此時:turbine.aggregator.clusterConfig須要配置想要監控的應用名稱
  # 2. 當clusterNameExpression: default時,turbine.aggregator.clusterConfig能夠不寫,由於默認就是default
  # 3. 當clusterNameExpression: metadata['cluster']時,假設想要監控的應用配置了eureka.instance.metadata-map.cluster: ABC,則須要配置,同時turbine.aggregator.clusterConfig: ABC
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/複製代碼

配置文件註解寫的很清楚。spring-boot

4、Turbine演示

依次開啓eureka-server、service-hi、service-lucy、service-turbine工程。微服務

打開瀏覽器輸入:http://localhost:8769/turbine.stream,界面以下:ui

这里写图片描述

依次請求:spa

http://localhost:8762/hi?name=forezp
 
http://localhost:8763/hi?name=forezp複製代碼

須要JAVASpring Cloud大型企業分佈式微服務雲構建的B2B2C電子商務平臺源碼請加企鵝求求:一零三八七七四六二六

相關文章
相關標籤/搜索