Hystrix ダッシュボードには、各サーキット ブレーカー (@HystrixCommand で注釈が付けられたメソッド) のステータス、リクエスト数、成功数、失敗数、低下数などの Hystrix 関連データを表示できます。
序文
通常状態はUP、トリップ状態はCIRCUIT_OPENとなっており、/healthから確認できますが、前提としてSpringBootのアクチュエータ(ヘルスモニタリング)がプロジェクトに導入されている必要があります。親プロジェクトに追加されました
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
ダッシュボード制御 ダッシュボードの準備
環境を整える
- m-parent に基づいて新しいモジュール mvn プロジェクトを作成する
m-cloud-hystrix-dashboard-9000
- 依存関係をインポートする
<dependencies>
<!--hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--hystrix 仪表盘-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
@EnableHystrixDashboard
アクティベーション ダッシュボードを追加するクラスを開始します
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrixDashboard //开启HystrixDashboard
public class HystrixDashboard9000 {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboard9000.class, args);
}
}
- アプリケーション.yml
server:
port: 9000
spring:
application:
name: m-cloud-hystrix-dashboard
#注册发现
eureka:
client:
service-url:
defaultZone: http://CloudEurekaServerA:8761/eureka,http://CloudEurekaServerB:8762/eureka
instance:
prefer-ip-address: true
instance-id: ${
spring.cloud.client.ip-address}:${
spring.application.name}:${
server.port}:@project.version@
- 監視対象のマイクロサービスに監視サーブレットを登録します (例: m-service-autodeliver)
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new
HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new
ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
- プロジェクトを開始し、http://localhost:8090/actuator/hystrix.stream
postMan にアクセスしてコンシューマ サービスを呼び出します。
- アクセス テストhttp://localhost:9000/hystrix
8. postMan はコンシューマ サービスの再試行を呼び出します
ダッシュボードの解釈
パーセンテージ、10 秒以内のエラー リクエストの割合。
黒丸:
サイズ: リクエスト トラフィックのサイズを表します。トラフィックが多いほど、ボールも大きくなります。
色: リクエスト処理の健全性ステータスを表し、緑から赤に減少します。緑赤色は非常に不健全な
曲線変動グラフ:
この方法でのトラフィックの変動グラフを 2 分以内に記録し、トラフィックの上昇傾向または下降傾向を判断します。
ダッシュボード集約監視の解釈
以前は、Hystrix データ クエリとマイクロサービス インスタンスの分析に焦点を当てていましたが、マイクロサービス アーキテクチャでは、マイクロサービスインスタンス 1 (hystrix) ip1 :port1/actuator/hystrixの自動配信など、マイクロサービスの複数のインスタンス (クラスター化) が存在することがよくあります
。.streamインスタンス 2 (hystrix) ip2:port2/actuator/hystrix.streamインスタンス 3 (hystrix) ip3:port3/actuator/hystrix.stream既存の方法に従い、ダッシュボードと組み合わせることができます 監視データを入力するたびにフロー URL にアクセスして、手動操作を自動機能に置き換えることができるかどうかを確認してください。Hystrix Turbine アグリゲーション (各インスタンスの hystrix モニタリング データの集約) モニタリングTurbine (Turbine)の考え方: マイクロサービス アーキテクチャでは、マイクロサービスは多くの場合複数のインスタンスをデプロイします。一度に 1 つのインスタンスのモニタリングしか表示できない場合は、次のことを行う必要があります。このようなシナリオでは、Hystrix Turbine を集約監視に使用すると、関連するマイクロサービスの監視データを集約して見やすくすることができます。
環境を整える
- m-parent に基づいて新しいモジュール mvn プロジェクトを作成する
m-cloud-hystrix-turbine-9001
- 依存関係をインポートする
<dependencies>
<!--hystrix turbine聚合监控-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
@EnableTurbine
アクティベーション ダッシュボードを追加するクラスを開始します
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine //开启 Turbine
public class HystrixTurbine9001 {
public static void main(String[] args) {
SpringApplication.run(HystrixTurbine9001.class,args);
}
}
- アプリケーション.yml
server:
port: 9001
spring:
application:
name: m-cloud-hystrix-turbine
#注册发现
eureka:
client:
service-url:
defaultZone: http://CloudEurekaServerA:8761/eureka,http://CloudEurekaServerB:8762/eureka
instance:
prefer-ip-address: true
instance-id: ${
spring.cloud.client.ip-address}:${
spring.application.name}:${
server.port}:@project.version@
#turbine配置
turbine:
# appCofing配置需要聚合的服务名称,⽐如这⾥聚合⾃动投递微服务的hystrix监控数据
# 如果要聚合多个微服务的监控数据,那么可以使⽤英⽂逗号拼接,⽐如 a,b,c
appConfig: m-service-autodeliver
clusterNameExpression: "'default'" # 集群默认名称
-
ブラウザで Turbine プロジェクトhttp://localhost:9001/turbine.streamにアクセスすると、監視データが表示されます (postMan の再試行データはありません)。
-
ダッシュボード ページからデータを表示する方が直感的で、ダッシュボードのアドレス バーに入力したアドレスを入力します。
-
m-service-autodeliver-8090 をコピーして m-service-autodeliver-8091 に変更し、m-parent プロジェクトに追加します。postMan は 8090 と 8091 のインターフェイスにアクセスします。
-
サービスを再起動し
、上記のサービスを順番に停止します (再起動順序は 8090-8091-9000-9001)。 -
アクセスインターフェース
-
モニタリングページ