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. (尚010)Vue列表的搜素和排序

    1.test010.html <!DOCTYPE html><html lang="en"><head> <meta charset=&q ...

  2. Windows异常相关数据结构

    当一个异常发生时,操作系统要向引起异常的线程的栈里压入三个结构,这三个结构是:E X C E P T I O N _ R E C O R D结构.C O N T E X T结构和E X C E P T ...

  3. 100: cf 878C set+并查集+链表

    $des$Berland要举行 $n$ 次锦标赛,第一次只有一个人,之后每一次会新加入一个人.锦标赛中有 $k$ 种运动项目,每个人在这 $k$ 种项目上都有一个能力值,每次会选择任意两个还未被淘汰的 ...

  4. Processing 字体变形

    在Processing中做字体变形通常需要有以下基础知识: 1.PGraphics对象 2.图片像素化 制作过程也不复杂,代码如下: color ELLIPSE_COLOR = color(0); c ...

  5. (32)Vue模板语法

    模板语法 文本: <span>Message: {{ msg }}</span> v-once 一次性地插值,当数据改变时,插值处的内容不会更新 <span v-once ...

  6. (28)打鸡儿教你Vue.js

    单件商品金额计算和单选全选功能 new Vue({ el: '#app', data: { totalMoney: 0, productList: [] }, filters: { formatMon ...

  7. 性能测试学习第八天-----linux环境整合篇

  8. ZR#989

    ZR#989 先吐槽一下这个ZZ出题人,卡哈希表. 我就不写那个能过的类高精了,直接写哈希的题解 解法: 判断两个数相加结果是否等于第三个数, 可以直接用 hash判断. #include<io ...

  9. leaflet使用手册

    谷歌地图加载地址: 谷歌交通地图地址:http://www.google.cn/maps/vt/pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m3!1e0!2sm!3i38007257 ...

  10. 2、ES6结构赋值和模板字符串

    ES6允许按照一定的模式,从数组和对象中提取值,这被称为结构,即解开数据的结构 1.数组的解构赋值 let [a,b] = [1,2] let [a,b,c=100] = [1,2] //c的默认值为 ...