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月前
|
Prometheus 监控 Java
如何全面监控所有的 Spring Boot 微服务
如何全面监控所有的 Spring Boot 微服务
148 3
|
4月前
|
监控 Java 对象存储
监控与追踪:如何利用Spring Cloud Sleuth和Netflix OSS工具进行微服务调试
监控与追踪:如何利用Spring Cloud Sleuth和Netflix OSS工具进行微服务调试
83 1
|
5月前
|
XML 监控 Java
Spring Cloud全解析:熔断之Hystrix简介
Hystrix 是由 Netflix 开源的延迟和容错库,用于提高分布式系统的弹性。它通过断路器模式、资源隔离、服务降级及限流等机制防止服务雪崩。Hystrix 基于命令模式,通过 `HystrixCommand` 封装对外部依赖的调用逻辑。断路器能在依赖服务故障时快速返回备选响应,避免长时间等待。此外,Hystrix 还提供了监控功能,能够实时监控运行指标和配置变化。依赖管理方面,可通过 `@EnableHystrix` 启用 Hystrix 支持,并配置全局或局部的降级策略。结合 Feign 可实现客户端的服务降级。
318 23
|
5月前
|
Java 对象存储 开发者
故障隔离与容错处理:Hystrix在Spring Cloud和Netflix OSS中的应用
故障隔离与容错处理:Hystrix在Spring Cloud和Netflix OSS中的应用
85 3
|
7月前
|
监控 druid Java
spring boot 集成配置阿里 Druid监控配置
spring boot 集成配置阿里 Druid监控配置
357 6
|
6月前
|
Java Spring 监控
Spring Boot Actuator:守护你的应用心跳,让监控变得触手可及!
【8月更文挑战第31天】Spring Boot Actuator 是 Spring Boot 框架的核心模块之一,提供了生产就绪的特性,用于监控和管理 Spring Boot 应用程序。通过 Actuator,开发者可以轻松访问应用内部状态、执行健康检查、收集度量指标等。启用 Actuator 需在 `pom.xml` 中添加 `spring-boot-starter-actuator` 依赖,并通过配置文件调整端点暴露和安全性。Actuator 还支持与外部监控工具(如 Prometheus)集成,实现全面的应用性能监控。正确配置 Actuator 可显著提升应用的稳定性和安全性。
231 0
|
7月前
|
监控 Java 微服务
Spring Boot微服务部署与监控的实战指南
【7月更文挑战第19天】Spring Boot微服务的部署与监控是保障应用稳定运行和高效维护的重要环节。通过容器化部署和云平台支持,可以实现微服务的快速部署和弹性伸缩。而利用Actuator、Prometheus、Grafana等监控工具,可以实时获取应用的运行状态和性能指标,及时发现并解决问题。在实际操作中,还需根据应用的具体需求和场景,选择合适的部署和监控方案,以达到最佳效果。
|
7月前
|
监控 Dubbo 应用服务中间件
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
通用快照方案问题之Sentinel与SpringCloud和Dubbo的整合如何解决
65 0
|
7月前
|
Prometheus 监控 数据可视化
通用快照方案问题之Hystrix进行指标监控如何解决
通用快照方案问题之Hystrix进行指标监控如何解决
60 0
|
存储 安全 NoSQL
Spring中国教育管理中心-Apache Cassandra 的 Spring 数据教程十四
Spring中国教育管理中心-Apache Cassandra 的 Spring 数据教程十四