springcloud(十):熔斷監控Hystrix Dashboard

         申明: 這裏比較坑爹,你們寫的時候要當心,這裏和springboot的版本有關係哈,我使用的是2.0 版本,要麼調頻爲1.5 版本,要麼使用其餘方式 解決錯誤,我選擇了仍是用2.0  各位慎重參考哈html

 

    Hystrix-dashboard是一款針對Hystrix進行實時監控的工具,經過Hystrix Dashboard咱們能夠在直觀地看到各Hystrix Command的請求響應時間, 請求成功率等數據web

 

話很少說看項目,爲了不在一個項目上反覆修改,你們看的一頭霧水,因此我仍是選擇從新建立項目spring

 

1.建立項目springboot

 

 

2. 選擇項目類型服務器

 

 3.選擇項目名稱,能夠隨便寫,可是不能有大寫微信

 

 4.選擇咱們要生成的依賴app

 

 5.選擇工程和模塊命名ide

 

6.項目結構以下,和上一個木有大的變化,只是配置變了spring-boot

 

 7. 編輯pom.xml文件工具

<dependencies> <dependency> <groupId>cn.kgc</groupId> <artifactId>eureka-common-school</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!--@EnableDiscoveryClient--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <!--@EnableHystrixDashboard--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <!--@EnableCircuitBreaker--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--@EnableFeignClients--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>

 

8.編輯咱們的屬性文件

server.port=8765 spring.application.name=hystrix-dashboard eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ # 將feign集成的斷路器設置成有效狀態 feign.hystrix.enabled=true # 加載全部的端點 management.endpoints.web.exposure.include="*"

 

9..在cn.kgc.feign包下編寫StudentFeign業務接口,好多人在這裏添加service註解,木有看懂,可是我這裏也能拿到數據

package cn.kgc.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; /*FeignClient的name屬性值和eureka_client_product的appliaction屬性文件找那個的spring.application.name保持一致 fallback屬性指定容錯處理類 springcloud默認已經爲feign整合了hystrix,只要hystrix在項目中,使用feign就會 默認使用熔斷器處理所欲的請求 熔斷器模式相似於生活中的電路保險絲,當電流抄在可能銀帆危險時就會自動斷開,使用熔斷器模式, 若是請求出現異常,全部的請求都會直接返回而不會等待或阻塞,這樣能夠減小資源的浪費。 熔斷器還有一種半開的狀態,當熔斷器發現異常後悔進入半打開狀態,此時會定時接受 一個請求來檢測系統是否恢復,若是請求調用成功,表明系統已經恢復正常,救護關掉熔斷器, 不然繼續打開*/ @FeignClient(name="client-school-provider",fallback = StudentFeignFallBack.class) public interface StudentFeign { //下面的調用接口標準要和eureka-client-provider中的controller請求方法必須保持一致 @RequestMapping("/data.do") public String stuData(); }

 

10..在cn.kgc.feign包下編寫StudentFeignFallBack容錯處理類

package cn.kgc.feign; import org.springframework.stereotype.Component; //容錯處理類 @Component public class StudentFeignFallBack implements StudentFeign{ @Override public String stuData() { return "服務器異常,請稍後在嘗試登錄"; } }

 

 

11.在cn.kgc.controller包下編寫StudentController控制器類

package cn.kgc.controller; import cn.kgc.feign.StudentFeign; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class StudentController { @Autowired private StudentFeign studentFeign; @RequestMapping("/studata.do") public String showOptionsData(){ return studentFeign.stuData(); } }

 

12.啓動拉。仍是老規矩依次啓動:eureka-server、eureka-client-provider、hystrix-dashboard

 

 13. 正常訪問

 

圖中會有一些提示:

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/actuator/hystrix.stream 

大概意思就是若是查看默認集羣使用第一個url,查看指定集羣使用第二個url,單個應用的監控使用最後一個,咱們暫時只演示單個應用的因此在輸入框中輸入: http://localhost:8765/actuator/hystrix.stream ,輸入以後點擊 monitor,進入頁面。若是沒有請求會先顯示Loading ...

 

 

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

 

 

請求服務hhttp://localhost:8765/studata.do

 

在刷新地址

 

 

 注意這些是啥意思,本身翻譯下面的圖,這個是把上面個列表以圖形化的形式展現出來了,須要使用工具哦

 

 

 

斷頭了,爲了發帖子,脖子要折了,轉帖請註明出處

有問題請聯繫我哈:微信、QQ:964918306


此帖子爲原創

做者:紅酒人生

轉載請註明出處:https://www.cnblogs.com/holly8/p/11025732.html

相關文章
相關標籤/搜索