一:Hystrix Dashboard簡介
在微服務架構中爲例保證程序的可用性,防止程序出錯導致網絡阻塞,出現了斷路器模型。斷路器的狀況反應了一個程序的可用性和健壯性,它是一個重要指標。Hystrix Dashboard是作爲斷路器狀態的一個組件,提供了數據監控和友好的圖形化界面。
我們的工程基於上一篇文章中的工程,SpringBoot的版本爲2.0.3
二:斷路器監控的配置(基於SpringBoot2.0.3)
首先我們導入pom依賴,假如你的SpringBoot的版本爲2.0以下的版本,那麼pom只需要導入:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
但是假如你的SpringBoot的版本爲2.0以上的版本時候,比如我現在使用的是SpringBoot2.0.3版本,那麼就需要導入如下的依賴,否則,就會出現@EnableHystrixDashboard類找不到的情況。
<!--spring-cloud-starter-hystrix-dashboard的起步依賴-->
<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-dashboard</artifactId>
</dependency>
在主程序啓動類中加入@EnableHystrixDashboard註解,開啓hystrixDashboard。
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
@EnableHystrix
@EnableHystrixDashboard
public class MallManagerServiceApplication {
public static void main(String[] args) {
SpringApplication.run(MallManagerServiceApplication.class, args);
}
}
打開瀏覽器:訪問http://localhost:8011/hystrix,界面如下
當我們在輸入框當中輸入:http://localhost:8011/hystrix.stream,Title裏面輸入Hystrix,卻出現瞭如下的界面:
頁面提示Unable to connect to Command Metric Stream。
如何解決?
我們只需要在application.yml配置文件當中引入如下配置:注意最後的*一定要加上引號,不然會啓動報錯。
#management.endpoints.web.exposure.include=*
management:
endpoints:
web:
exposure:
include: "*"
我們輸入框當中輸入的不能是http://localhost:8011/hystrix.stream,而是http://localhost:8011/actuator/hystrix.stream
再次進入頁面,發現一直在顯示Loading....
這個時候,我們只需要去訪問幾次提供熔斷的方法就可以解決了,因爲現在我們還沒有訪問過熔斷的方法,系統找不到數據。
我們多訪問幾次熔斷方法,比如上一篇文章當中:http://localhost:8011/sayHelloAA,刷新儀表盤,看到如下頁面。