Hystrix Dashboard (断路器:hystrix 仪表盘)
Hystrix一个很重要的功能是,可以通过HystrixCommand收集相关数据指标. Hystrix Dashboard可以很高效的现实每个断路器的健康状况。
1)加入依赖
在Ribbon服务和Feign服务的Maven工程的pom.xml中添加
1 | <dependency> |
spring-boot-starter-actuator用于手机metric, 支持hystrix.stream。spring-cloud-starter-netflix-hystrix-dashboard支持dashboard的UI
2)添加注解
在Spring Boot启动类上用@EnableHystrixDashboard注解和@EnableCircuitBreaker注解。需要特别注意的是我们之前的Feign服务由于内置断路器支持, 所以没有@EnableCircuitBreaker注解,但要使用Dashboard则必须加,如果不加,Dashboard无法接收到来自Feign内部断路器的监控数据,会报“Unable to connect to Command Metric Stream”错误
1 | package org.cwalzy.springcloudeureka; |
3)然后就可以访问/hystrix,这个URL将dashboard指向定义在Hystrix客户端应用中的 /actuator/hystrix.stream
在dashboard中输入服务的URL:点击 monitor后进入监控界面,访问我们之前创建的Ribbon服务localhost:8901/, 或者Feign服务localhost:8902/可以看到监控UI动态变化
利用Turbine在一个Dashboard上监控多个流
以上例子只能监控一个,要同时监控多个流怎么办? 答案是, 可以单独做一个Turbine服务,专门监控所有断路器状态,从而掌握整个系统中所有微服务的状态。下面我们就来创建一个Turbine服务,来监控我们之前做的Feign服务和Ribbon服务
1). 创建一个maven工程, 在pox.xml添加以下依赖
1 | <dependency> |
整个个pox.xml文件如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.cwalzy</groupId>
<artifactId>springcloud.helloworld.turbine.service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springcloud.helloworld.turbine.service</name>
<description>Turbine service demo</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
<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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2). 创建Turbine Dashboard启动类:
用@EnableHystrixDashboard和@EnableTurbine修饰主类, 分别用于支持Hystrix Dashboard和Turbine
1 | package org.cwalzy.ribbon; |
3). 在application.yml中配置turbine参数
1 | eureka: |
turbine.appConfig定义了要监控的服务,这里是我们在前面章节创建的service-feign和sercice-ribbon; aggregator.clusterConfig定义了聚合方式, 此处为default.
1 | turbine.appConfig :配置Eureka中的serviceId列表,表明监控哪些服务 |
4)启动服务
依次启动eureka服务, 2个Helloworld服务, Feign服务,ribbon服务和刚创建turbine服务。从eureka服务中我们可以看到
5)通过Turbine服务访问HystrixDashborad, http:localhost:8903/hystrix

监控流的URL填 http://localhost:8903/turbine.stream , 点击monitor stream, 进入监控页面, 随便刷新下feign和ribbon服务( http://localhost:8902/hello 和 http://localhost:8901 ), 可以看到监控页面的变化。如下图, 两个服务的监控都会显示在dashboard上
参考:
http://projects.spring.io/spring-cloud/spring-cloud.html#_circuit_breaker_hystrix_dashboard
http://blog.csdn.net/ityouknow/article/details/72625646
本文转载自 https://www.cnblogs.com/chry/p/7286601.html
原文基于 spring boot 1.5.3.RELEASE 版本
而本文中有一些改动 是基于 spring boot 2.1.5.RELEASE 版本