【六】Hystrix Dashboard

时间:2024-09-29 19:04:50

  

  除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard) , Hystrix会持续地记录所有通过 Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求多少成功,多少失败等。 Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。Spring Cloud也提供了Hystrix Dashboard的整合, 对监控内容转化成可视化界面。

【六】Hystrix Dashboard

【六】Hystrix Dashboard

1.pom.xml

<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>com.atguigu.springcloud</groupId>
<artifactId>microservicecloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>microservicecloud-consumer-hystrix-dashboard</artifactId> <dependencies>
<!-- 自己定义的api -->
<dependency>
<groupId>com.everjiankang.springcloud</groupId>
<artifactId>microservicecloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 修改后立即生效,热部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- Ribbon相关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- feign相关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!-- hystrix和 hystrix-dashboard相关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
</project>

2. application.yml

server:
  port: 9001

3.启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication
@EnableHystrixDashboard
public class DeptConsumer_DashBoard_App
{
public static void main(String[] args)
{
SpringApplication.run(DeptConsumer_DashBoard_App.class, args);
}
}

4.在被监控(有方法调用的)微服务项目的Pom.xml文件中添加: (8001,8002,8003集群项目中)

<!-- actuator监控信息完善 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

5.启动启动类

6.访问http://localhost:9001/hystrix

【六】Hystrix Dashboard

按图解启动三个euraka集群服务

microservicecloud-eureka-7001

microservicecloud-eureka-7002

microservicecloud-eureka-7003

然后启动项目:

microservicecloud-provider-dept-8001-hystrix

(带有熔断功能的微服务注册到了eureka集群,且被豪猪仪表盘项目【microservicecloud-consumer-hystrix-dashboard】监控)

访问:

http://localhost:8001/dept/get/1

http://localhost:8001/hystrix.stream

  ping 监控的仪表盘 json数据

【六】Hystrix Dashboard

【六】Hystrix Dashboard

1 : Delay :该参数用来控制服务器上轮询监控信息的延迟时间,默认为 2000毫秒,可以通过配置该属性来降低客户端的网络和 CPU 消耗。 
2 : Title :该参数对应了头部标题Hystrixstream 之后的内容,默认会使用具体监控实例的 URL ,可以通过配置该信息来展示更合适的标题。

【六】Hystrix Dashboard

多次刷8001的功能接口: http://localhost:8001/dept/get/1,会看到仪表盘图形页面有如下变化:

【六】Hystrix Dashboard

实心圆:共有两种含义。它通过颜色的变化代表了实例的健康程度,它的健康度从绿色<黄色<橙色<红色递减。
该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越大该实心圆就越大。
所以通过该实心圆的展示,就可以在大量的实例中快速的发现故障实例和高压力实例。

【六】Hystrix Dashboard

【六】Hystrix Dashboard


【六】Hystrix Dashboard