久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

7,、Spring Cloud Hystrix

 路人甲Java 2021-06-19

1.Spring Cloud Hystrix簡(jiǎn)介

(1).分布式問題

  復(fù)雜分布式體系結(jié)構(gòu)中的應(yīng)用程序有數(shù)十個(gè)依賴關(guān)系,每個(gè)依賴關(guān)系在某些時(shí)候?qū)⒉豢杀苊獾厥 ?/span>

 

  多個(gè)微服務(wù)之間調(diào)用的時(shí)候,,假設(shè)微服務(wù)A調(diào)用微服務(wù)B和微服務(wù)C,,微服務(wù)B和微服務(wù)C又調(diào)用其它的微服務(wù),這就是所謂的“扇出”,。如果扇出的鏈路上某個(gè)微服務(wù)的調(diào)用響應(yīng)時(shí)間過長(zhǎng)或者不可用,,對(duì)微服務(wù)A的調(diào)用就會(huì)占用越來越多的系統(tǒng)資源,進(jìn)而引起系統(tǒng)崩潰,,所謂的“雪崩效應(yīng)”.

  對(duì)于高流量的應(yīng)用來說,,單一的后端依賴可能會(huì)導(dǎo)致所有服務(wù)器上的所有資源都在幾秒鐘內(nèi)飽和。比失敗更糟糕的是,,這些應(yīng)用程序還可能導(dǎo)致服務(wù)之間的延遲增加,,備份隊(duì)列,線程和其他系統(tǒng)資源緊張,導(dǎo)致整個(gè)系統(tǒng)發(fā)生更多的級(jí)聯(lián)故障,。這些都表示需要對(duì)故障和延遲進(jìn)行隔離和管理,,以便單個(gè)依賴關(guān)系的失敗,不能取消整個(gè)應(yīng)用程序或系統(tǒng),。

  備注:一般情況對(duì)于服務(wù)依賴的保護(hù)主要有3中解決方案:

①.熔斷模式:這種模式主要是參考電路熔斷,,如果一條線路電壓過高,保險(xiǎn)絲會(huì)熔斷,,防止火災(zāi),。放到我們的系統(tǒng)中,,如果某個(gè)目標(biāo)服務(wù)調(diào)用慢或者有大量超時(shí),,此時(shí),熔斷該服務(wù)的調(diào)用,,對(duì)于后續(xù)調(diào)用請(qǐng)求,,不在繼續(xù)調(diào)用目標(biāo)服務(wù),直接返回,,快速釋放資源,。如果目標(biāo)服務(wù)情況好轉(zhuǎn)則恢復(fù)調(diào)用。

②.隔離模式:這種模式就像對(duì)系統(tǒng)請(qǐng)求按類型劃分成一個(gè)個(gè)小島的一樣,,當(dāng)某個(gè)小島被火少光了,,不會(huì)影響到其他的小島。例如可以對(duì)不同類型的請(qǐng)求使用線程池來資源隔離,,每種類型的請(qǐng)求互不影響,,如果一種類型的請(qǐng)求線程資源耗盡,則對(duì)后續(xù)的該類型請(qǐng)求直接返回,,不再調(diào)用后續(xù)資源,。這種模式使用場(chǎng)景非常多,例如將一個(gè)服務(wù)拆開,,對(duì)于重要的服務(wù)使用單獨(dú)服務(wù)器來部署,,再或者公司最近推廣的多中心。

③.限流模式:上述的熔斷模式和隔離模式都屬于出錯(cuò)后的容錯(cuò)處理機(jī)制,,而限流模式則可以稱為預(yù)防模式,。限流模式主要是提前對(duì)各個(gè)類型的請(qǐng)求設(shè)置最高的QPS閾值,若高于設(shè)置的閾值則對(duì)該請(qǐng)求直接返回,,不再調(diào)用后續(xù)資源,。這種模式不能解決服務(wù)依賴的問題,只能解決系統(tǒng)整體資源分配問題,,因?yàn)闆]有被限流的請(qǐng)求依然有可能造成雪崩效應(yīng),。

