亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringCloud中的熔斷監(jiān)控HystrixDashboard和Turbine示例詳解

 更新時間:2024年09月09日 12:25:36   作者:242030  
HystrixDashboard是用于實時監(jiān)控Hystrix性能的工具,展示請求響應時間和成功率等數(shù)據(jù),本文介紹了如何配置和使用HystrixDashboard和Turbine進行熔斷監(jiān)控,包括依賴添加、啟動類配置和測試流程,感興趣的朋友一起看看吧

SpringCloud之熔斷監(jiān)控HystrixDashboard和Turbine

Hystrix-dashboard是一款針對Hystrix進行實時監(jiān)控的工具,通過Hystrix Dashboard我們可以在直觀地看到各

Hystrix Command的請求響應時間, 請求成功率等數(shù)據(jù)。但是只使用Hystrix Dashboard的話, 你只能看到單個應

用內(nèi)的服務信息,這明顯不夠。我們需要一個工具能讓我們匯總系統(tǒng)內(nèi)多個服務的數(shù)據(jù)并顯示到Hystrix

Dashboard上,這個工具就是Turbine。

1、Hystrix Dashboard

我們在熔斷示例項目的基礎上更改。

1.1 添加依賴

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-cloud-consumer-hystrix-dashboard</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-cloud-consumer-hystrix-dashboard</name>
    <description>spring-cloud-consumer-hystrix-dashboard</description>
    <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>Dalston.RELEASE</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <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>
        <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>

1.2 啟動類

啟動類添加啟用Hystrix Dashboard和熔斷器

package com.example;
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.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class SpringCloudConsumerHystrixDashboardApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringCloudConsumerHystrixDashboardApplication.class, args);
    }
}

1.3 其它類

package com.example.remote;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name= "spring-cloud-producer", fallback = HelloRemoteHystrix.class)
public interface HelloRemote {
    @RequestMapping(value = "/hello")
    public String hello(@RequestParam(value = "name") String name);
}
package com.example.remote;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
@Component
public class HelloRemoteHystrix implements HelloRemote{
    @Override
    public String hello(@RequestParam(value = "name") String name) {
        return "hello " +name+", this messge send failed ";
    }
}
package com.example.controller;
import com.example.remote.HelloRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConsumerController {
    @Autowired
    HelloRemote helloRemote;
    @RequestMapping("/hello/{name}")
    public String index(@PathVariable("name") String name) {
        return helloRemote.hello(name);
    }
}
spring.application.name=spring-cloud-consumer-hystrix-dashboard
server.port=9003
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

1.4 測試

啟動工程后訪問 http://localhost:9003/hystrix,將會看到如下界面:

圖中會有一些提示:

Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream

Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]

Single Hystrix App: http://hystrix-app:port/hystrix.stream

大概意思就是如果查看默認集群使用第一個url,查看指定集群使用第二個url,單個應用的監(jiān)控使用最后一個,我

們暫時只演示單個應用的所以在輸入框中輸入: http://localhost:9003/hystrix.stream ,輸入之后點擊

monitor,進入頁面。如果沒有請求會先顯示Loading ...

在這里插入圖片描述

訪問 http://localhost:9003/hystrix.stream 也會不斷的顯示ping。

在這里插入圖片描述

請求服務 http://localhost:9003/hello/neo,就可以看到監(jiān)控的效果了:

在這里插入圖片描述

首先訪問 http://localhost:9003/hystrix.stream,顯示如下:

data: {"type":"HystrixCommand","name":"HelloRemote#hello(String)","group":"spring-cloud-producer","currentTime":1662554090588,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"spring-cloud-producer"}
data: {"type":"HystrixThreadPool","name":"spring-cloud-producer","currentTime":1662554090588,"currentActiveCount":0,"currentCompletedTaskCount":1,"currentCorePoolSize":10,"currentLargestPoolSize":1,"currentMaximumPoolSize":10,"currentPoolSize":1,"currentQueueSize":0,"currentTaskCount":1,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"rollingCountCommandRejections":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"reportingHosts":1}
ping: 

說明已經(jīng)返回了監(jiān)控的各項結(jié)果。

到監(jiān)控頁面就會顯示如下圖:

在這里插入圖片描述

