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这个微服务注册到Eureka上,当然了也可以不注册。
我们在父工程的maven上右键新建module , 起名为 micorservice-hystrix-dashboard
<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
同时我们也打算注册到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);
}
}
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}}
因为我们注册到了Eureka上,所以需要先启动microservice-discovery-eureka,然后再启动该服务,启动成功后,访问 http://localhost:8888/hystrix
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