天天看點

第九篇: 斷路器監控(Hystrix Dashboard)

在第三篇:斷路器(Hystrix)講述了如何使用斷路器,并簡單的介紹了下Hystrix Dashboard元件,這篇文章更加詳細的介紹Hystrix Dashboard。

一、Hystrix Dashboard簡介

在微服務架構中為例保證程式的可用性,防止程式出錯導緻網絡阻塞,出現了斷路器模型。斷路器的狀況反應了一個程式的可用性和健壯性,它是一個重要名額。Hystrix Dashboard是作為斷路器狀态的一個元件,提供了資料監控和友好的圖形化界面。

二、準備工作

本文的的工程栗子,來源于第一篇: 服務的注冊 内的 eureka服務和 第二篇: 服務消費者(Feign)内的feign服務為引用,在它的基礎上進行改造。

三、開始改造 leopard-service-feign

在pom的工程檔案引入相應的依賴(必須):

<!-- 監控 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- hystrix 依賴 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<!-- hystrix web 視圖檢視 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
		</dependency>
           

在程式的入口FeignServiceApplication類,加上@EnableHystrix注解開啟斷路器,這個是必須的,并且需要在程式中聲明斷路點HystrixCommand;加上@EnableHystrixDashboard注解,開啟HystrixDashboard

package com.leopard.service.feign;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
 
@EnableDiscoveryClient
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
@EnableHystrix
@EnableHystrixDashboard
public class FeignServiceApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(FeignServiceApplication.class, args);
	}
}
           

運作程式: 依次開啟 leopard-eureka 和 leopard-service-feign.

四、Hystrix Dashboard圖形展示

打開 http://localhost:8181/hystrix.stream,可以看到一些具體的資料:

第九篇: 斷路器監控(Hystrix Dashboard)

打開http://localhost:8181/hystrix 可以看見以下界面:

并依次輸入  http://localhost:8181/hystrix.stream 、2000 、service-feign

第九篇: 斷路器監控(Hystrix Dashboard)

确認後可以看到如下界面:

第九篇: 斷路器監控(Hystrix Dashboard)

這個時候,再打開一個新視窗,通路 http://localhost:8181/test/getPort     ,可以看到

第九篇: 斷路器監控(Hystrix Dashboard)

此時回到,上一個視窗可以看到

第九篇: 斷路器監控(Hystrix Dashboard)

再回到上上層,一開始 打開的 http://localhost:8181/hystrix.stream 頁面,可以看到已經加載到資料的監控頁面資訊:

第九篇: 斷路器監控(Hystrix Dashboard)

到此就完成了監控搭建。

文章轉載:https://blog.csdn.net/forezp/article/details/70217283

文章參考:

https://www.cnblogs.com/chenweida/p/9025589.html

https://blog.csdn.net/qiuqiangqiang/article/details/80273091