原文:https://www.cnblogs.com/songlu/p/9973856.html

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 文件添加如下依赖:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 ,配置内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 断路器指标看板的更多相关文章

  1. SpringCloud2.0 Hystrix Dashboard 断路器指标看板 基础教程(八)

    1.启动基础工程 1.1.启动[服务中心]集群,工程名称:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) ...

  2. spring cloud 2.x版本 Hystrix Dashboard断路器教程

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

  3. SpringCloud2.0 Hystrix Feign 基于Feign实现断路器

    原文:https://www.cnblogs.com/songlu/p/9968953.html 1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 Sprin ...

  4. SpringCloud2.0 Hystrix Ribbon 基于Ribbon实现断路器

    原文:https://www.cnblogs.com/songlu/p/9949203.html 1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 Sprin ...

  5. SpringCloud2.0 Hystrix Feign 基于Feign实现断路器 基础教程(七)

    1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集 ...

  6. SpringCloud2.0 Hystrix Ribbon 基于Ribbon实现断路器 基础教程(六)

    1.启动[服务中心]集群,工程名:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) 2.启动[服务提供者]集 ...

  7. SpringCloud2.0 Turbine 断路器集群监控 基础教程(九)

    1.启动基础工程 1.1.启动[服务中心]集群,工程名称:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) ...

  8. SpringCloud学习系列之三----- 断路器(Hystrix)和断路器监控(Dashboard)

    前言 本篇主要介绍的是SpringCloud中的断路器(Hystrix)和断路器指标看板(Dashboard)的相关使用知识. SpringCloud Hystrix Hystrix 介绍 Netfl ...

  9. Spring Cloud 入门教程(八): 断路器指标数据监控Hystrix Dashboard 和 Turbine

    1. Hystrix Dashboard (断路器:hystrix 仪表盘)  Hystrix一个很重要的功能是,可以通过HystrixCommand收集相关数据指标. Hystrix Dashboa ...

随机推荐

  1. const 变量在多个文件共享,如何验证两种不同的方式下,编译器是否会在多个文件下建立多个副本

    对于const变量多个文件共享,当我们不希望编译器为每个文件分别生成独立的变量,而是像非常量对象一个,一处定义,多处声明并使用. 解决办法是,对于const变量,不管是声明还是定义都添加extern关 ...

  2. Java集合详解7:一文搞清楚HashSet,TreeSet与LinkedHashSet的异同

    <Java集合详解系列>是我在完成夯实Java基础篇的系列博客后准备开始写的新系列. 这些文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查 ...

  3. es6 Decorator修饰器

    1.类的修饰: 修饰器(Decorator)函数,用来修改类的行为.修饰器是一个对类进行处理的函数.修饰器函数的第一个参数,就是所要修饰的目标类. @testable class MyTestable ...

  4. 《Linux就该这么学》培训笔记_ch11_使用Vsftpd服务传输文件

    <Linux就该这么学>培训笔记_ch11_使用Vsftpd服务传输文件 文章最后会post上书本的笔记照片. 文章主要内容: 文件传输协议 Vsftpd服务程序 匿名访问模式 本地用户模 ...

  5. html5 audio标签切换播放音乐的方法

    html5 audio标签切换播放音乐的方法<pre><audio id="music1" preload loop="loop">&l ...

  6. spring boot 从开发到部署上线(简明版)

    我们组有一个优良传统--借鉴于"冰桶挑战赛"的形式,采取点名的方式,促进团队成员每天利用一小段时间,不断的完善团队 wiki 的小游戏. 但有时候忙于业务,可能会忘记,所以我写了一 ...

  7. 红黑树和AVL树的区别(转)

    add by zhj: AVL树和红黑树都是平衡二叉树,虽然AVL树是最早发明的平衡二叉树,但直接把平衡二叉树等价于AVL树,我认为非常不合适. 但很多地方都在这么用.两者的比较如下 平衡二叉树类型 ...

  8. FusionInsight大数据开发---Kafka应用开发

    Kafka应用开发 了解Kafka应用开发适用场景 熟悉Kafka应用开发流程 熟悉并使用Kafka常用API 进行Kafka应用开发 Kafka的定义Kafka是一个高吞吐.分布式.基于发布订阅的消 ...

  9. 使用 Navicat Premium 将 sql server 的数据库迁移到 mysql 的数据库中

    步骤1,打开 Navicat Premium ,创建一个新的 mysql 数据库: 步骤2,选中刚刚创建的新数据库 ,双击选中后点击导入向导,然后选择 "ODBC",并点击下一步 ...

  10. css 光标

    <style> div{width:100;height:50;float:left;border:1px solid red;margin:1px;} </style> &l ...