前言

本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3

本文基于前两篇文章eureka-server、eureka-client、eureka-ribbon和eureka-feign的实现。

参考

概念

Hystrix Dashboard时Hystrix提供的一个可以查看hystrix监控数据的控制面板。Hystrix提供了近实时的数据监控,Hystrix会实时、累加的记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求,多少成功和多少失败等。

创建Hystrix Dashboard工程

1.1 创建sping boot工程:hysteric-dashboard

1.2 添加pom.xml相关依赖

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

1.3 application添加配置信息

spring:
application:
name: hystrix-dashboard
server:
port: 8500 eureka:
instance:
hostname: localhost
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://eureka1.server.com:8701/eureka/,http://eureka2.server.com:8702/eureka/,http://eureka3.server.com:8703/eureka/

1.4 启动类HystrixDashboardApplication增加注解

package spring.cloud.demo.hystrixdashboard;

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

@EnableHystrixDashboard:启动Hystrix Dashboard断路器看板相关配置

1.5 启动hystrix-dashboard服务

打开浏览器,输入http://localhost:8500/hystrix显示结果如下:

url输入框:代表要监控的服务消费者

Single Hystrix App: https://hystrix-app:port/actuator/hystrix.stream:要监控路径url格式

1.6 监控ribbon服务

1.6.1 eureka-ribbon增加Hystrix的Configuration

package spring.cloud.demo.eurekaribbon.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; /**
* @auther: maomao
* @DateT: 2019-09-17
*/
@Configuration
public class HystrixConfig { @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;
}
}

启动eureka-client和eureka-ribbon服务。然后在hystrix dashboard控制面板url框中输入:

点击Monitor Stream会显示:

  • Unable to connect to Command Metric Stream问题原因:因为我们开启监控的断路器流Hystrix Stream路径http://localhost:8901/hystrix.stream不是spring boot的默认路径,也不是hystrix的默认路径,所有要增加Hystrixconfig来制定断路器的指标流Servlet。

  • 首次成功启动页面也有可能会显示loading,这代表还没有访问我们要监控的服务,这是我们可以多次请求要访问的服务就可以看到指标数据

按照同样的方式我可以设置eureka-feign的配置来进行监看。

总结

本文简单的搭建了Hystrix Dashborad数据监控平台。

Hystrix现在已经是停止开发,处于维护阶段,在Github上Hystrix已经说明,建议我们使用Resilience4J。后续会更新关于Resilience4J的简单实用。

代码地址

gitHub地址


《Srping Cloud 2.X小白教程》目录


转载请注明出处,

  • 联系方式:4272231@163.com

spring cloud 2.x版本 Hystrix Dashboard断路器教程的更多相关文章

  1. spring cloud 2.x版本 Ribbon服务发现教程(内含集成Hystrix熔断机制)

    本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 前言 本文基于前两篇文章eureka-server和eureka-client的实现. 参考 ...

  2. spring cloud 2.x版本 Feign服务发现教程(内含集成Hystrix熔断机制)

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server和eureka-client的实现. 参考 ...

  3. spring cloud 2.x版本 Eureka Client服务提供者教程

    本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 1 创建eureka client 1.1 新建Srping boot工程:eureka-c ...

  4. spring cloud 2.x版本 Zuul路由网关教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  5. spring cloud 2.x版本 Gateway动态路由教程

    摘要 本文采用的Spring cloud为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的几篇Spring cloud Gateway文章的实现. 参考 Gatew ...

  6. spring cloud 2.x版本 Gateway路由网关教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  7. spring cloud 2.x版本 Config配置中心教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的文章eureka-server的实现. 参考 eureka-server ...

  8. spring cloud 2.x版本 Gateway自定义过滤器教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  9. spring cloud(五)熔断监控Hystrix Dashboard和Turbine

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

随机推荐

  1. 深挖的Java源代码之Integer.parseInt()vs Integer.valueOf()

    Integer.parseInt()和Integer.valueOf()都是用来将String转换为Int的,但是为什么Java会提供两个这样的方法呢,他们如果是同样的操作,岂不是多此一举? 我们来深 ...

  2. 数据库迁移导致Unknown character set: 'GBK' 应用异常

    https://blog.csdn.net/u013415591/article/details/82692242https://blog.csdn.net/gx_1_11_real/article/ ...

  3. Httpclient 4.5.2 请求重试机制

    重点是HttpRequestRetryHandler.retryRequest()方法 public static String callHttpServer(String contentType,S ...

  4. swiper手滑导航圆点不同步

    // 滚动图 var mySwiper = new Swiper('.swiper-container', { // 如果需要分页器 pagination: { el: '.swiper-pagina ...

  5. python 实现 PC 客户端自动化快速入门:pywinauto !

    本文转载自:http://www.lemfix.com/topics/420 一.前言 ​ 我们柠檬班的小可爱,在学完我们柠檬班自动化的课程之后,就掌握了接口自动化,web自动化,app自动化,这些工 ...

  6. tomcat在centos7能启动不显示

    首先查看启动日志,日志显示成功启动,java路径也对,没有问题. 日志目录路径为$(tomcat)/logs/catalina.log 查看命令为:tail -300f catalina.log 然后 ...

  7. Python抓取妹子图,内含福利

    目标抓取全站妹子封面图片全部爬下来以图片标题命名 分析网页数据结构   妹子图首页 接下来找张图片右击点击检查   想要数据 拿到图片链接直接用浏览器可以访问,但是程序下载有反爬虫,图片直接下载不了需 ...

  8. Elasticsearch 6.x版本全文检索学习之数据建模

    1.什么是数据建模. 答:数据建模,英文为Data Modeling,为创建数据模型的过程.数据模型Data Mdel,对现实世界进行抽象描述的一种工具和方法,通过抽象的实体及实体之间联系的形式去描述 ...

  9. H5 App实现热更新,不需要重新安装app

    直接上代码吧,你竟然搜到了我的文章就应该知道了,为什么要热更新 //app热更新下载 //假定字符串的每节数都在5位以下 function toNum(a) { //也可以这样写 var c=a.sp ...

  10. python Windows环境下文件路径问题

    转自:http://blog.sina.com.cn/s/blog_5ee7254801013zu7.html 在python程序里面我们经常需要对文件进行操作,Windows下的文件目录路径使用反斜 ...