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


在这里插入图片描述

概述

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: 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

在这里插入图片描述

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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小工匠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值