在SpringCloud学习系列博客第六篇文章中,我们已经学习了Hystrix的使用,但是那篇文章中有一点遗漏没有讲,那就是Hystrix Dashboard ,它可以实时的监控Hystrix的运行情况。


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

每天学点SpringCloud(十一):Hystrix仪表盘

这些状态对我们定位问题还是比较有帮助的,那么我们来看一下如何使用它吧

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,我们可以看到如下界面
每天学点SpringCloud(十一):Hystrix仪表盘
这个是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,转载请保留。

相关文章:

  • 2021-12-25
  • 2021-11-16
  • 2022-01-04
  • 2022-12-23
  • 2021-12-17
  • 2021-06-02
  • 2021-07-24
  • 2021-12-08
猜你喜欢
  • 2021-07-04
  • 2021-08-27
  • 2021-09-19
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案