在第四篇文章斷路器講述瞭如何使用斷路器,並簡單的介紹了下Hystrix Dashboard組件,這篇文章更加詳細的介紹Hystrix Dashboard。web
1、Hystrix Dashboard簡介
在微服務架構中爲例保證程序的可用性,防止程序出錯致使網絡阻塞,出現了斷路器模型。斷路器的情況反應了一個程序的可用性和健壯性,它是一個重要指標。瞭解springcloud架構能夠加求求:三五三六二四七二五九,Hystrix Dashboard是做爲斷路器狀態的一個組件,提供了數據監控和友好的圖形化界面。spring
2、準備工做
本文的的來源於第一篇文章的栗子,在它的基礎上進行改造。網絡
3、開始改造service-hi
在pom的工程文件引入相應的依賴:架構
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</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-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> </dependencies>
其中,這三個依賴是必須的,缺一不可。app
在程序的入口ServiceHiApplication類,加上@EnableHystrix註解開啓斷路器,這個是必須的,而且須要在程序中聲明斷路點HystrixCommand;加上@EnableHystrixDashboard註解,開啓HystrixDashboard分佈式
@SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient @RestController @EnableHystrix @EnableHystrixDashboard @EnableCircuitBreaker public class ServiceHiApplication { /** * 訪問地址 http://localhost:8762/actuator/hystrix.stream * @param args */ public static void main(String[] args) { SpringApplication.run( ServiceHiApplication.class, args ); } @Value("${server.port}") String port; @RequestMapping("/hi") @HystrixCommand(fallbackMethod = "hiError") public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) { return "hi " + name + " ,i am from port:" + port; } public String hiError(String name) { return "hi,"+name+",sorry,error!"; } }
運行程序: 依次開啓eureka-server 和service-hi.ide
4、Hystrix Dashboard圖形展現
打開http://localhost:8762/actuator/hystrix.stream,能夠看到一些具體的數據:
打開localhost:8762/hystrix 能夠看見如下界面:
在界面依次輸入:http://localhost:8762/actuator/hystrix.stream 、2000 、miya
;點肯定。spring-boot
在另外一個窗口輸入: http://localhost:8762/hi?name=forezp微服務
從新刷新hystrix.stream網頁,你會看到良好的圖形化界面:.ui