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. LA 3704细胞自动机——循环矩阵&&矩阵快速幂

    题目 一个细胞自动机包含 $n$ 个格子,每个格子的取值为 $0 \sim m-1$.给定距离 $d$,则每次操作是将每个格子的值变为到它的距离不超过 $d$ 的所有格子的在操作之前的值的和除以 $m ...

  2. C# Apache Thrift Demo

    转载至 https://headsigned.com/posts/csharp-apache-thrift-demo/ This demo application shows how to imple ...

  3. sql server 中的表值函数和标量值函数

      顾名思义:表值函数返回的是表,而标量值函数可以返回基类型 一.表值函数 用户定义表值函数返回 table 数据类型.对于内联表值函数,没有函数主体:表是单个 SELECT 语句的结果集. 以下示例 ...

  4. 洛谷 P1373 小a和uim之大逃离 题解

    每日一题 day30 打卡 Analysis f[i][j][p][q]表示他们走到(i,j),且两人魔瓶内魔液量的差为p时的方法数.q=0表示最后一步是小a走的,q=1表示最后一步是uim走的.题目 ...

  5. word写博客

    虽然很多博客已经可以直接粘贴图片了但是如果图片比较多的话还是会很麻烦的.如果文章中只有一张图片那还好说,直接使用CSDN提供的编辑器粘贴就完了.但是我们的文档中一般图片都是多于1张的,经常是10张.如 ...

  6. qDeleteAll与clear

    qDeleteAll:专门用于指针容器,对容器或者迭代器中的每个对象进行delete操作,而不是从容器中移除对象.源代码如下: void qDeleteAll(ForwardIterator begi ...

  7. saltstack 发布 iis 站点

    Saltstack 发布 iis 站点 saltstack 主服务器配置:切换到 salt 的主目录下 : 主目录示例:/home/salt 程序集放置目录: web/web1 sls 目录: web ...

  8. C语言实现的简单银行存取款程序 请输入如下数字命令

    #include <stdio.h> int main(void) { //提供变量 cmd balance(余额) deposit(存款) withdraw(取款) //利用while做 ...

  9. H - Almost Union-Find

    //带删除操作的并查集 //题意:给你一个1~n的集合,有三种操作 // 1: 把p和q所在的集合合并 //2:把p移到q所在的集合中 //3:返回p所在集合中的元素个数和元素的和 //第二种操作不能 ...

  10. SSM 整合 ehcache 报错

    异常: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springfra ...