javascript
Spring Cloud【Finchley】-12使用Hystrix Dashboard实现Hystrix数据的可视化监控
文章目錄
- 概述
- Hystrix Dashboard
- Step 1 新建項目
- Step2 增加maven依賴
- Step3 啟動類增加注解@EnableHystrixDashboard
- Step4 配置文件application.yml
- Step5 啟動微服務(wù)
- Step6 測試
- 代碼
概述
Spring Cloud【Finchley】-11Feign項目整合Hystrix監(jiān)控中,我們通過 http://ip:port/actuator/hystrix.stream 的形式來查看到的Hystrix的數(shù)據(jù)都是文本形式,可讀性非常差。 好在Spring Cloud為我們提供了Hystrix Dashboard,來看下如何使用吧。
官方文檔: https://cloud.spring.io/spring-cloud-static/Finchley.SR2/single/spring-cloud.html#_circuit_breaker_hystrix_dashboard
Hystrix Dashboard
為了方便統(tǒng)一管理,這里的例子我們也將Hystrix Dashboard這個微服務(wù)注冊到Eureka上,當(dāng)然了也可以不注冊。
Step 1 新建項目
我們在父工程的maven上右鍵新建module , 起名為 micorservice-hystrix-dashboard
如下
Step2 增加maven依賴
<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-dashboard</artifactId></dependency>我們打算注冊到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: 8888spring:application:name: micorservice-hystrix-dashboard#eureka eureka:client:service-url:defaultZone: http://artisan:artisan123@localhost:8761/eurekainstance:prefer-ip-address: true # 起碼點擊后 會看到ip信息instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}Step5 啟動微服務(wù)
因為我們注冊到了Eureka上,所以需要先啟動microservice-discovery-eureka,然后再啟動該服務(wù),啟動成功后,訪問 http://localhost:8888/hystrix
Step6 測試
- 繼續(xù)啟動服務(wù)提供者微服務(wù) micorservice-provider-user,
- 然后啟動整合了Hystrix的消費者微服務(wù) micorservice-consumer-movie-ribbon-hystrix 和 micorservice-consumer-movie-fegin-hystrix
到Eureka上看下注冊的服務(wù)列表
micorservice-consumer-movie-fegin-hystrix 對應(yīng)的hystrix url為:http://localhost:7901/actuator/hystrix.stream
micorservice-consumer-movie-ribbon-hystrix 對應(yīng)的hystrix url為:
http://localhost:7902/actuator/hystrix.stream
分別輸入url和自定義的title
點擊Monitor Stream 進(jìn)入, 一直處于loading狀態(tài)
是因為還沒有觸發(fā)hystrix,我們來調(diào)用這倆微服務(wù)提供的對外接口
訪問下 http://localhost:7901/movie/1 觸發(fā)hystrix收集信息,多訪問幾次,信息如下
訪問下 http://localhost:7902/movie/2 觸發(fā)hystrix收集信息 ,多訪問幾次
以上就實現(xiàn)了通過Dashboard 對單個節(jié)點的微服務(wù)進(jìn)行近乎實時的可視化監(jiān)控。
上圖中的參數(shù)說明參考官網(wǎng) https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki:
代碼
https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-hystrix-dashboard
總結(jié)
以上是生活随笔為你收集整理的Spring Cloud【Finchley】-12使用Hystrix Dashboard实现Hystrix数据的可视化监控的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Cloud【Finchle
- 下一篇: Spring Cloud【Finchle