SpringCloud微服務(04):Turbine組件,實現微服務集群監控


本文源碼:GitHub·點這里 || GitEE·點這里

寫在前面,閱讀本文前,你需要了解熔斷器相關內容
SpringCloud微服務:Hystrix組件,實現服務熔斷

一、聚合監控簡介

1、Dashboard組件

微服務架構中為了保證程序的可用性,防止程序出錯導致網絡阻塞,出現了斷路器模型。斷路器的狀況反應程序的可用性和健壯性,它是一個重要指標。HystrixDashboard是作為斷路器狀態的一個組件,提供了數據監控和直觀的圖形化界面。

2、Turbine組件

Hystrix Dashboard組件監控服務的熔斷情況時,每個服務都有圖形界面,當微服務數量很多時,監控非常繁雜.為了同時監控多個服務的熔斷狀況,Netflix開源了Hystrix的另一個組件Turbine.Turbine用於聚合多個Hystrix Dashboard監控,將多個Hystrix Dashboard組件的數據聚集在一個面板展示,集中監控。

3、案例結構

聚合監控服務
node04-monitor-7002
注冊中心
node04-eureka-7001
兩個服務提供者,都配置了熔斷器,和Dashboard組件
node04-provider-6001
node04-provider-6002

二、Dashboard組件

這個組件是針對單個微服務的監控的。具體使用流程如下。

1、注解和依賴

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>

啟動類注解

  • @EnableHystrix
  • @EnableHystrixDashboard

2、啟動下面兩個服務

node04-eureka-7001
node04-provider-6001

3、訪問指定接口

1)、訪問配置的熔斷接口
http://localhost:6001/getInfo
2)、打開數據面板
http://localhost:6001/hystrix.stream
可以看到一些具體的數據,類似打印日志的方式,展現上面接口的執行信息。
3)、打開圖形面板
http://localhost:6001/hystrix
查看配置監控信息。

刷新幾次上面配置的熔斷接口,查看效果。

三、Turbine組件

node04-monitor-7002 聚合監控服務,聚集6001,和6002兩個服務的監控。

1、依賴和注解

1)、服務提供者新增依賴

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2)、聚合服務依賴

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

啟動類注解

  • @EnableTurbine

2、啟動服務

依次啟動注冊中心,兩個服務提供者,最后啟動聚合監控中心。

3、操作流程

1)、打開監控面板
進行如下配置

2)、刷新兩個服務的熔斷接口

http://localhost:6001/getInfo
http://localhost:6002/getInfo

查看上面面板的監控信息如下。

聚合監控服務流程就是這樣了。

四、源代碼說明

GitHub·地址
https://github.com/cicadasmile/spring-cloud-base
GitEE·地址
https://gitee.com/cicadasmile/spring-cloud-base


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM