Hystrix Dashboard

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。

添加依赖

我们新建一个工程 spring-cloud-consul-monitor,修改 pom 文件,添加相关依赖。

pom.xml

    <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>

启动类

在启动类中添加注解 @EnableHystrixDashboard 开启熔断监控支持。

ConsuleMonitorApplication.java

package com.louis.spring.cloud.consul.monitor;

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

修改配置

修改配置文件,配置启动端口和应用名称。

application.yml

server:
port: 8531
spring:
application:
name: spring-cloud-consul-monitor

配置监控路径

注意,如果你使用的是2.x等比较新的版本,需要在 Hystrix 的消费端配置监控路径,我们这里消费端是 spring-cloud-consul-consumer, 所以修改它的启动类。

ConsuleConsumerApplication.java

    // 此配置是为了服务监控而配置,与服务容错本身无关,
// ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
// 只要在自己的项目里配置上下面的servlet就可以了
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}

测试效果

先后启动 spring-cloud-consul-producer、 spring-cloud-consul-consumer、spring-cloud-consul-monitor 服务。

访问 http://localhost:8531/hystrix,会看到如下图所示界面。

此时没有任何具体的监控信息,需要输入要监控的消费者地址及监控信息的轮询时间和标题。

Hystrix Dashboard 共支持三种不同的监控方式:

单体Hystrix 消费者:通过URL http://hystrix-app:port/hystrix.stream 开启,实现对具体某个服务实例的监控。

默认集群监控:通过URL http://turbine-hostname:port/turbine.stream 开启,实现对默认集群的监控。

自定集群监控:通过URL http://turbine-hostname:port/turbine.stream?cluster=[clusterName] 开启,实现对clusterName集群的监控。

我们这里现在是对单体 Hystrix 消费者的监控,后面整合 Turbine 集群的时候再说明后两种的监控方式。

我们先访问 http://localhost:8521/feign/call, 查看要监控的服务是否可以正常访问。

确认服务可以正常访问之后,在监控地址内输入 http://localhost:8521/hystrix.stream,然后点击 Monitor Stream 开始监控。

刚进去,页面先显示 loading... 信息, 多次访问 http://localhost:8521/feign/call 之后,统计图表信息如下图所示。

各个指标的含义参见下图。

源码下载

码云:https://gitee.com/liuge1988/spring-cloud-demo.git


作者:朝雨忆轻尘
出处:https://www.cnblogs.com/xifengxiaoma/
版权所有,欢迎转载,转载请注明原文作者及出处。