(2).Hystrix斷路器

  Hystrix是一個(gè)用于處理分布式系統(tǒng)的延遲和容錯(cuò)的開源庫,在分布式系統(tǒng)里,許多依賴不可避免的會(huì)調(diào)用失敗,,比如超時(shí),、異常等,Hystrix能夠保證在一個(gè)依賴出問題的情況下,,不會(huì)導(dǎo)致整體服務(wù)失敗,,避免級(jí)聯(lián)故障,以提高分布式系統(tǒng)的彈性,。

  斷路器:本身是一種開關(guān)裝置,,當(dāng)某個(gè)服務(wù)單元發(fā)生故障之后,通過斷路器的故障監(jiān)控(類似熔斷保險(xiǎn)絲),向調(diào)用方返回一個(gè)符合預(yù)期的,、可處理的備選響應(yīng)(FallBack),而不是長(zhǎng)時(shí)間的等待或者拋出調(diào)用方無法處理的異常,,這樣就保證了服務(wù)調(diào)用方的線程不會(huì)被長(zhǎng)時(shí)間、不必要地占用,,從而避免了故障在分布式系統(tǒng)中的蔓延,,乃至雪崩。

(3).Hystrix作用

[1].服務(wù)降級(jí)

  Hystrix服務(wù)降級(jí),,其實(shí)就是線程池中單個(gè)線程障處理,,防止單個(gè)線程請(qǐng)求時(shí)間太長(zhǎng),導(dǎo)致資源長(zhǎng)期被占有而得不到釋放,,從而導(dǎo)致線程池被快速占用完,,導(dǎo)致服務(wù)崩潰。

  Hystrix能解決如下問題:

①.請(qǐng)求超時(shí)降級(jí),,線程資源不足降級(jí),,降級(jí)之后可以返回自定義數(shù)據(jù)

②.線程池隔離降級(jí),分布式服務(wù)可以針對(duì)不同的服務(wù)使用不同的線程池,,從而互不影響

③.自動(dòng)觸發(fā)降級(jí)與恢復(fù)

④.實(shí)現(xiàn)請(qǐng)求緩存和請(qǐng)求合并

[2].服務(wù)熔斷

  熔斷模式:這種模式主要是參考電路熔斷,,如果一條線路電壓過高,保險(xiǎn)絲會(huì)熔斷,,防止火災(zāi),。放到我們的系統(tǒng)中,如果某個(gè)目標(biāo)服務(wù)調(diào)用慢或者有大量超時(shí),,此時(shí),,熔斷該服務(wù)的調(diào)用,對(duì)于后續(xù)調(diào)用請(qǐng)求,,不在繼續(xù)調(diào)用目標(biāo)服務(wù),,直接返回,快速釋放資源,。如果目標(biāo)服務(wù)情況好轉(zhuǎn)則恢復(fù)調(diào)用,。

[3].服務(wù)限流

  限流模式主要是提前對(duì)各個(gè)類型的請(qǐng)求設(shè)置最高的QPS閾值,,若高于設(shè)置的閾值則對(duì)該請(qǐng)求直接返回,不再調(diào)用后續(xù)資源,。這種模式不能解決服務(wù)依賴的問題,,只能解決系統(tǒng)整體資源分配問題,因?yàn)闆]有被限流的請(qǐng)求依然有可能造成雪崩效應(yīng),。

[4].接近實(shí)時(shí)的監(jiān)控

(4).官方文檔

  https://github.com/Netflix/Hystrix/wiki/How-To-Use

