每天學點SpringCloud(十一):Hystrix儀表盤

在SpringCloud學習系列博客第六篇文章中,我們已經學習了Hystrix的使用,但是那篇文章中有一點遺漏沒有講,那就是Hystrix Dashboard ,它可以實時的監控Hystrix的運行情況。


我們先來看一下使用Hystrix Dashboard我們可以得到多少有用的信息呢?

1

這些狀態對我們定位問題還是比較有幫助的,那麼我們來看一下如何使用它吧

1.引入依賴

1
2
3
4
5
6
7
8
9
10
11
12
<dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
      </dependency>
      <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>

hystrix依賴主要是hystrix核心功能依賴,dashboard是爲我們提供儀表盤面板的頁面功能的,actuator是用來暴露dashboard所需要的端口的。

2.啓用hystrix儀表盤

在啓動類增加註解@EnableHystrixDashboard。

1
2
3
4
5
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableFeignClients
@EnableHystrix

3.修改actuator配置

默認的時候actuator是沒有開啓hystrix的端口的,所以我們需要在配置文件中增加一些配置來開啓這個端口。

1
2
3
4
5
6
7
8
management:
 endpoints:
   web:
     exposure:
       include: '*'
feign:
 hystrix:
   enabled: true

上方的配置如果不明白的話可以參考:SpringCloud監控

4.使用

訪問ip:端口/hystrix,我們可以看到如下界面
1
這個是Dashboard的歡迎頁面,第一個文本框是hystrix監控頁面的地址。此地址默認是/hystrix.stream,然後還會被actuator的路徑所影響,比如說,我的actuator默認路徑/actuator,所以我輸入訪問地址爲:  ip:端口/actuator/hystrix.stream。
第二個文本框爲間隔更新數據時間,第三個是此次監控起的一個名字。


上方信息輸入完成後點擊monitor後我們就可以看到文章開頭圖片描述的頁面了。


GitHub地址:https://github.com/shiyujun/spring-cloud-demo。代碼所在模塊:cloud-demo-consumer-feign-hystrix

如果對您有所幫助,請記得幫忙點一個star哦

本文出自http://zhixiang.org.cn,轉載請保留。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章