Spring Boot + Spring Cloud 构建微服务系统(五):熔断监控面板(Hystrix Dashboard)的更多相关文章

  1. Spring boot学习1 构建微服务:Spring boot 入门篇

    Spring boot学习1 构建微服务:Spring boot 入门篇 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框 ...

  2. Spring Boot + Spring Cloud 构建微服务系统(六):熔断监控集群(Turbine)

    Spring Cloud Turbine 上一章我们集成了Hystrix Dashboard,使用Hystrix Dashboard可以看到单个应用内的服务信息,显然这是不够的,我们还需要一个工具能让 ...

  3. Spring Boot + Spring Cloud 构建微服务系统(七):API服务网关(Zuul)

    技术背景 前面我们通过Ribbon或Feign实现了微服务之间的调用和负载均衡,那我们的各种微服务又要如何提供给外部应用调用呢. 当然,因为是REST API接口,外部客户端直接调用各个微服务是没有问 ...

  4. Spring Boot + Spring Cloud 构建微服务系统(九):配置中心(Spring Cloud Config)

    技术背景 如今微服务架构盛行,在分布式系统中,项目日益庞大,子项目日益增多,每个项目都散落着各种配置文件,且随着服务的增加而不断增多.此时,往往某一个基础服务信息变更,都会导致一系列服务的更新和重启, ...

  5. Spring Boot + Spring Cloud 构建微服务系统(十):配置中心(Spring Cloud Bus)

    技术背景 我们在上一篇讲到,Spring Boot程序只在启动的时候加载配置文件信息,这样在GIT仓库配置修改之后,虽然配置中心服务器能够读取最新的提交信息,但是配置中心客户端却不会重新读取,以至于不 ...

  6. Spring Boot + Spring Cloud 构建微服务系统(八):分布式链路追踪(Sleuth、Zipkin)

    技术背景 在微服务架构中,随着业务发展,系统拆分导致系统调用链路愈发复杂,一个看似简单的前端请求可能最终需要调用很多次后端服务才能完成,那么当整个请求出现问题时,我们很难得知到底是哪个服务出了问题导致 ...

  7. Spring Boot + Spring Cloud 构建微服务系统(四):容错机制和熔断(Hystrix)

    雪崩效应 在微服务架构中,由于服务众多,通常会涉及多个服务层级的调用,而一旦基础服务发生故障,很可能会导致级联故障,进而造成整个系统不可用,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者 ...

  8. Spring Boot + Spring Cloud 构建微服务系统(三):服务消费和负载(Feign)

    Spring Cloud Feign Spring Cloud Feign是一套基于Netflix Feign实现的声明式服务调用客户端.它使得编写Web服务客户端变得更加简单.我们只需要通过创建接口 ...

  9. Spring Boot + Spring Cloud 构建微服务系统(二):服务消费和负载(Ribbon)

    使用RestTemplate调用服务 在上一篇教程中,我们是这样调用服务的,先通过 LoadBalancerClient 选取出对应的服务,然后使用 RestTemplate 进行远程调用. Load ...

随机推荐

  1. js常用判断和语法

    1.js获取选中的redio元素 var version = $('.version input[name="input1"]:checked').val();//单选框默认选中& ...

  2. 将VSCode设置成中文语言环境

    VSCode是一款轻量级的好用的编译软件,今天小编来将软件默认的英文语言环境变为我们熟悉的中文语言环境. 工具/原料   电脑一台 安装有VSCode 方法/步骤     首先打开VSCode软件,可 ...

  3. Java SSM 框架相关基础面试题

    一.Spring 面试题 1. Spring 在 SSM 中起什么作用? Spring 是轻量级框架,作用是作为 Bean 工厂,用来管理 Bean 的声明周期和框架集成. Spring 的两大核心: ...

  4. 模板学习实践三 functor

    #include <iostream>#include <typeinfo> void foo(){ std::cout << "foo() called ...

  5. javaScript 字符串

    var name = '小明'; var age = 20; var message = '你好, ' + name + ', 你今年' + age + '岁了!'; alert(message) 要 ...

  6. 20175316 盛茂淞 实验一 Java开发环境的熟悉

    20175316 盛茂淞 实验一 Java开发环境的熟悉 实验目的 使用JDK编译.运行简单的Java程序 实验要求 1.建立"自己学号exp1"的目录 2.在"自己学号 ...

  7. Python基础整理

    第一章 Python介绍 1.3 基本类型 操作符 +,-,*,/,%,**(幂),divmod(除法) divmod(10,3)=(3,1) None表示出错 表示假: None,0,0.0,&qu ...

  8. 更改h标签的字体粗细

    h1,h2,h3,h4,h5,h6{ font-weight:normal }

  9. CCPC-2017-秦皇岛站

    10月25日 听说信用卡到了好兴奋,然而没有额度是啥情况啊qwq. 晚上坐飞机出发,成都-鄂尔多斯-石家庄-秦皇岛,队友吐槽鄂尔多斯到石家庄好近啊,然后过了一会儿我们因为石家庄大雾迫降在了济南.嘤嘤嘤 ...

  10. python之路(三)-深浅拷贝

    深浅拷贝用法来自copy模块. 导入模块:import copy 浅拷贝:copy.copy 深拷贝:deepcopy 字面理解:浅拷贝指仅仅拷贝数据集合的第一层数据,深拷贝指拷贝数据集合的所有层.所 ...