2.服務(wù)熔斷

 

  熔斷機(jī)制是應(yīng)對(duì)雪崩效應(yīng)的一種微服務(wù)鏈路保護(hù)機(jī)制,。當(dāng)扇出鏈路的某個(gè)微服務(wù)不可用或者響應(yīng)時(shí)間太長(zhǎng)時(shí),會(huì)進(jìn)行服務(wù)的降級(jí),,進(jìn)而熔斷該節(jié)點(diǎn)微服務(wù)的調(diào)用,,快速返回"錯(cuò)誤"的響應(yīng)信息。當(dāng)檢測(cè)到該節(jié)點(diǎn)微服務(wù)調(diào)用響應(yīng)正常后恢復(fù)調(diào)用鏈路,。在SpringCloud框架里熔斷機(jī)制通過Hystrix實(shí)現(xiàn),。Hystrix會(huì)監(jiān)控微服務(wù)間調(diào)用的狀況,當(dāng)失敗的調(diào)用到一定閾值,,缺省是5秒內(nèi)20次調(diào)用失敗就會(huì)啟動(dòng)熔斷機(jī)制,。熔斷機(jī)制的注解是@HystrixCommand,。

(1).創(chuàng)建工程

  新建microservicecloud-provider-dept-hystrix-8001

 

 

  將microservicecloud-provider-dept-8001下的package和applicaiton.yml配置文件復(fù)制到microservicecloud-provider-dept-hystrix-8001上,。

 

(2).配置pom文件

  修改部分:

<!--  hystrix -->

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix</artifactId>

</dependency>

  完整部分:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven./POM/4.0.0"

         xmlns:xsi="http://www./2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./xsd/maven-4.0.0.xsd">

    <parent>

        <artifactId>microservicecloud</artifactId>

        <groupId>com.hosystem</groupId>

        <version>1.0-SNAPSHOT</version>

    </parent>

    <modelVersion>4.0.0</modelVersion>

 

    <artifactId>microservicecloud-provider-dept-hystrix-8001</artifactId>

    <dependencies>

        <!-- 引入自己定義的api通用包,可以使用Dept部門Entity -->

        <dependency>

            <groupId>com.hosystem</groupId>

            <artifactId>microservicecloud-api</artifactId>

            <version>${project.version}</version>

        </dependency>

        <!-- 將微服務(wù)provider側(cè)注冊(cè)進(jìn)eureka -->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-eureka</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-config</artifactId>

        </dependency>

        <!-- actuator監(jiān)控信息完善 -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-actuator</artifactId>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

        </dependency>

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

        </dependency>

        <dependency>

            <groupId>com.alibaba</groupId>

            <artifactId>druid</artifactId>

        </dependency>

        <dependency>

            <groupId>ch.qos.logback</groupId>

            <artifactId>logback-core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mybatis.spring.boot</groupId>

            <artifactId>mybatis-spring-boot-starter</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-jetty</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-test</artifactId>

        </dependency>

        <!-- 修改后立即生效,,熱部署 -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>springloaded</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-devtools</artifactId>

        </dependency>

        <!--  hystrix -->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-hystrix</artifactId>

        </dependency>

    </dependencies>

 

</project>

(3).修改applicaiton.yml

server:

  port: 8001

 

mybatis:

  config-location: classpath:mybatis/mybatis.cfg.xml        # mybatis配置文件所在路徑

  type-aliases-package: com.hosytem.springcloud.entities    # 所有Entity別名類所在包

  mapper-locations:

  - classpath:mybatis/mapper/**/*.xml                       # mapper映射文件

 

#name spring.application.name=microservicecloud-dept   很重要很重要很重要

spring:

   application:

    name: microservicecloud-dept

   datasource:

    type: com.alibaba.druid.pool.DruidDataSource            # 當(dāng)前數(shù)據(jù)源操作類型

    driver-class-name: org.gjt.mm.mysql.Driver              # mysql驅(qū)動(dòng)包

    url: jdbc:mysql://192.168.188.188:3306/cloudDB01              # 數(shù)據(jù)庫名稱

    username: root

    password: 123456

    dbcp2:

      min-idle: 5                                           # 數(shù)據(jù)庫連接池的最小維持連接數(shù)

      initial-size: 5                                       # 初始化連接數(shù)

      max-total: 5                                          # 最大連接數(shù)

      max-wait-millis: 200                                  # 等待連接獲取的最大超時(shí)時(shí)間

 

eureka:

  client: #客戶端注冊(cè)進(jìn)eureka服務(wù)列表內(nèi)

    service-url:

#      defaultZone: http://localhost:7001/eureka

      defaultZone: http://:7001/eureka/,http://:7002/eureka/,http://:7003/eureka/

  instance:

    instance-id: microservicecloud-dept8001-hystrix   #自定義服務(wù)名稱信息

    prefer-ip-address: true     #訪問路徑可以顯示IP地址

info:

  app.name: hosystem-microservicecloud

  company.name: www.hosystem.com

  build.artifactId: $project.artifactId$

  build.version: $project.version$

(4).修改DeptController

 

package com.hosystem.springcloud.controller;

 

import com.hosystem.springcloud.entities.Dept;

import com.hosystem.springcloud.service.DeptService;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.cloud.client.ServiceInstance;

import org.springframework.cloud.client.discovery.DiscoveryClient;

import org.springframework.web.bind.annotation.*;

 

import java.util.List;

 

 

@RestController

public class DeptController

{

 

    @Autowired

    private DeptService service = null;

 

    @RequestMapping(value="/dept/get/{id}",method=RequestMethod.GET)

    //一旦調(diào)用服務(wù)方法失敗并拋出了錯(cuò)誤信息后,,會(huì)自動(dòng)調(diào)用@HystrixCommand標(biāo)注好的fallbackMethod調(diào)用類中的指定方法

    @HystrixCommand(fallbackMethod = "processHystrix_Get")

    public Dept get(@PathVariable("id") Long id)

    {

        Dept dept =  this.service.get(id);

        if(null == dept)

        {

            throw new RuntimeException("該ID:"+id+"沒有沒有對(duì)應(yīng)的信息");

        }

        return dept;

    }

 

    public Dept processHystrix_Get(@PathVariable("id") Long id)

    {

        return new Dept().setDeptno(id)

                .setDname("該ID:"+id+"沒有沒有對(duì)應(yīng)的信息,null--@HystrixCommand")

                .setDb_source("no this database in MySQL");

    }

}

(5).修改主啟動(dòng)類

  修改DeptProvider8001_App主啟動(dòng)類。

package com.hosystem.springcloud;

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

 

@SpringBootApplication

@EnableEurekaClient //本服務(wù)啟動(dòng)后會(huì)自動(dòng)注冊(cè)進(jìn)eureka服務(wù)中

@EnableDiscoveryClient

@EnableCircuitBreaker//對(duì)hystrixR熔斷機(jī)制的支持

public class DeptProvider8001_Hystrix_App

{

    public static void main(String[] args)

    {

        SpringApplication.run(DeptProvider8001_Hystrix_App.class, args);

    }

}

(6).測(cè)試

[1].啟動(dòng)eureka7001,、eureka7002,、eureka7003

[2].啟動(dòng)DeptProvider8001_Hystrix_App

[3].啟動(dòng)microservicecloud-consumer-dept-80

 

 

[4].訪問

http://localhost/consumer/dept/get/112

 

3.服務(wù)降級(jí)

 

  整體資源不足于應(yīng)對(duì)當(dāng)前的困難,則選擇性關(guān)掉某些服務(wù),,優(yōu)先提供重要的服務(wù),。

  服務(wù)降級(jí)處理是在客戶端實(shí)現(xiàn)完成的,與服務(wù)端沒有關(guān)系,。

(1).修改microservicecloud-api

  修改microservicecloud-api工程,,根據(jù)已經(jīng)有的DeptClientService接口新建一個(gè)實(shí)現(xiàn)了FallbackFactory接口的類DeptClientServiceFallbackFactor。

 

package com.hosystem.springcloud.service;

 

import com.hosystem.springcloud.entities.Dept;

import feign.hystrix.FallbackFactory;

import org.springframework.stereotype.Component;

 

import java.util.List;

 

@Component//不要忘記添加,,不要忘記添加

public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService>

{

    @Override

    public DeptClientService create(Throwable throwable)

    {

        return new DeptClientService() {

            @Override

            public Dept get(long id)

            {

                return new Dept().setDeptno(id)

                        .setDname("該ID:"+id+"沒有沒有對(duì)應(yīng)的信息,Consumer客戶端提供的降級(jí)信息,此刻服務(wù)Provider已經(jīng)關(guān)閉")

                        .setDb_source("no this database in MySQL");

            }

            @Override

            public List<Dept> list()

            {

                return null;

            }

            @Override

            public boolean add(Dept dept)

            {

                return false;

            }

        };

    }

}

