SpringCloud2.0 Hystrix Dashboard 断路器指标看板 基础教程(八)
1、启动基础工程
1.1、启动【服务中心】集群,工程名称:springcloud-eureka-server
1.2、启动【服务提供者】集群,工程名称:springcloud-eureka-client
1.3、启动【服务消费者】,工程名称:springcloud-eureka-ribbon
1.4、启动【服务消费者】,工程名称:springcloud-eureka-feign
2、创建【断路器指标看板】,即 Hystrix Dashboard
2.1、新建 Spring Boot 工程,工程名称:springcloud-eureka-hystrix-dashboard
2.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>
2.3、在工程启动类中,添加注解 @EnableDiscoveryClient,@EnableHystrixDashboard
package com.miniooc.eurekahystrixdashboard; 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; /**
* EurekaHystrixDashboardApplication
*
* @author 宋陆
* @version 1.0.0
*/
@EnableHystrixDashboard // 启用 HystrixDashboard 断路器看板 相关配置
@EnableDiscoveryClient // 启用 Eureka 服务发现 相关配置
@SpringBootApplication
public class EurekaHystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(EurekaHystrixDashboardApplication.class, args);
} }
2.4、新建工程配置文件 application.yml ,配置内容:
server:
port: 52630 spring:
application:
name: eureka-hystrix-dashboard eureka:
instance:
hostname: localhost
# 表示eureka client间隔多久去拉取服务注册信息,默认为30秒,如果要迅速获取服务注册状态,可以缩小该值
lease-renewal-interval-in-seconds: 5
# 表示eureka server至上一次收到client的心跳之后,等待下一次心跳的超时时间,在这个时间内若没收到下一次心跳,则将移除该instance。
# 默认为90秒
# 如果该值太大,则很可能将流量转发过去的时候,该instance已经不存活了。
# 如果该值设置太小了,则instance则很可能因为临时的网络抖动而被摘除掉。
# 该值至少应该大于 leaseRenewalIntervalInSeconds
lease-expiration-duration-in-seconds: 10
client:
serviceUrl:
defaultZone: http://localhost:9527/eureka/,http://localhost:9528/eureka/,http://localhost:9529/eureka/
2.5、启动【断路器指标看板】工程
2.6、打开浏览器,访问 http://localhost:52630/hystrix

2.7、监控地址输入 http://localhost:52610/hystrix.stream 来监控 springcloud-eureka-ribbon 服务,点击【Monitor Stream】按钮,开启断路器指标看板

报了一个红色提示,Unable to connect to Command Metric Stream.这是因为我们开启监控的断路器流 Hystrix Stream: http://localhost:52610/hystrix.stream。这个路径,不是springboot工程默认路径,也不是hystrix默认路径。
解决方案:修改【服务消费者】工程,注册断路器指标流Servlet
2.8、修改【服务消费者】工程,工程名称:springcloud-eureka-ribbon,修改EurekaRibbonConfig类,注册断路器指标流Servlet
package com.miniooc.eurekaribbon.config; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate; /**
* EurekaRibbonConfig
* 应用配置类,初始化 Bean和配置信息
*
* @author 宋陆
* @version 1.0.0
*/
@Configuration
public class EurekaRibbonConfig { @Bean // 初始化 Bean
@LoadBalanced // 实现负载均衡
public RestTemplate restTemplate() {
return new RestTemplate();
} @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;
}
}
2.9、重启【服务消费者】springcloud-eureka-ribbon 服务。刷新【断路器指标看板】页面

红框处 Loading... 状态,是因为重启【服务消费者】后,没有任何请求,所以,也就没有任何数据流产生。监控页面就处于加载中。只要我们请求一下 http://localhost:52610/ribbonInfo,就可以看到数据指标了。

2.10、新开浏览器窗口,访问 http://localhost:52630/hystrix
2.11、监控地址输入 http://localhost:52620/hystrix.stream 来监控 springcloud-eureka-feign 服务,点击【Monitor Stream】按钮,开启断路器指标看板
依旧是同样的问题,Unable to connect to Command Metric Stream。
解决方案:修改【服务消费者】工程,注册断路器指标流Servlet
2.12、修改【服务消费者】工程,工程名称:springcloud-eureka-feign,新增EurekaFeignConfig类,注册断路器指标流Servlet
package com.miniooc.eurekafeign.config; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate; /**
* EurekaFeignConfig
* 应用配置类,初始化 Bean和配置信息
*
* @author 宋陆
* @version 1.0.0
*/
@Configuration
public class EurekaFeignConfig { @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;
} }
2.13、重启【服务消费者】springcloud-eureka-feign 服务。刷新【断路器指标看板】页面
依旧是 Loading... 问题,只要我们请求一下 http://localhost:52610/feignInfo,就可以看到数据指标了。

