Spring Cloud入门-Hystrix Dashboard与Turbine断路器监控(Hoxton版本)

项目使用的Spring Cloud为Hoxton版本,Spring Boot为2.2.2.RELEASE版本

Spring Cloud入门系列汇总

序号内容链接地址
1Spring Cloud入门-十分钟了解Spring Cloudhttps://blog.csdn.net/ThinkWon/article/details/103715146
2Spring Cloud入门-Eureka服务注册与发现(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103726655
3Spring Cloud入门-Ribbon服务消费者(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103729080
4Spring Cloud入门-Hystrix断路器(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103732497
5Spring Cloud入门-Hystrix Dashboard与Turbine断路器监控(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103734664
6Spring Cloud入门-OpenFeign服务消费者(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103735751
7Spring Cloud入门-Zuul服务网关(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103738851
8Spring Cloud入门-Config分布式配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103739628
9Spring Cloud入门-Bus消息总线(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103753372
10Spring Cloud入门-Sleuth服务链路跟踪(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103753896
11Spring Cloud入门-Consul服务注册发现与配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103756139
12Spring Cloud入门-Gateway服务网关(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103757927
13Spring Cloud入门-Admin服务监控中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103758697
14Spring Cloud入门-Oauth2授权的使用(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103761687
15Spring Cloud入门-Oauth2授权之JWT集成(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103763364
16Spring Cloud入门-Oauth2授权之基于JWT完成单点登录(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103766368
17Spring Cloud入门-Nacos实现注册和配置中心(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103769680
18Spring Cloud入门-Sentinel实现服务限流、熔断与降级(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103770879
19Spring Cloud入门-Seata处理分布式事务问题(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103786102
20Spring Cloud入门-汇总篇(Hoxton版本)https://blog.csdn.net/ThinkWon/article/details/103786588

摘要

Hystrix Dashboard 是Spring Cloud中查看Hystrix实例执行情况的一种仪表盘组件,支持查看单个实例和查看集群实例,本文将对其用法进行详细介绍。

简介

Hystrix提供了Hystrix Dashboard来实时监控HystrixCommand方法的执行情况。 Hystrix Dashboard可以有效地反映出每个Hystrix实例的运行情况,帮助我们快速发现系统中的问题,从而采取对应措施。

Hystrix 单个实例监控

我们先通过使用Hystrix Dashboard监控单个Hystrix实例来了解下它的使用方法。

创建一个hystrix-dashboard模块

用来监控hystrix实例的执行情况。

在pom.xml中添加相关依赖:

<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>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

在application.yml进行配置:

server:
  port: 8501

spring:
  application:
    name: hystrix-dashboard

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8001/eureka/

在启动类上添加@EnableHystrixDashboard来启用监控功能:

@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }

}

启动相关服务

这次我们需要启动如下服务:eureka-server、user-service、hystrix-service、hystrix-dashboard,启动后注册中心显示如下。

在这里插入图片描述

Hystrix实例监控演示

访问Hystrix Dashboard:http://localhost:8501/hystrix

在这里插入图片描述

填写好信息后点击监控按钮,这里我们需要注意的是,由于我们本地不支持https,所以我们的地址需要填入的是http,否则会无法获取监控信息;

在这里插入图片描述

还有一点值得注意的是,被监控的hystrix-service服务需要开启Actuator的hystrix.stream端点,配置信息如下:

management:
  endpoints:
    web:
      exposure:
        #暴露hystrix监控端点
        include: 'hystrix.stream'

调用几次hystrix-service的接口:http://localhost:8401/user/testCommand/1

在这里插入图片描述

可以发现曾经我们在@HystrixCommand中添加的commandKey和threadPoolKey属性都显示在上面了,并且有4次调用都成功了。

Hystrix Dashboard 图表解读

图表解读如下,需要注意的是,小球代表该实例健康状态及流量情况,颜色越显眼,表示实例越不健康,小球越大,表示实例流量越大。曲线表示Hystrix实例的实时流量变化。

在这里插入图片描述

Hystrix 集群实例监控

这里我们使用Turbine来聚合hystrix-service服务的监控信息,然后我们的hystrix-dashboard服务就可以从Turbine获取聚合好的监控信息展示给我们了。

创建一个turbine-service模块

用来聚合hystrix-service的监控信息。

在pom.xml中添加相关依赖:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</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-turbine</artifactId>
</dependency>

在application.yml进行配置,主要是添加了Turbine相关配置:

server:
  port: 8601

spring:
  application:
    name: turbine-service

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8001/eureka/

turbine:
  # 指定需要收集信息的服务名称
  app-config: hystrix-service
  # 指定服务所属集群
  cluster-name-expression: new String('default')
  # 以主机名和端口号区分服务
  combine-host-port: true

在启动类上添加@EnableTurbine来启用Turbine相关功能:

@EnableTurbine
@EnableDiscoveryClient
@SpringBootApplication
public class TurbineServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(TurbineServiceApplication.class, args);
    }

}

启动相关服务

使用application-replica1.yml配置再启动一个hystrix-service服务,启动turbine-service服务,此时注册中心显示如下。

在这里插入图片描述

Hystrix集群监控演示

访问Hystrix Dashboard:http://localhost:8501/hystrix

添加集群监控地址,需要注意的是我们需要添加的是turbine-service的监控端点地址:

在这里插入图片描述

调用几次hystrix-service的接口:http://localhost:8401/user/testCommand/1以及http://localhost:8402/user/testCommand/1

在这里插入图片描述

可以看到我们的Hystrix实例数量变成了两个。

使用到的模块

springcloud-learning
├── eureka-server -- eureka注册中心
├── user-service -- 提供User对象CRUD接口的服务
├── hystrix-service -- hystrix服务调用测试服务
├── turbine-service -- 聚合收集hystrix实例监控信息的服务
└── hystrix-dashboard -- 展示hystrix实例监控信息的仪表盘

项目源码地址

GitHub项目源码地址

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值