欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > javascript >内容正文

javascript

Spring Cloud【Finchley】-12使用Hystrix Dashboard实现Hystrix数据的可视化监控

发布时间:2025/3/21 javascript 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Spring Cloud【Finchley】-12使用Hystrix Dashboard实现Hystrix数据的可视化监控 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章目录

  • 概述
  • Hystrix Dashboard
    • Step 1 新建项目
    • Step2 增加maven依赖
    • Step3 启动类增加注解@EnableHystrixDashboard
    • Step4 配置文件application.yml
    • Step5 启动微服务
    • Step6 测试
  • 代码

概述

Spring Cloud【Finchley】-11Feign项目整合Hystrix监控中,我们通过 http://ip:port/actuator/hystrix.stream 的形式来查看到的Hystrix的数据都是文本形式,可读性非常差。 好在Spring Cloud为我们提供了Hystrix Dashboard,来看下如何使用吧。

官方文档: https://cloud.spring.io/spring-cloud-static/Finchley.SR2/single/spring-cloud.html#_circuit_breaker_hystrix_dashboard


Hystrix Dashboard

为了方便统一管理,这里的例子我们也将Hystrix Dashboard这个微服务注册到Eureka上,当然了也可以不注册。


Step 1 新建项目

我们在父工程的maven上右键新建module , 起名为 micorservice-hystrix-dashboard

如下


Step2 增加maven依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency>

我们打算注册到Eureka上,所以也需要添加spring-cloud-starter-netflix-eureka-client


Step3 启动类增加注解@EnableHystrixDashboard

同时我们也打算注册到Eureka上,所以也需要添加@EnableDiscoveryClient注解

package com.artisan.micorservice;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;@SpringBootApplication @EnableDiscoveryClient @EnableHystrixDashboard public class MicorserviceMovieRibbonHystrixDashboard {public static void main(String[] args) {SpringApplication.run(MicorserviceMovieRibbonHystrixDashboard.class, args);} }

Step4 配置文件application.yml

server:port: 8888spring:application:name: micorservice-hystrix-dashboard#eureka eureka:client:service-url:defaultZone: http://artisan:artisan123@localhost:8761/eurekainstance:prefer-ip-address: true # 起码点击后 会看到ip信息instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}

Step5 启动微服务

因为我们注册到了Eureka上,所以需要先启动microservice-discovery-eureka,然后再启动该服务,启动成功后,访问 http://localhost:8888/hystrix

Step6 测试

  • 继续启动服务提供者微服务 micorservice-provider-user,
  • 然后启动整合了Hystrix的消费者微服务 micorservice-consumer-movie-ribbon-hystrix 和 micorservice-consumer-movie-fegin-hystrix

到Eureka上看下注册的服务列表

micorservice-consumer-movie-fegin-hystrix 对应的hystrix url为:http://localhost:7901/actuator/hystrix.stream

micorservice-consumer-movie-ribbon-hystrix 对应的hystrix url为:
http://localhost:7902/actuator/hystrix.stream

分别输入url和自定义的title

点击Monitor Stream 进入, 一直处于loading状态

是因为还没有触发hystrix,我们来调用这俩微服务提供的对外接口

访问下 http://localhost:7901/movie/1 触发hystrix收集信息,多访问几次,信息如下

访问下 http://localhost:7902/movie/2 触发hystrix收集信息 ,多访问几次

以上就实现了通过Dashboard 对单个节点的微服务进行近乎实时的可视化监控。

上图中的参数说明参考官网 https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki:


代码

https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-hystrix-dashboard

总结

以上是生活随笔为你收集整理的Spring Cloud【Finchley】-12使用Hystrix Dashboard实现Hystrix数据的可视化监控的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。