SpringCloud2.0 Hystrix Dashboard 断路器指标看板 基础教程(八)的更多相关文章
- SpringCloud2.0 Hystrix Dashboard 断路器指标看板
原文:https://www.cnblogs.com/songlu/p/9973856.html 1.启动基础工程 1.1.启动[服务中心]集群,工程名称:springcloud-eureka-ser ...
- spring cloud 2.x版本 Hystrix Dashboard断路器教程
前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...
- SpringCloud2.0 Hystrix Feign 基于Feign实现断路器 基础教程(七)
1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集 ...
- SpringCloud2.0 Hystrix Ribbon 基于Ribbon实现断路器 基础教程(六)
1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集 ...
- SpringCloud2.0 Hystrix Feign 基于Feign实现断路器
原文:https://www.cnblogs.com/songlu/p/9968953.html 1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 Sprin ...
- SpringCloud2.0 Hystrix Ribbon 基于Ribbon实现断路器
原文:https://www.cnblogs.com/songlu/p/9949203.html 1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 Sprin ...
- git基础教程(八)
8. gitlab相关介绍 8.1 gitlab优势 社区版本,自己可以在公司搭建环境 维护人员多,版本更新块 易用性强,上手快 集成CI(持续集成) 集成CD(持续发布) 8.2 持续集成 8.2. ...
- SpringCloud2.0 Turbine 断路器集群监控 基础教程(九)
1.启动基础工程 1.1.启动[服务中心]集群,工程名称:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) ...
- SpringCloud学习系列之三----- 断路器(Hystrix)和断路器监控(Dashboard)
前言 本篇主要介绍的是SpringCloud中的断路器(Hystrix)和断路器指标看板(Dashboard)的相关使用知识. SpringCloud Hystrix Hystrix 介绍 Netfl ...
随机推荐
- Linux CentOS7 通过 yum 搭建 svn 服务器,并配置权限
1,使用 yum 安装 svn 服务器 yum -y install subversion rpm -ql subversion -- 改命令可以查看 svn 的安装位置 2,创建仓库根目录,可任意选 ...
- 配置windows live writer
下载地址 https://pan.baidu.com/s/1WVpLQEadIHN15W2DIhWh4A 安装流程参考博客 https://www.cnblogs.com/haseo/p/376232 ...
- rtmp_specification_1.0
Copyright Adobe Systems Incorporated H. Parmar, Ed. M. Thornburgh, Ed. Adobe December 21, 2012 Adobe ...
- [xsy3132]数表
题意:一个$n\times m$的数表,数值$\in[0,4)$,你可以任意次选择一行或一列$+1,\text{mod }4$,要最小化所有数的和 因为$n\leq10$,所以数表可以看成$m$个$n ...
- 【转】Object.keys方法之详解
一.语法 Object.keys(obj) 参数:要返回其枚举自身属性的对象 返回值:一个表示给定对象的所有可枚举属性的字符串数组 二.处理对象,返回可枚举的属性数组 let person = {n ...
- MAC——Homebrew介绍和使用
一.Homebrew是什么 Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径 ...
- SQlL Server ----- 通过年月进行查询
websit 中的代码. 不修改 对控件进行修改,展示年月 WdatePicker({ dateFmt: 'yyyy-MM', isShowToday: false, isShowClear: fa ...
- Lock Free (无锁并发)
CAS( compare and swap) 原子操作,保证了如果需要更新的地址没有被其他进程(线程)改动过,那么它可以安全的写入.而这也是我们对于某个数据或者数据结构加锁要保护的内容,保证读写的一致 ...
- 测试函数——python编程从入门到实践
测试函数 学习测试,得有测试的代码.下面是一个简单的函数: name_function.py def get_formatted_name(first, last): ""&quo ...
- C/C++語言 - 日常算法 - 蛇形填數
C/C++語言 - 日常算法 - 蛇形填數 日期 : 2019-06-11 問題描述: 在n×n方阵里填入1,2,…,n×n,要求填成蛇形. 例如,n=4时方阵为: 10 11 12 1 9 ...