SpringCloud Hystrix-Dashboard儀表盤的實(shí)現(xiàn)
Hystrix Dashboard,它主要用來實(shí)時(shí)監(jiān)控Hystrix的各項(xiàng)指標(biāo)信息。通過Hystrix Dashboard反饋的實(shí)時(shí)信息,可以幫助我們快速發(fā)現(xiàn)系統(tǒng)中存在的問題。下面通過一個(gè)例子來學(xué)習(xí)。
一、新建一個(gè)Spring Cloud 項(xiàng)目,命名為hystrix-dashboard
1.1在pom.xml引入相關(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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
1.2在spring boot 的啟動類上面引入注解@EnableHystrixDashboard,啟用Hystrix Dashboard功能。
package org.hope.hystrix.dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@SpringCloudApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
1.3修改配置文件application.properties
spring.application.name=hystrix-dashboard server.port=2001
1.4啟動應(yīng)用,然后再瀏覽器中輸入http://localhost:2001/hystrix可以看到如下界面

通過Hystrix Dashboard主頁面的文字介紹,我們可以知道,Hystrix Dashboard共支持三種不同的監(jiān)控方式
☞默認(rèn)的集群監(jiān)控:通過URL:http://turbine-hostname:port/turbine.stream開啟,實(shí)現(xiàn)對默認(rèn)集群的監(jiān)控。
☞指定的集群監(jiān)控:通過URL:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]開啟,實(shí)現(xiàn)對clusterName集群的監(jiān)控。
☞單體應(yīng)用的監(jiān)控:通過URL:http://hystrix-app:port/hystrix.stream開啟,實(shí)現(xiàn)對具體某個(gè)服務(wù)實(shí)例的監(jiān)控。
☞Delay:控制服務(wù)器上輪詢監(jiān)控信息的延遲時(shí)間,默認(rèn)為2000毫秒,可以通過配置該屬性來降低客戶端的網(wǎng)絡(luò)和CPU消耗。
☞Title:該參數(shù)可以展示合適的標(biāo)題。
二、要有一個(gè)eureka-server用來提供eureka的服務(wù)注冊中心,在碼云上有,可以作為參考。此處不再粘代碼。
三、要有一個(gè)eureka-service來提供服務(wù),工程名為hello-service,項(xiàng)目地址同上。
四、新建一個(gè)服務(wù)被監(jiān)控的工程,工程名為ribbon-customer。
4.1pom.xml引入相關(guān)依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency>
4.2在啟動類上添加@EnableCircuitBreaker 開啟斷路器功能
package com.didispace;
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.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableCircuitBreaker //開啟斷路器功能
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
4.3 RestController
package com.didispace.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConsumerController {
@Autowired
HelloService helloService;
@RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)
public String helloConsumer() {
return helloService.hello();
}
}
4.4 application.properties配置文件
spring.application.name=ribbon-consumer server.port=9000 eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000
通過上面的步驟,已經(jīng)基本完成了準(zhǔn)備工作,下面我們進(jìn)行測試。
1.啟動eureka-server
2.啟動hello-service
3.啟動ribbon-customer
4.啟動hystrix-dashboard
5.在瀏覽器輸入http://localhost:2001/hystrix
6.在瀏覽器的新窗口輸入http://localhost:9000/ribbon-consumer
7.在Hystrix-Dashboard的主界面上輸入: http://localhost:9000/hystrix.stream然后點(diǎn)擊 Monitor Stream按鈕

在監(jiān)控的界面有兩個(gè)重要的圖形信息:一個(gè)實(shí)心圓和一條曲線。
- 實(shí)心圓:1、通過顏色的變化代表了實(shí)例的健康程度,健康程度從綠色、黃色、橙色、紅色遞減。2、通過大小表示請求流量發(fā)生變化,流量越大該實(shí)心圓就越大。所以可以在大量的實(shí)例中快速發(fā)現(xiàn)故障實(shí)例和高壓實(shí)例。
- 曲線:用來記錄2分鐘內(nèi)流浪的相對變化,可以通過它來觀察流量的上升和下降趨勢。
注意:當(dāng)使用Hystrix Board來監(jiān)控Spring Cloud Zuul構(gòu)建的API網(wǎng)關(guān)時(shí),Thread Pool信息會一直處于Loading狀態(tài)。這是由于Zuul默認(rèn)會使用信號量來實(shí)現(xiàn)隔離,只有通過Hystrix配置把隔離機(jī)制改成為線程池的方式才能夠得以展示。
參考:
[1]《Spring Cloud微服務(wù)實(shí)戰(zhàn)》,翟永超
[2]博客,純潔的微笑,http://www.dhdzp.com/article/167053.htm
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringCloud-Hystrix-Dashboard客戶端服務(wù)監(jiān)控的實(shí)現(xiàn)方法
- Springcloud hystrix服務(wù)熔斷和dashboard如何實(shí)現(xiàn)
- SpringCloud之熔斷監(jiān)控Hystrix Dashboard的實(shí)現(xiàn)
- springcloud 熔斷監(jiān)控Hystrix Dashboard和Turbine
- SpringCloud中的斷路器(Hystrix)和斷路器監(jiān)控(Dashboard)
- Hystrix?Dashboard斷路監(jiān)控儀表盤的實(shí)現(xiàn)詳細(xì)介紹
相關(guān)文章
Android Studio更改項(xiàng)目使用的JDK(詳細(xì)步驟)
本文介紹了如何在Android Studio中修改Gradle和JDK的配置步驟,包括打開設(shè)置、進(jìn)入Gradle設(shè)置、修改JDK路徑、保存并生效等,感興趣的朋友跟隨小編一起看看吧2024-11-11
java中json和對象之間相互轉(zhuǎn)換的運(yùn)用
本文主要介紹了java中json和對象之間相互轉(zhuǎn)換的運(yùn)用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
Spring Boot 約定大于配置之如何實(shí)現(xiàn)自定義配置
本文介紹了SpringBoot的“約定大于配置”理念以及如何實(shí)現(xiàn)自定義配置,通過實(shí)現(xiàn)接口和添加@Configuration注解,開發(fā)者可以靈活地?cái)U(kuò)展和定制SpringBoot的默認(rèn)行為,感興趣的朋友一起看看吧2025-03-03
Java擴(kuò)展庫RxJava的基本結(jié)構(gòu)與適用場景小結(jié)
RxJava(GitHub: https://github.com/ReactiveX/RxJava)能夠幫助Java進(jìn)行異步與事務(wù)驅(qū)動的程序編寫,這里我們來作一個(gè)Java擴(kuò)展庫RxJava的基本結(jié)構(gòu)與適用場景小結(jié),剛接觸RxJava的同學(xué)不妨看一下^^2016-06-06
springboot多模塊項(xiàng)目mvn打包遇到存在依賴但卻無法發(fā)現(xiàn)符號問題
在SpringBoot多模塊項(xiàng)目中,如果遇到依賴存在但無法發(fā)現(xiàn)符號的問題,常見原因可能是pom.xml配置問題,例如,如果某個(gè)模塊僅作為依賴而不是啟動工程,不應(yīng)在其pom中配置spring-boot-maven-plugin插件,因?yàn)檫@將影響jar包的生成方式2024-09-09
深入理解Java class文件格式_動力節(jié)點(diǎn)Java學(xué)院整理
對于理解JVM和深入理解Java語言, 學(xué)習(xí)并了解class文件的格式都是必須要掌握的功課2017-06-06

