Hystrix除了可以对不可用的服务进行断路隔离外,还能够对服务进行实时监控。Hystrix可以实时、累加地记录所有关于HystrixCommand的执行信息,包括每秒执行多少、请求成功多少、失败多少等。
  要想实时地对服务进行监控,需要在项目中添加相关的监控依赖,具体如下:

<dependency><!--监控依赖--><!--http://localhost:8030/hystrix.stream-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

  在xcservice-eureka-user-hystrix工程的pom.xml中引入上述依赖后,即可查看监控信息,具体操作步骤如下。
  (1)分别启动注册中心、服务提供者(7901)和服务消费者工程。
  (2)通过浏览器访问地址http://localhost:8030/findOrder-sByUser/1(此步骤不可省略,否则将由于系统应用的所有接口都未被调用,而只输出ping:)。
  (3)通过浏览器访问地址http://localhost:8030/hystrix.stream,将看到如下所示的输出信息。

ping: 

data: {"type":"HystrixCommand","name":"findOrdersByUser","group":"UserController","currentTime":1563192973047,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"UserController"}

data: {"type":"HystrixThreadPool","name":"UserController","currentTime":1563192973047,"currentActiveCount":0,"currentCompletedTaskCount":6,"currentCorePoolSize":10,"currentLargestPoolSize":6,"currentMaximumPoolSize":10,"currentPoolSize":6,"currentQueueSize":0,"currentTaskCount":6,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"rollingCountCommandRejections":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"reportingHosts":1}

  可以看出,访问具体地址后,浏览器会不断地执行刷新操作以获取实时的监控数据。这样运维人员就可以通过这些数据来判断出系统当前的监控状态。虽然采用上面这种纯文字输出的方式可以实时监控数据,但其可读性十分差。
  为此,我们可以通过Hystrix Dashboard以可视化的方式来查看实时监控数据。Hystrix Dashboard是Hystrix的一个组件,它提供了数据监控和友好的图形化界面支持。
  下面通过一个具体的应用来演示Hystrix Dashboard的使用。
  (1)新建xcservice-springcloud的子工程xcservice-hystrix-dashboard,在其pom.xml文件中添加监控依赖和Hystrix Dashboard依赖,如文件5-5所示。
  文件5-5 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.xc</groupId>
<artifactId>xcservice-springcloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.xc</groupId>
<artifactId>xcservice-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xcservice-hystrix-dashboard</name>
<description>Hystrix Dashboard是Hystrix的一个组件,它提供了数据监控和友好的图形化界面支持。</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies> <dependency><!--数据监控和友好的图形化界面支持--><!--http://localhost:8031/hystrix.stream-->
<groupId>org.springframework.cloud</groupId>
<artifactId> spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency> <dependency><!--监控依赖--><!--http://localhost:8030/hystrix.stream-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

  (2)编写配置文件application.yml,指定应用的端口号和名称等信息,如文件5-6所示。
  文件5-6 application.yml

server:
port: 8031 # 指定该Eureka实例的端口号 spring:
application:
name: xcservice-hystrix-dashboard # 指定应用名称

  (3)编写启动类Application.java,并在其类上添加@EnableHystrixDashboard注解来开启Hystrix仪表板功能,如文件5-7所示。
  文件5-7 Application.java

package com.xc.xcservicehystrixdashboard;

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

  (4)启动工程后,通过浏览器访问地址http://local-host:8031/hystrix.stream将会看到如图5-8所示的信息。

  

  在图5-8中,Hystrix Dashboard下的输入框用于输入需要监控的服务URL,Delay中的参数表示服务器上的轮询时间间隔,Title中的输入框用于设置浏览器中所监视服务的标题。
  在Hystrix Dashboard下的输入框中输入http://localhost:8030/hystrix.stream,并设置Title为“订单微服务”后,单击【Monitor Stream】按钮。
  此时如果通过另一个浏览器访问http://localhost:8030/findOrdersByUser/1,并且不断地刷新地址,将出现如下所示页面。

  关于图中各个指标的含义,在Hystrix Dashboard Wiki上已经给出了详细说明,读者可访问地址https://github.com/Netflix/Hystrix/wiki/Dashboard查看。

