一、简介
Hystrix Dashboard是Hystrix熔断器的一个组件,它未用户提供了相对友好的图形化界面来监控接口访问数据。下面我们通过demo来学习。
二、通过demo学习
新建一个dashboard-service项目。
1、pom.xml依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
2、application.properties配置
server.port=9095
spring.application.name=dashboard-service
hystrix.dashboard.proxy-stream-allow-list=*
3、项目代码
package com.example.dashboardservice9095;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@SpringBootApplication
public class DashboardService9095Application {
// http://localhost:9095/hystrix
// http://localhost:7070/actuator/hystrix.stream
public static void main(String[] args) {
SpringApplication.run(DashboardService9095Application.class, args);
}
}
三、总结
启动项目后,我们访问dashboard-service:http://localhost:9095/hystrix 打开Dashboard界面。
如果我们想监控A应用的接口熔断情况,我们需要在A应用中添加以下依赖:
<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>
并且需要我们在A应用的yml配置文件中新增以下配置:
management:
endpoints:
web:
exposure:
include: refresh,hystrix.stream #refresh打开actuator的配置文件刷新设置;hystrix.stream:打开hystrix状态信息获取
这样我们就可以监控A应用的请求情况了。假设A应用的服务地址是:http://localhost:7070/,我们可以访问:http://localhost:7070/actuator/hystrix.stream查看A应用中接口的熔断情况。或者我们可以通过hystrix-dashboard来监控:
简单讲解下dashboard的图形界面:
上面的“queryOrder”、“queryOrderTimeout”为监听熔断的接口;
下面灰色的圆圈代表是健康情况,如果是红色则代表不健康,形状越大流量越大
凸起来的灰色线,是请求的流量的变化情况
第一列 监控的是request请求
第一个绿色的数字,代表成功访问请求的数量,对应横向的绿色Success。98%是错误率。
第二个蓝色的数字,代表Short-Circuited
第三个青色的数字,代表错误请求的数量
第二列 针对的是response
第一个橙色的数字,代表超时访问的数量
第二个紫色的数字,代表拒绝访问的数量
第三个红色的数字,代表失败的服务数量
第三列 针对的是request/response 错误比例 或者成功比例
最重要的一个指标是参考 Circuit 代表熔断器的状态 close的关闭,open是打开