其實就是 http://localhost:9003/hystrix.stream 返回結(jié)果的圖形化顯示,Hystrix Dashboard Wiki上詳細

說明了圖上每個指標的含義,如下圖:

在這里插入圖片描述

到此單個應用的熔斷監(jiān)控已經(jīng)完成。

2、Turbine

在復雜的分布式系統(tǒng)中,相同服務的節(jié)點經(jīng)常需要部署上百甚至上千個,很多時候,運維人員希望能夠把相同服務

的節(jié)點狀態(tài)以一個整體集群的形式展現(xiàn)出來,這樣可以更好的把握整個系統(tǒng)的狀態(tài)。 為此,Netflix提供了一個開

源項目(Turbine)來提供把多個hystrix.stream的內(nèi)容聚合為一個數(shù)據(jù)源供Dashboard展示。

2.1 添加依賴

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-cloud-hystrix-dashboard-turbine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-cloud-hystrix-dashboard-turbine</name>
    <description>spring-cloud-hystrix-dashboard-turbine</description>
    <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>Dalston.RELEASE</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.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </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>

2.2 配置文件

spring.application.name=hystrix-dashboard-turbine
server.port=8001
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
  • turbine.appConfig:配置Eureka中的serviceId列表,表明監(jiān)控哪些服務。
  • turbine.aggregator.clusterConfig:指定聚合哪些集群,多個使用”,”分割,默認為default??墒褂?/li>

http://.../turbine.stream?cluster={clusterConfig之一}訪問。

  • turbine.clusterNameExpression

1、clusterNameExpression指定集群名稱,默認表達式appName;此時:

turbine.aggregator.clusterConfig需要配置想要監(jiān)控的應用名稱;

2、當clusterNameExpression: default時,turbine.aggregator.clusterConfig可以不寫,因為默認就是

default;

3、當clusterNameExpression: metadata[‘cluster’]時,假設想要監(jiān)控的應用配置了

eureka.instance.metadata-map.cluster: ABC,則需要配置,同時

turbine.aggregator.clusterConfig: ABC

2.3 啟動類

啟動類添加@EnableTurbine,激活對Turbine的支持

package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class SpringCloudHystrixDashboardTurbineApplication {
	public static void main(String[] args) {
		SpringApplication.run(SpringCloudHystrixDashboardTurbineApplication.class, args);
	}
}

到此Turbine(hystrix-dashboard-turbine)配置完成

2.4 測試

在示例項目spring-cloud-consumer-hystrix基礎上修改為兩個服務的調(diào)用者spring-cloud-consumer-node1和

spring-cloud-consumer-node2。

spring-cloud-consumer-node1項目改動如下:application.properties文件內(nèi)容

spring.application.name=node01
server.port=9001
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

spring-cloud-consumer-node2項目改動如下:application.properties文件內(nèi)容

spring.application.name=node02
server.port=9002
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

HelloRemote類修改:

package com.example.remote;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "spring-cloud-producer", fallback = HelloRemoteHystrix.class)
public interface HelloRemote {
    @RequestMapping(value = "/hello")
    public String hello(@RequestParam(value = "name") String name);
}

對應的HelloRemoteHystrixConsumerController類跟隨修改,具體查看代碼

package com.example.remote;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
@Component
public class HelloRemoteHystrix implements HelloRemote{
    @Override
    public String hello(@RequestParam(value = "name") String name) {
        return "hello " +name+", this messge send failed ";
    }
}
package com.example.controller;
import com.example.remote.HelloRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConsumerController {
    @Autowired
    HelloRemote helloRemote;
    @RequestMapping("/hello/{name}")
    public String index(@PathVariable("name") String name) {
        return helloRemote.hello(name);
    }
}

修改完畢后,依次啟動spring-cloud-eureka、spring-cloud-consumer-node1、spring-cloud-consumer-

node2、spring-cloud-hystrix-dashboard-turbine

打開eureka后臺可以看到注冊了三個服務:

在這里插入圖片描述

訪問 http://localhost:8001/turbine.stream

返回:

: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1662554703162}
: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1662554706172}

并且會不斷刷新以獲取實時的監(jiān)控數(shù)據(jù),說明和單個的監(jiān)控類似,返回監(jiān)控項目的信息。

