本文是Spring Cloud专栏的第六篇文章,了解前五篇文章内容有助于更好的理解本文:

  1. Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览

  2. Spring Cloud第二篇 | 使用并认识Eureka注册中心

  3. Spring Cloud第三篇 | 搭建高可用Eureka注册中心

  4. Spring Cloud第四篇 | 客户端负载均衡Ribbon

  5. Spring Cloud第五篇 | 服务熔断Hystrix

一、Hystrix仪表盘监控介绍

Hystrix仪表盘( Hystrix Dashboard),就像汽车的仪表盘实时显示汽车的各 项数据一样, Hystrix仪表盘主要用来监控 Hystrix的实时运行状态,通过它我们可以看到 HystriX的各项指标信息,从而快速发现系统中存在的问题进而解决 要使用 Hystriⅸ仪表盘功能,我们首先需要有一个 Hystrix Dashboard,这个功能我们可以在原来的消费者应用上添加,让原来的消费者应用具备Hysr仪表 盘功能,但一般地微服务架构思想是推崇服务的拆分, Hystrix Dashboard也是一个服务,所以通常会单独创建一个新的工程专门用做 Hystrix Dashboard 服务,Hystrix Dashboard所处的作用如图

二、Hystrix仪表盘监控应用

1、新建一个模块命名为(springcloud-hystrix-dashboard)

2、添加依赖hystrix的Dashboard依赖

<!--hystrix-dashboard功能的起步依赖,仪表盘功能-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

此时依赖可能下载不下来,可以添加阿里云仓库

<repositories>
<repository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

3、在启动类上添加注解@EnableHystrixDashboard

4、端口配置为3721,到此我们的hystrix监控服务就搭建完毕了,启动访问http://localhost:3721/hystrix

Hystrix仪表盘工程已经创建好了,我们需要有一个服务,让这个服务提供一个路径为/actuator/hystrix.stream接口,然后就可以使用Hystrix仪表盘来对该服务进行监控了

5、改造消费者(springcloud-service-consumer)

我们改造消费者服务,让其能提供/actuator/hystrix.stream接口,步骤如下:

5-1、消费者项目需要有Hystrix的依赖,在之前案例中使用服务熔断的时候已经加过了

5-2、需要有一个springboot的服务监控依赖,可以直接添加到父模块依赖中

<!--springboot提供的服务健康检查监控的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

5-3、配置文件需要配置springboot监控的端点访问权限

#用来暴露endpoints的,由于endpoints中会包含很多敏感信息,
#除了health和info两个支持直接访问外,其他的默认不能直接访问,
#所以我们让他们都能访问(*),或者指定springboot的监控端点访问权限,
#*表示所有的端点都允许访问,如果只写hystrix.stream,他会把默认的info,health端点关闭
management:
endpoints:
web:
exposure:
include: ["info","health","hystrix.stream"]

从控制台日志上可以看到

2019-08-07 15:58:31.187  INFO 7396 --- [ost-startStop-1] o.s.b.a.e.web.ServletEndpointRegistrar   : Registered '/actuator/hystrix.stream' to hystrix.stream-actuator-endpoint

6、第一次访问,要先访问其他带用熔断器的接口,访问入口:http://localhost:9090/actuator/hystrix.stream

注意:这里有一个细节需要注意,要访问/hystrix.stream接口,首先访问消费者(springcloud-service-consumer)工程中任意的一个带有熔断器的接口,否则直接访问/hystrix.stream接口时,会输出一连串ping:    ping: ....

7、把http://localhost:9090/actuator/hystrix.stream填写到Hystrix Dashboard仪表盘上,直接在网上找了一个详细描述图,如下图

详细参考案例源码:https://gitee.com/coding-farmer/springcloud-learn

最新文章

  1. echarts引入及应用
  2. java servlet Json.org.jar
  3. 20Spring_JdbcTemplatem模板工具类
  4. Java---文件夹及文件操作
  5. (原+译)win7远程连接ubuntu16.04
  6. XML新手入门 创建构造良好的XML(2)
  7. java泛型中使用的排序算法——归并排序及分析
  8. 协议形式化分析Scyther 资料整理
  9. ZOC7在Mac下发送命令到多个窗口设置
  10. java 线程理解
  11. 【笔记】Python基础六:模块module介绍及常用模块
  12. liunx之Centos6.8杀毒软件的安装
  13. php 函数集锦
  14. ThreaLocal
  15. 微信小程序云开发之云函数创建
  16. iOS UISlider滑动块触摸范围调整变大
  17. XToDo未完成内容标记管理器
  18. asp.net 获取客户端IP
  19. open -python操作文件
  20. 解决IDEA右键 new 没有新建class/Interface等等选项

热门文章

  1. RPA - UiPath简明教程 ║ .NET的又一领域
  2. Python openpyxl Excel绘制柱形图
  3. java多线程回顾2:生命周期与控制
  4. C# V: 读取XML文件
  5. Graphviz 画图的一些总结
  6. 领扣(LeetCode)合并两个有序数组 个人题解
  7. 解决FirewallD is not running问题
  8. 【故障公告】数据库服务器 CPU 近 100% 引发的故障
  9. Redis报错: StackExchange.Redis.RedisServerException: Endpoint 39.105.22.111:7200 serving hashslot 12448 is not reachable at this point of time.
  10. 【Luogu P1265】公路修建