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

版权声明:【show me the code ,change the world】 https://blog.csdn.net/yangshangwei/article/details/85316166

概述

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/yangshangwei/SpringCloudMaster/tree/master/micorservice-hystrix-dashboard

猜你喜欢

转载自blog.csdn.net/yangshangwei/article/details/85316166
今日推荐