Spring Cloud第六篇 | Hystrix仪表盘监控Hystrix Dashboard

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

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

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

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

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

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

1、Hystrix仪表盘监控介绍

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

2、Hystrix仪表盘监控应用

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

二、添加依赖hystrix的Dashboard依赖spring-boot

<!--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>复制代码

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

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

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

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

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

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

5-二、须要有一个springboot的服务监控依赖,能够直接添加到父模块依赖中

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

5-三、配置文件须要配置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复制代码

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

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

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

详细参考案例源码:gitee.com/coding-farm…

相关文章
相关标签/搜索