5Hystrix Dashboard · SpringCloud微服务实战 · 看云
5. Hystrix Dashboard
导航
本节代码地址
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-feign
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-client/fw-cloud-client-eureka
GitHub: https://github.com/xuyisu/fw-sping-cloud/tree/master/fw-cloud-hystrix/fw-cloud-hystrix-dashboard
Hystrix提供了对于微服务调用状态的监控信息,需要结合spring-boot-actuator模块一起使用。Hystrix Dashboard主要用来实时监控Hystrix的各项指标信息。通过Hystrix Dashboard反馈的实时信息,可以帮助我们快速发现系统中存在的问题
已下是官方展示的图片
下面我们要做的就是展示和这个类似的监控出来。
5.1 新建项目
5.2 maven配置
主要需要加入spring-cloud-starter-netflix-hystrix-dashboard的包,并且不需要配置什么信息,但是被监控的项目需要添加spring-boot-starter-actuator用于提供应用健康信息。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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>
</dependencies>
5.3 新建启动类
启动类上加上@EnableHystrixDashboard注解
@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication
public class FwHystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(FwHystrixDashboardApplication.class, args);
}
}
5.4 配置应用信息
server:
port: 8677
spring:
application:
name: fw-hystrix-feign-dashboard
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
5.5 项目启动
5.6 如何使用呢?
从页面上的文件内容我们可以知道,Hystrix Dashboard共支持三种不同的监控方式:
默认的集群监控: http://turbine-hostname:port/turbine.stream
指定的集群监控: http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
单体应用的监控: http://hystrix-app:port/actuator/hystrix.stream
页面上面的几个参数局域
最上面的输入框: 输入上面所说的三种监控方式的地址,用于访问具体的监控信息页面。
Delay: 该参数用来控制服务器上轮询监控信息的延迟时间,默认2000毫秒。
Title: 该参数对应头部标题Hystrix Stream之后的内容,默认会使用具体监控实例的Url。
我们先来看下单个服务实例的监控,从http://hystrix-app:port/actuator/hystrix.stream连接中可以看出,Hystrix Dashboard监控单节点实例需要访问实例的actuator/hystrix.stream接口
5.6.1 下面我们来看一下具体的监控信息
在输入框输入 http://localhost:8676/actuator/hystrix.stream其他默认,注意不要输错
如果出现以下界面
原因如下:
- 地址输入的不正确
- 被监控的服务没有添加
spring-boot-starter-actuator的包 - 没有对外暴露被监控的端点
为了方便,我们将它全部暴露出来,生产可以根据需要确定暴露的端点或者不暴露。
management:
endpoints:
web:
exposure:
include: '*'
需要注意的是
Spring Boot 2.0之后所有对外暴露的端点都加上/actuator前缀
5.6.2 正确姿势后的显示
可以看到监控信息出现了,需要连续请求几次localhost:8676/feignInfo接口
具体每个状态什么意思,直接拿官方的图片来看,看不懂应该的可以翻译一下。






