javascript
史上最简单的SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)
轉:https://blog.csdn.net/forezp/article/details/70217283
在我的第四篇文章斷路器(https://blog.csdn.net/forezp/article/details/69934399)講述了如何使用斷路器,并簡單的介紹了下Hystrix Dashboard組件,這篇文章更加詳細的介紹Hystrix Dashboard。
一、Hystrix Dashboard簡介
在微服務架構中為例保證程序的可用性,防止程序出錯導致網絡阻塞,出現了斷路器模型。斷路器的狀況反應了一個程序的可用性和健壯性,它是一個重要指標。Hystrix Dashboard是作為斷路器狀態的一個組件,提供了數據監控和友好的圖形化界面。
二、準備工作
本文的的工程栗子,來源于第一篇文章(https://blog.csdn.net/forezp/article/details/69696915)的栗子,在它的基礎上進行改造。
三、開始改造service-hi
在pom的工程文件引入相應的依賴:
<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> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId> </dependency>其中,這三個依賴是必須的,缺一不可。
在程序的入口ServiceHiApplication類,加上@EnableHystrix注解開啟斷路器,這個是必須的,并且需要在程序中聲明斷路點HystrixCommand;加上@EnableHystrixDashboard注解,開啟HystrixDashboard
@SpringBootApplication @EnableEurekaClient @RestController @EnableHystrix @EnableHystrixDashboard public class ServiceHiApplication {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 String name) {return "hi "+name+",i am from port:" +port;}public String hiError(String name) {return "hi,"+name+",sorry,error!";} }運行程序: 依次開啟eureka-server 和service-hi.
四、Hystrix Dashboard圖形展示
打開http://localhost:8762/hystrix.stream,可以看到一些具體的數據:
打開locahost:8762/hystrix 可以看見以下界面:
在界面依次輸入:locahost:8762/hystrix.stream 、2000 、miya ;點確定
在另一個窗口輸入: http://localhost:8762/hi?name=forezp
重新刷新hystrix.stream網頁,你會看到良好的圖形化界面:
源碼下載:
https://github.com/forezp/SpringCloudLearning/tree/master/chapter12
總結
以上是生活随笔為你收集整理的史上最简单的SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 披萨为什么那么贵?
- 下一篇: 史上最简单的SpringCloud教程