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

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

20190806093230928.jpg


概述


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

如下


20181228002401785.png

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: 8888
spring:
  application:
    name: micorservice-hystrix-dashboard
#eureka
eureka:
  client:
    service-url:
      defaultZone: http://artisan:artisan123@localhost:8761/eureka
  instance:
    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


20181228003018178.png


Step6 测试


继续启动服务提供者微服务 micorservice-provider-user,

然后启动整合了Hystrix的消费者微服务 micorservice-consumer-movie-ribbon-hystrix 和 micorservice-consumer-movie-fegin-hystrix


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


20181228003353812.png


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


20181228003640609.png

20181228003719142.png

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



20181228003757459.png

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

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



20181228003954102.png


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

20181228004047199.png

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


2019030322550097.png

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



20190112103817663.png


代码


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

相关文章
|
2月前
|
Java UED 开发者
Spring Boot 降级功能的神秘面纱:Hystrix 与 Resilience4j 究竟藏着怎样的秘密?
【8月更文挑战第29天】在分布式系统中,服务稳定性至关重要。为应对故障,Spring Boot 提供了 Hystrix 和 Resilience4j 两种降级工具。Hystrix 作为 Netflix 的容错框架,通过隔离依赖、控制并发及降级机制增强系统稳定性;Resilience4j 则是一个轻量级库,提供丰富的降级策略。两者均可有效提升系统可靠性,具体选择取决于需求与场景。在面对服务故障时,合理运用这些工具能确保系统基本功能正常运作,优化用户体验。以上简介包括了两个工具的简单示例代码,帮助开发者更好地理解和应用。
42 0
|
24天前
|
XML 监控 Java
Spring Cloud全解析:熔断之Hystrix简介
Hystrix 是由 Netflix 开源的延迟和容错库,用于提高分布式系统的弹性。它通过断路器模式、资源隔离、服务降级及限流等机制防止服务雪崩。Hystrix 基于命令模式,通过 `HystrixCommand` 封装对外部依赖的调用逻辑。断路器能在依赖服务故障时快速返回备选响应,避免长时间等待。此外,Hystrix 还提供了监控功能,能够实时监控运行指标和配置变化。依赖管理方面,可通过 `@EnableHystrix` 启用 Hystrix 支持,并配置全局或局部的降级策略。结合 Feign 可实现客户端的服务降级。
101 23
|
9天前
|
Java 对象存储 开发者
故障隔离与容错处理:Hystrix在Spring Cloud和Netflix OSS中的应用
故障隔离与容错处理:Hystrix在Spring Cloud和Netflix OSS中的应用
26 3
|
2月前
hystrix.stream dashboard
hystrix.stream dashboard
29 3
|
2月前
|
XML 前端开发 数据库
SpringCloud+Vue3主子表插入数据
SpringCloud+Vue3主子表插入数据
40 0
|
2月前
|
XML 前端开发 数据库
SpringCloud+Vue3主子表插入数据
SpringCloud+Vue3主子表插入数据
26 0
|
3月前
|
监控 Dubbo 应用服务中间件
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
39 0
|
3月前
|
Prometheus 监控 数据可视化
通用快照方案问题之Hystrix进行指标监控如何解决
通用快照方案问题之Hystrix进行指标监控如何解决
38 0
|
4月前
|
监控 Java 微服务
Spring Cloud 之 Hystrix
Spring Cloud Hystrix 是一个用于处理分布式系统延迟和容错的库,防止雪崩效应。它作为断路器,当服务故障时通过监控短路,返回备用响应,保持系统弹性。主要功能包括服务降级和熔断:
|
4月前
|
监控
springCloud之Hystrix监控
springCloud之Hystrix监控
下一篇
无影云桌面