Spring Cloud Hystrix Dashboard的使用 5.1.3的更多相关文章

  1. Spring Cloud Hystrix Dashboard熔断器-Turbine集群监控(六)

    序言 上一篇说啦hystrix的使用方法与配置还有工作流程及为何存在,我去,上一篇这么屌,去看看吧,没这么屌的话,我贴的有官方文档,好好仔细看看 hystrix除啦基本的熔断器功能之外,还可以对接口的 ...

  2. spring cloud hystrix dashboard 没有/actuator/hystrix.stream路径解决

    首先我用的是spring boot Greenwich.SR2 在测试hystrix-dashboard监控服务时,发现访问localhost:9001/actuator/hystrix.stream ...

  3. Spring Cloud 2-Hystrix DashBoard仪表盘(五)

    Spring Cloud  Hystrix DashBoard  1.监控系统配置 pom.xml application.yml Application.java 2.被监控服务配置 pom.xml ...

  4. 微服务架构之spring cloud hystrix&hystrix dashboard

    在前面介绍spring cloud feign中我们已经使用过hystrix,只是没有介绍,spring cloud hystrix在spring cloud中起到保护微服务的作用,不会让发生的异常无 ...

  5. Spring Cloud 微服务笔记(六)Spring Cloud Hystrix

    Spring Cloud Hystrix Hystrix是一个延迟和容错库,旨在隔离远程系统.服务和第三方库,阻止链接故障,在复杂的分布式系统中实现恢复能力. 一.快速入门 1)依赖: <dep ...

  6. 试水Spring Cloud Hystrix

    Spring Cloud Hystrix是一个容错库,它实现了断路器模式,使得当服务发生异常时,会自动切断连接,并将请求引导至预设的回调方法. 服务端 在Spring Tool Suite的文件菜单中 ...

  7. Spring Cloud Hystrix理解与实践(一):搭建简单监控集群

    前言 在分布式架构中,所谓的断路器模式是指当某个服务发生故障之后,通过断路器的故障监控,向调用方返回一个错误响应,这样就不会使得线程因调用故障服务被长时间占用不释放,避免故障的继续蔓延.Spring ...

  8. 分布式系统的延时和故障容错之Spring Cloud Hystrix

    本示例主要介绍 Spring Cloud 系列中的 Eureka,如何使用Hystrix熔断器容错保护我们的应用程序. 在微服务架构中,系统被拆分成很多个服务单元,各个服务单元的应用通过 HTTP 相 ...

  9. 7、Spring Cloud Hystrix

    1.Spring Cloud Hystrix简介 (1).分布式问题 复杂分布式体系结构中的应用程序有数十个依赖关系,每个依赖关系在某些时候将不可避免地失败. 多个微服务之间调用的时候,假设微服务A调 ...

随机推荐

  1. C# URL编码转换 URL转码 UrlDecode UrlEncode

    using System.Web; 引用system.web. textBox2.Text = System.Web.HttpUtility.UrlDecode(textBox1.Text, Syst ...

  2. Java8新特性(拉姆达表达式lambda)

    一.函数式接口 函数式接口(functional interface 也叫功能性接口,其实是同一个东西).简单来说,函数式接口是只包含一个方法的接口.比如Java标准库中的java.lang.Runn ...

  3. ClickHouse 分布式高可用集群搭建(转载)

    一.ClickHouse安装方式: 源码编译安装 Docker安装 RPM包安装 为了方便使用,一般采用RPM包方式安装,其他两种方式这里不做说明. 二.下载安装包 官方没有提供rpm包,但是Alti ...

  4. 【转载】Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration info

    网上查到http://social.msdn.microsoft.com/Forums/vstudio/en-US/58271e39-beca-49ac-90f9-e116fa3dd3c0/mxed- ...

  5. declare/typeset

    用来生命变量的,作用完全一样. 不像C语言那样严谨的语法,变量在使用前必须声明. 但是在shell中对变量的声明要求并不高,因为shell弱化了变量的类概念,所以shell被称为弱类型语言, 声明变量 ...

  6. 看加载的php.ini 和 phpinfo 配置路径

    php -i | grep "phar.readonly"看当前值php -i | grep "php.ini" 看加载的php.ini是哪个

  7. 自行撰写Grasshopper电池

    Grasshopper目前作为参数化设计是非常常用的工具,但是人们会经常碰到它提供的电池不能满足自己设计方案需求的情况,所以就需要自己创作电池,而最简单的一种方法就是自己写. 工具: Visual S ...

  8. 获取句柄的类型以及对应的ID序号

    遍历所有进程下的所有句柄,以及对应句柄类型. 一丶简介 在有的时候.我们会需要对应句柄名字.以及句柄类型的名称. 以及它所对应的的ID. 因为每个系统不一样.所以每次都是不一样的. 有的时候我们就需要 ...

  9. 移动端滚动选择器mobileSelect.js

    一款多功能的移动端滚动选择器,支持单选到多选.支持多级级联.提供自定义回调函数.提供update函数二次渲染.重定位函数.兼容pc端拖拽等等.. 特性 原生js移动端选择控件,不依赖任何库 可传入普通 ...

  10. VsCode插件与Node.js交互通信

    首先关于VsCode插件通信,如果不明白的可以参考我的这篇博客VsCode插件开发之插件初步通信 如果需要详细例子的话,可以参考VsCode插件开发 现在又有一个新的需求是,VsCode插件可以通过j ...