Spring Cloud(八)断路器仪表盘(Hystrix Dashboard)

一、Hystrix Dashboard简介

在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。

二、实战

本文以介绍基于Ribbon实现Hystrix Dashboard。通过改造ribbon-consumer实现:关联文章

2.1 pom添加依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

2.2 更新启动类

添加注解EnableHystrixDashboard

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrixDashboard
public class FeignConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(FeignConsumerApplication.class, args);
	}
}

2.3 更新配置文件

server.port=8083
spring.application.name=ribbon-consumer
eureka.client.service-url.defaultZone = http://localhost:8080/eureka/

#management.endpoints.web.exposure.include=hystrix-stream
management.endpoints.web.exposure.include=*

基于spring boot2.0(与之前版本有不同),添加management.endpoints.web.exposure.include

三、Hystrix Dashboard图形展示

3.1 启动Euraka Server,ribbon-consumer,euraka-client,打开http://localhost:8083/hystrix,进入Dashbord:
Spring Cloud(八)断路器仪表盘(Hystrix Dashboard)
然后进入监控页面:
Spring Cloud(八)断路器仪表盘(Hystrix Dashboard)

访问路径:http://localhost:8083/hi/payne
随着访问次数的变动,Dashbord会有变化。
Spring Cloud(八)断路器仪表盘(Hystrix Dashboard)
3.2 stop eureka-client,再次访问,系统将采用熔断机制
Dahsboard 每个点鼠标悬浮的时候就会有对应的数据说明信息:
Spring Cloud(八)断路器仪表盘(Hystrix Dashboard)
在监控的界面有两个重要的图形信息:一个实心圆和一条曲线。

  • 实心圆:1、通过颜色的变化代表了实例的健康程度,健康程度从绿色、黄色、橙色、红色递减。2、通过大小表示请求流量发生变化,流量越大该实心圆就越大。所以可以在大量的实例中快速发现故障实例和高压实例。
  • 曲线:用来记录2分钟内流浪的相对变化,可以通过它来观察流量的上升和下降趋势。

GitHub项目地址:https://github.com/PayneYu/spring-cloud-study