ABAP Netweaver, Hybris Commerce和SAP 云平臺的登錄認證
830
2025-03-31
文章目錄
概述
Hystrix Dashboard
Step 1 新建項目
Step2 增加maven依賴
Step3 啟動類增加注解@EnableHystrixDashboard
Step4 配置文件Application.yml
Step5 啟動微服務
Step6 測試
代碼
概述
Spring Cloud【Finchley】-11Feign項目整合Hystrix監控中,我們通過 http://ip:port/actuator/hystrix.stream 的形式來查看到的Hystrix的數據都是文本形式,可讀性非常差。 好在Spring Cloud為我們提供了Hystrix Dashboard,來看下如何使用吧。
官方文檔: https://cloud.spring.io/spring-cloud-static/Finchley.SR2/single/spring-cloud.html#_circuit_breaker_hystrix_dashboard
Hystrix Dashboard
為了方便統一管理,這里的例子我們也將Hystrix Dashboard這個微服務注冊到Eureka上,當然了也可以不注冊。
Step 1 新建項目
我們在父工程的maven上右鍵新建module , 起名為 micorservice-hystrix-dashboard
如下
Step2 增加maven依賴
我們打算注冊到Eureka上,所以也需要添加spring-cloud-starter-netflix-eureka-client
Step3 啟動類增加注解@EnableHystrixDashboard
同時我們也打算注冊到Eureka上,所以也需要添加@EnableDiscoveryClient注解
package com.artisan.micorservice; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringbootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringbootApplication @EnableDiscoveryClient @EnableHystrixDashboard public class MicorserviceMovieRibbonHystrixDashboard { public static void main(String[] args) { SpringApplication.run(MicorserviceMovieRibbonHystrixDashboard.class, args); } }
Step4 配置文件application.yml
server: port: 8888 spring: application: name: micorservice-hystrix-dashboard #eureka eureka: client: service-url: defaultZone: http://artisan:artisan123@localhost:8761/eureka instance: prefer-ip-address: true # 起碼點擊后 會看到ip信息 instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
Step5 啟動微服務
因為我們注冊到了Eureka上,所以需要先啟動microservice-discovery-eureka,然后再啟動該服務,啟動成功后,訪問 http://localhost:8888/hystrix
Step6 測試
繼續啟動服務提供者微服務 micorservice-provider-user,
然后啟動整合了Hystrix的消費者微服務 micorservice-consumer-movie-ribbon-hystrix 和 micorservice-consumer-movie-fegin-hystrix
到Eureka上看下注冊的服務列表
micorservice-consumer-movie-fegin-hystrix 對應的hystrix url為:http://localhost:7901/actuator/hystrix.stream
micorservice-consumer-movie-ribbon-hystrix 對應的hystrix url為:
http://localhost:7902/actuator/hystrix.stream
分別輸入url和自定義的title
點擊Monitor Stream 進入, 一直處于loading狀態
是因為還沒有觸發hystrix,我們來調用這倆微服務提供的對外接口
訪問下 http://localhost:7901/movie/1 觸發hystrix收集信息,多訪問幾次,信息如下
訪問下 http://localhost:7902/movie/2 觸發hystrix收集信息 ,多訪問幾次
以上就實現了通過Dashboard 對單個節點的微服務進行近乎實時的可視化監控。
上圖中的參數說明參考官網 https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki:
代碼
https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-hystrix-dashboard
Spring Spring Cloud
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。