Hystrix Dashboard能对Hystrix进行实时监控,以有效的方式显示每个熔断器的运行状况。
从系统的整体运行状况来看,查看单个服务的Hystrix数据不是很有用,Turbine能将多个服务的数据显示到Hystrix Dashboard上。
Hystrix Dashboard
-
复制feign-hystrix-consumer项目重命名为hystrix-dashboard
-
添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 修改yml
server:
port: 8800
spring:
application:
#服务名称
name: hystrix-dashboard
eureka:
client:
#是否将自己注册到Eureka服务中
register-with-eureka: true
#是否从Eureka服务中获取注册信息
fetch-registry: true
#Eureka注册中心的地址,多个注册中心用,隔开
serviceUrl:
defaultZone: http://localhost:8761/eureka/
feign:
hystrix:
#开启熔断器功能
enabled: true
#将/actuator/hystrix.stream作为管理端点开放
management:
endpoints:
web:
exposure:
include: hystrix.stream
- 开启Hystrix Dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
@EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
- 测试
启动eureka-service和hystrix-dashboard项目,
访问http://localhost:8800/actuator/hystrix.stream,页面会不断的ping。
在另一个页面访问当前项目的接口http://localhost:8800/test,ping就会有数据了。
然后访问http://localhost:8800/hystrix,会看到以下页面
将http://localhost:8800/actuator/hystrix.stream填写到输入框,点击monitor。会出现以下页面
其实就是将http://localhost:8800/actuator/hystrix.stream里面的ping图形化了
Turbine
- 在hystrix-dashboard项目中添加一个application-dashboard2.yml文件
和application.yml文件一样,只是修改一下服务名和端口
server:
port: 8801
spring:
application:
#服务名称
name: hystrix-dashboard2
eureka:
client:
#是否将自己注册到Eureka服务中
register-with-eureka: true
#是否从Eureka服务中获取注册信息
fetch-registry: true
#Eureka注册中心的地址,多个注册中心用,隔开
serviceUrl:
defaultZone: http://localhost:8761/eureka/
feign:
hystrix:
#开启熔断器功能
enabled: true
#将/actuator/hystrix.stream作为管理端点开放
management:
endpoints:
web:
exposure:
include: hystrix.stream
启动hystrix-dashboard服务和hystrix-dashboard2服务
- 创建hystrix-dashboard-turbine项目
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>springcloud-demo</artifactId>
<groupId>demo.cloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hystrix-dashboard-turbine</artifactId>
<name>hystrix-dashboard-turbine</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
</project>
- 修改application.yml文件
server:
port: 8802
spring:
application:
#服务名称
name: hystrix-dashboard-turbine
eureka:
client:
#是否将自己注册到Eureka服务中
register-with-eureka: true
#是否从Eureka服务中获取注册信息
fetch-registry: true
#Eureka注册中心的地址,多个注册中心用,隔开
serviceUrl:
defaultZone: http://localhost:8761/eureka/
#defaultZone: http://peer1:8761/eureka/, http://peer2:8762/eureka/
turbine:
#监控的服务名称
app-config: hystrix-dashboard, hystrix-dashboard2
#集群名称
cluster-name-expression: "'default'"
#指定聚合哪些集群,默认default
aggregator:
cluster-config: default
- 开启Turbine
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class HystrixDashboardTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
}
}
- 测试
访问http://localhost:8802/hystrix,输入http://localhost:8802/turbine.stream点击monitor
项目路径
作者公众号