SpringCloud的可视化熔断器监控Hystrix Dashboard

Hystrix Dashboard 是 Hystrix 的仪表盘组件,提供了数据监控,可以实时监控 Hystrix 的各个指标,例如:
   各Hystrix Command的请求响应时间, 请求成功率等数据,然后通过图形化界面展示出来

创建一个子模块hystrix-dashboard

 启用Hystrix Dashboard步骤:

 1~4步骤是在子模块hystrix-dashboard中操作
   1.修改子模块hystrix-dashboard与springcloud04添加父子模块引用
     注1:hystrix-dashboard是个独立的服务,不用注册到 Eureka server 
   2.添加依赖,(添加至主模块springcloud04,这样其它子模块均可引用):
     <dependency>
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
     </dependency>
     <dependency>
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
     注1:引用的依赖可以使用“https://start.spring.io/”搜索“hystrix/dashboard/actuator”即可
   3.启动类添加如下注解
     @EnableHystrixDashboard//启用熔断器仪表盘
   4.修改application.yml
     server.port=7401
     spring.application.name=hystrix-dashboard 

5~7步骤是在子模块eureka-consumer中操作
   5.添加依赖,此依赖是打开Actuator(但此依赖已在步骤2被导入父模块springcloud04,所以可省略) 
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
   6.启动类添加如下注解
     @EnableCircuitBreaker//启动断路器
   
     注1:如果是 spring boot 是低版本(1.x),到此配置就已经完成了,启动后就可以看到效果了,
          但是此项目使用的 spring boot 版本是 2.X,在 spring boot 升为 2.0 后,为了安全,
          默认 Actuator 只暴露了2个端点,heath 和 info,所以我们的配置还没有完成,下面继续
   7.修改application.yml添加如下配置
     # 熔断器DashBoard: actuator在boot2.0调整后开关web端点的配置,*代表开启所有
     management.endpoints.web.exposure.include="*"  
    
     注1:* 在YAML中有特殊的含义,所以如果想使用include或者exclude包含所有的端点时要加上双引号 
     注2:由于端点可能包含敏感信息,应该仔细的考虑什么时候暴露它们

至此,配置已经完成,依次启动
     eureka-cluster1
     eureka-cluster2
     eureka-provider1
     eureka-provider2
     hystrix-dashboard
     eureka-consumer
     然后访问“http://localhost:7401/hystrix”,即可跳至“熔断器仪表板”界面
     注1:此界面有3个不同的请求地址,前两个是对于集群模式使用的,最后一个是单节点模式使用的,
          此篇配置的是单节点模式,所以在页面的地址栏输入 http://localhost:7301/actuator/hystrix.stream,
          再点击“Monitor Stream”按钮即可

http://localhost:7301/actuator/hystrix.stream中的7301是消费者,也就是eureka-consumer的端口号

效果图如下:

发布了62 篇原创文章 · 获赞 6 · 访问量 2564

猜你喜欢

转载自blog.csdn.net/qq_44424498/article/details/103582734