進行圖形化監(jiān)控查看,輸入:http://localhost:8001/hystrix,返回酷酷的小熊界面

在這里插入圖片描述

輸入:http://localhost:8001/turbine.stream,然后點擊 Monitor Stream ,可以看到出現(xiàn)了倆個監(jiān)控列表

在這里插入圖片描述

訪問http://localhost:9001/hello/neohttp://localhost:9002/hello/neo

在這里插入圖片描述

到此這篇關于SpringCloud中的熔斷監(jiān)控HystrixDashboard和Turbine的文章就介紹到這了,更多相關SpringCloud熔斷監(jiān)控內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 用Java制作用戶登錄界面超詳細圖文教程

    用Java制作用戶登錄界面超詳細圖文教程

    很多人學習Java的第一個任務是使用Java設計客戶端登錄界面中,希望我的學習方法與總結(jié)能幫助到需要的朋友,這篇文章主要給大家介紹了關于用Java制作用戶登錄界面的相關資料,需要的朋友可以參考下
    2024-06-06
  • javac、java打jar包命令實例

    javac、java打jar包命令實例

    這篇文章主要演示Java中使用命令打jar包的實例過程,很實用,希望能給大家做一個參考。
    2016-06-06
  • spring通過filter,Interceptor統(tǒng)一處理ResponseBody的返回值操作

    spring通過filter,Interceptor統(tǒng)一處理ResponseBody的返回值操作

    這篇文章主要介紹了spring通過filter,Interceptor統(tǒng)一處理ResponseBody的返回值操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Java?Request獲取請求頭數(shù)據(jù)實例詳解

    Java?Request獲取請求頭數(shù)據(jù)實例詳解

    在開發(fā)中我們經(jīng)常需要獲取用戶IP地址,通過地址來實現(xiàn)一些功能,下面這篇文章主要給大家介紹了關于Java中Request獲取請求頭數(shù)據(jù)的相關資料,需要的朋友可以參考下
    2024-01-01
  • Spring實戰(zhàn)之使用XML方式管理聲明式事務操作示例

    Spring實戰(zhàn)之使用XML方式管理聲明式事務操作示例

    這篇文章主要介紹了Spring實戰(zhàn)之使用XML方式管理聲明式事務操作,結(jié)合實例形式詳細分析了Spring XML方式管理聲明式事務具體步驟、配置、接口及使用技巧,需要的朋友可以參考下
    2020-01-01
  • 三道java新手入門面試題,通往自由的道路--鎖+Volatile

    三道java新手入門面試題,通往自由的道路--鎖+Volatile

    這篇文章主要為大家分享了最有價值的3道多線程面試題,涵蓋內(nèi)容全面,包括數(shù)據(jù)結(jié)構(gòu)和算法相關的題目、經(jīng)典面試編程題等,對hashCode方法的設計、垃圾收集的堆和代進行剖析,感興趣的小伙伴們可以參考一下
    2021-07-07
  • java隨機生成10位數(shù)的字符串ID

    java隨機生成10位數(shù)的字符串ID

    這篇文章主要為大家詳細介紹了java隨機生成10位數(shù)字符串ID的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Java中@RestController注解使用

    Java中@RestController注解使用

    在Spring框架中,@RestController注解是一個非常重要的注解,它用于將一個類標記為RESTful風格的控制器,本文就來介紹一下Java中@RestController注解使用,感興趣的可以了解一下
    2023-11-11
  • 關于Spring框架中異常處理情況淺析

    關于Spring框架中異常處理情況淺析

    最近學習Spring時,認識到Spring異常處理的強大,這篇文章主要給大家介紹了關于Spring框架中異常處理情況的相關資料,通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2021-08-08
  • IDEA 包轉(zhuǎn)模塊的解決步驟

    IDEA 包轉(zhuǎn)模塊的解決步驟

    很多朋友遇到這樣一個問題,直接在idea拉取代碼,發(fā)現(xiàn)創(chuàng)建的模塊包類型不一樣了,類似這樣的問題該如何處理呢?很多朋友向小編求助,在這統(tǒng)一回答大家,需要的朋友參考下本文吧
    2021-06-06

最新評論