(2).修改DeptClientService接口

  修改microservicecloud-api工程,,DeptClientService接口在注解@FeignClient中添加fallbackFactory屬性值。

 

package com.hosystem.springcloud.service;

 

import com.hosystem.springcloud.entities.Dept;

import org.springframework.cloud.netflix.feign.FeignClient;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

import java.util.List;

 

//@FeignClient(value = "MICROSERVICECLOUD-DEPT")

@FeignClient(value = "MICROSERVICECLOUD-DEPT",fallbackFactory=DeptClientServiceFallbackFactory.class)

public interface DeptClientService

{

    @RequestMapping(value = "/dept/get/{id}",method = RequestMethod.GET)

    public Dept get(@PathVariable("id") long id);

 

    @RequestMapping(value = "/dept/list",method = RequestMethod.GET)

    public List<Dept> list();

 

    @RequestMapping(value = "/dept/add",method = RequestMethod.POST)

    public boolean add(Dept dept);

}

(3).mvn clean和mvn install

  對(duì)microservicecloud-api工程進(jìn)行mvn clean install

 

(4).修改microservicecloud-consumer-dept-feign

  microservicecloud-consumer-dept-feign工程修改YML

server:

  port: 80

feign:

  hystrix:

    enabled: true

eureka:

  client:

    register-with-eureka: false

    service-url:

      defaultZone: http://:7001/eureka/,http://:7002/eureka/,http://:7003/eureka/

(5).測(cè)試

[1].啟動(dòng)eureka7001,、eureka7002,、eureka7003

[2].啟動(dòng)microservicecloud-provider-dept-8001

 

[3].啟動(dòng)microservicecloud-consumer-dept-feign

 

[4].訪問測(cè)試

①.正常測(cè)試

http://localhost/consumer/dept/get/1

 

②.關(guān)閉服務(wù)測(cè)試

  關(guān)閉微服務(wù)microservicecloud-provider-dept-8001。

http://localhost/consumer/dept/get/1

 

  此時(shí)服務(wù)端provider已經(jīng)down了,,但是我們做了服務(wù)降級(jí)處理,,讓客戶端在服務(wù)端不可用時(shí)也會(huì)獲得提示信息而不會(huì)掛起耗死服務(wù)器,。

4.服務(wù)監(jiān)控hystrixDashboard

 

  除了隔離依賴服務(wù)的調(diào)用以外,Hystrix還提供了準(zhǔn)實(shí)時(shí)的調(diào)用監(jiān)控(Hystrix Dashboard),,Hystrix會(huì)持續(xù)地記錄所有通過Hystrix發(fā)起的請(qǐng)求的執(zhí)行信息,,并以統(tǒng)計(jì)報(bào)表和圖形的形式展示給用戶,包括每秒執(zhí)行多少請(qǐng)求多少成功,,多少失敗等,。Netflix通過hystrix-metrics-event-stream項(xiàng)目實(shí)現(xiàn)了對(duì)以上指標(biāo)的監(jiān)控。Spring Cloud也提供了Hystrix Dashboard的整合,,對(duì)監(jiān)控內(nèi)容轉(zhuǎn)化成可視化界面,。

(1).新建工程

  新建工程microservicecloud-consumer-hystrix-dashboard

 

 

