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

网友投稿 646 2022-05-30

文章目录

概述

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依赖

org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-netflix-hystrix-dashboard

我们打算注册到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

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

Spring Spring Cloud

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ROS2编程基础课程--教程
下一篇:「免费开源」基于Vue和Quasar的crudapi前端SPA项目实战之数据导出(十三)
相关文章