日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springCloud - 第13篇 - 服务监控 集群模式 Hystrix-turbine

發布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springCloud - 第13篇 - 服务监控 集群模式 Hystrix-turbine 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。

1. 在springcloud 體系中,可以用 hystrix-dashboard? 實時監控服務的運行狀態。上一文記錄了單實例的監控,現在實現集群監控。

2. 新建工程 hystrix-turbine 作為集群監控的實現服務。

2.1?file - new - module?

2.2??spring Initializr - module SDK 選擇自己的 JDK ,其余的可以不用填寫,next。

2.3?填寫工程相關信息:包名、工程名等,next。

2.4?此步只是幫助自動生成依賴,可不選,直接 next。

2.5?工程名,代碼存放位置等,finish 。

2.6?生成工程的結構如下:

2.7?pom.xml 重用 hystrix-dashboard 的依賴,另新增少量依賴:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com</groupId><artifactId>hystrix-turbine</artifactId><version>0.0.1-SNAPSHOT</version><name>hystrix-turbine</name><description>監控面板-集群 </description><parent><groupId>com</groupId><artifactId>hystrix-dashboard</artifactId><version>0.0.1-SNAPSHOT</version></parent><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-turbine</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies></project>

2.8 啟動類:

package com.hystrixturbine;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.turbine.EnableTurbine;//監控面板-集群 @EnableTurbine@SpringBootApplication public class HystrixTurbineApplication {public static void main(String[] args) {SpringApplication.run(HystrixTurbineApplication.class, args);}}

2.9 配置文件?application.properties:

# 注冊中心 - 端口: 1234、工程名: eureka (見 eureka 工程中配置)。 eureka.client.serviceUrl.defaultZone= http://localhost:1234/eureka/# 端口 server.port= 8889# 工程名 spring.application.name= hystrix-turbine# 被監控服務名稱 turbine.app-config= ribbon,feign# 集群名稱為“default”。 # 應用服務很多時,可用多個 hystrix-turbine 來監控不同的聚合集群,集群名可區分這些不同的聚合集群, # 此集群名亦可在 hystrix-dashboard 中用來定位不同的聚合集群: # 即:“http://turbine-hostname:port/turbine.stream?cluster=[clusterName]” 中對應 “clusterName”便可。 turbine.cluster-name-expression= "default"# 同一主機上的服務通過主機名與端口號的組合來進行區分,默認以 host 區分服務, # 這樣,本地調試時,本機上的不同服務則會聚合成一個服務來統計。 turbine.combine-host-port= true

3. 類同已有的 ribbon 工程,調整已有工程 feign 工程。

3.1 增加依賴?spring-cloud-starter-netflix-hystrix,此時 feign工程完整 pom 為:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.feign</groupId><artifactId>service-feign</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>service-feign</name><description>服務消費 feign 方式</description><parent><groupId>com.base</groupId><artifactId>base-config</artifactId><version>0.0.1-SNAPSHOT</version></parent><dependencies><!-- 開啟 hystrix 監控 --><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-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency></dependencies><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories></project>

3.2 配置文件中加上 hystrix 相關配置,完整配置為:

# 注冊中心 - 端口: 1234、工程名: eureka (見 eureka 工程中配置)。 eureka.client.serviceUrl.defaultZone= http://localhost:1234/eureka/# 端口 server.port= 8702# 工程名 spring.application.name= feign# 開啟斷熔器: ( Feign 自帶斷路器,但默認為不開啟: false) feign.hystrix.enabled=true# 也可配置為'*' ,納入 hystrix 服務監控 management.endpoints.web.exposure.include= hystrix.stream

3.3? 啟動類確認注解 :@EnableHystrix,同時加上?hystrixMetricsStreamServlet 方法,完整啟動類為:

package com.feign.servicefeign;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean;@SpringBootApplication/*** 基于接口的注解,可插拔,可使用 Feign注解 和 JAX-RS注解* Feign 默認集成 Ribbon,并和 Eureka 結合,默認實現負載均衡。*/ @EnableFeignClients// 標明自已為服務 @EnableEurekaClient// 開啟斷路器: Hystrix @EnableHystrix public class ServiceFeignApplication {public static void main(String[] args) {SpringApplication.run(ServiceFeignApplication.class, args);}@Beanpublic ServletRegistrationBean hystrixMetricsStreamServlet() {ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());registration.addUrlMappings("/hystrix.stream");return registration;} }

4. 依次啟動工程: 注冊中心 eureka ( 端口 1234 ) 、?服務應用 ribbon? ( 端口 8701 ) 、服務應用 feign ( 端口 8702)、

監控集群服務 hystrix-turbine ( 端口 8889)、監控儀表盤hystrix-dashboard? ( 端口 8888) 。

其中,服務應用 ribbon、feign 都調用第三方服務應用:seeParam? ( 端口 8801) 。

4.1 seeParam 工程未啟動,由于有熔斷機制,訪問 feign 工程效果為:

4.2 同樣,seeParam 工程未啟動,由于有熔斷機制,訪問 ribbon?工程效果為:

4.3 訪問?http://localhost:8888/hystrix.stream?,可看到和單實例監控界面入口一樣的面板界面。

此時,在 hystrix-dashboard 中使用集群監控的 URL 查看監控信息,在頁面第一個輸入框中輸入 hystrix-turbine 工程的訪問路徑:http://localhost:8889/turbine.stream

4.4? 進入實時監控顯示頁面可看到 ,剛才已經多次刷新過請求的 feign、ribbon 工程的運行狀況統計信息:

紅色 100% 表示 請求 seeParam 工程失敗。球體為紅色也表明服務健康狀態為最差。

4.5 啟動? seeParam 工程后,請求其接口:

再多次刷新 feign、ribbon 的請求后,分別請求到了 seeParam 的接口:

此時,再查看 hysteix-dashboard 中的服務統計信息:

失敗請求率為 0.0%,球體也變為綠色,表示服務運行正常。

至此,服務監控的集群模式也實現了。

-------------------------------------------------------------

下一篇:springCloud - 第14篇 -?

源碼見:

https://gitee.com/FJ_WoMenDeShiJie/springcloud-feign

https://gitee.com/FJ_WoMenDeShiJie/springcloud-ribbon

https://gitee.com/FJ_WoMenDeShiJie/springcloud-seeParam

https://gitee.com/FJ_WoMenDeShiJie/springcloud-hystrix-turbine

https://gitee.com/FJ_WoMenDeShiJie/springcloud-hystrix-dashboard

-------------------------------------------------------------

PS:這個系列不定時更新,只是個人的學習分享,

內容全程參考書目:

《Spring Cloud 與 Docker 微服務架構空實戰?》、

《Spring Cloud 微服務實戰》及此書作者博客:http://blog.didispace.com/spring-cloud-learning/

《深入理解 Spring Cloud 與微服務構建》及此書作者博客:https://blog.csdn.net/forezp/article/details/70148833

----------------------------------------------------------------
?

總結

以上是生活随笔為你收集整理的springCloud - 第13篇 - 服务监控 集群模式 Hystrix-turbine的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。