(2).修改pom

  修改部分:

   <!-- hystrix和 hystrix-dashboard相關(guān)-->

   <dependency>

       <groupId>org.springframework.cloud</groupId>

       <artifactId>spring-cloud-starter-hystrix</artifactId>

   </dependency>

   <dependency>

       <groupId>org.springframework.cloud</groupId>

       <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

   </dependency>

  完整部分:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven./POM/4.0.0"

         xmlns:xsi="http://www./2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./xsd/maven-4.0.0.xsd">

    <parent>

        <artifactId>microservicecloud</artifactId>

        <groupId>com.hosystem</groupId>

        <version>1.0-SNAPSHOT</version>

    </parent>

    <modelVersion>4.0.0</modelVersion>

 

    <artifactId>microservicecloud-consumer-hystrix-dashboard</artifactId>

    <dependencies>

        <!-- 自己定義的api -->

        <dependency>

            <groupId>com.hosystem</groupId>

            <artifactId>microservicecloud-api</artifactId>

            <version>${project.version}</version>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        

        <!-- 修改后立即生效,熱部署 -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>springloaded</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-devtools</artifactId>

        </dependency>

 

        <!-- Ribbon相關(guān) -->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-eureka</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-ribbon</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-config</artifactId>

        </dependency>

 

        <!-- feign相關(guān) -->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-feign</artifactId>

        </dependency>

 

        <!-- hystrix和 hystrix-dashboard相關(guān)-->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-hystrix</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

        </dependency>

    </dependencies>

</project>

(3).配置applicaiton.yml

server:

  port: 9001

(4).配置主啟動(dòng)類

  新建主啟動(dòng)類DeptConsumer_DashBoard_App,,然后添加注解@EnableHystrixDashboard.

package com.hosystem.springcloud;

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

 

@SpringBootApplication

@EnableHystrixDashboard

public class DeptConsumer_DashBoard_App

{

    public static void main(String[] args)

    {

        SpringApplication.run(DeptConsumer_DashBoard_App.class,args);

    }

}

(5).配置provider監(jiān)控依賴

  所有Provider微服務(wù)提供類(8001/8002/8003)都需要監(jiān)控依賴配置.

   <!-- actuator監(jiān)控信息完善 -->

   <dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-actuator</artifactId>

   </dependency>

(6).啟動(dòng)項(xiàng)目

[1].啟動(dòng)dashboard

  啟動(dòng)microservicecloud-consumer-hystrix-dashboard該微服務(wù)監(jiān)控消費(fèi)端,。

http://localhost:9001/hystrix

 

[2].啟動(dòng)eureka

  啟動(dòng)eureka7001、eureka7002,、eureka7003

 

[3].啟動(dòng)hystrix

  啟動(dòng)microservicecloud-provider-dept-hystrix-8001

 

http://localhost:8001/dept/get/1

http://localhost:8001/hystrix.stream

  

(7).監(jiān)控測(cè)試

  多次刷新http://localhost:8001/dept/get/1,,然后通過Hystrix Dashboard查看。

[1].填寫監(jiān)控地址

http://localhost:8001/hystrix.stream

 

  Delay:該參數(shù)用來控制服務(wù)器上輪詢監(jiān)控信息的延遲時(shí)間,,默認(rèn)為2000毫秒,,可以通過配置該屬性來降低客戶端的網(wǎng)絡(luò)和CPU消耗。

  Title:該參數(shù)對(duì)應(yīng)了頭部標(biāo)題Hystrix Stream之后的內(nèi)容,,默認(rèn)會(huì)使用具體監(jiān)控實(shí)例的URL,,可以通過配置該信息來展示更合適的標(biāo)題。

[2].監(jiān)控結(jié)果

  7色,、1圈,、1線

 

  實(shí)心圓:共有兩種含義。它通過顏色的變化代表了實(shí)例的健康程度,,它的健康度從綠色<黃色<橙色<紅色遞減,。該實(shí)心圓除了顏色的變化之外,它的大小也會(huì)根據(jù)實(shí)例的請(qǐng)求流量發(fā)生變化,,流量越大該實(shí)心圓就越大,。所以通過該實(shí)心圓的展示,就可以在大量的實(shí)例中快速的發(fā)現(xiàn)故障實(shí)例和高壓力實(shí)例

  曲線:用來記錄2分鐘內(nèi)流量的相對(duì)變化,,可以通過它來觀察到流量的上升和下降趨勢(shì),。

 

[3].復(fù)雜監(jiān)控結(jié)果

 

 

參考文檔:

https://github.com/Netflix/Hystrix/wiki/How-To-Use

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多