环境:

<java.version>1.8</java.version>
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<lcn.last.version>4.2.1</lcn.last.version>

一.首先说在spring cloud的每个微服务中配置Hystrix Dashboard

>Dashboard代表仪表盘,作用是用于展示微服务之间调用时的监控。

>这里说明的是服务间进行feign调用时,微服务配置Dashboard的步骤

>这里说的是,在每一个业务服务上添加Dashboard的步骤,不是单独抽离出来一个Dashboard服务

>配置Dashboard之前,微服务直接按已经完成了feign的调用,并且已经在feignClient上设置了熔断器

【ms-member服务(port:9000) 调用 ms-integral服务(port:9002)】

【ms-member服务是服务调用方,通过feign调用ms-integral服务,ms-integral是服务提供方】

1.首先每一个需要配置Dashboard仪表盘的微服务都需要添加依赖

<!--熔断器 健康检查-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--熔断器 Dashboard-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

2.启动类上添加注解

@EnableCircuitBreaker
@EnableHystrixDashboard//展示熔断器仪表盘

3.spring boot2.0以后,不提供 hystrix.stream节点,需要自己添加【可以不加@Service放在启动类,也可以加上@Service或者@Component放在一个单独的文件中,只要能注入spring中为Bean即可】

【解决:Hystrix仪表盘Unable to connect to Command Metric Stream的问题,就是这一步骤以上的这些都配置了即可解决这个问题】

/**
* SpringBoot2.0以后,不提供 hystrix.stream节点,需要自己增加
*/
@Service
public class HystrixStreamServlet { @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;
}
}

4.配置完成,即可分别启动ms-member和ms-integral服务, 启动后:

ms-member服务显示如下:

此时访问地址:

http://localhost:9000/hystrix

即可访问ms-member这个服务的熔断器仪表盘

在输入框输入:

http://localhost:9000/hystrix.stream

点击按钮

【解决:Hystrix仪表盘Loading...的问题】

跳转进来发现Hystrix仪表盘Loading...

原因:是因为并没有进行feign调用ms-intergral,所以暂时没有记录

直接访问http://localhost:9000/hystrix.stream 也可以发现一直在ping:

此时,可以访问一下ms-member中调用ms-integral服务的一个接口:

http://localhost:9000/member/save

本接口即保存会员,并且 调用ms-intergral 保存会员的原始积分记录。

调用feign的接口访问后,就可以看到

同理,按上面的步骤访问ms-integral服务的Hystrix Dashboard,因为ms-integral服务并没有调用别的服务的feign,所以它的依旧是loading...并且ping:一直没有消息反馈。

最后附一张说明

二.来说一说搭建Turbine 

在使用Hystrix Dashboard组件监控服务的熔断器状况时,每个服务都有一个Hystrix Dashboard主页,服务数量过多时,监控非常不方便。Netflix开源了另一个组件Turbine,用于聚合多个Hystrix Dashboard,将数据显示在一个页面上,集中监控。

新建一个Turbine服务,用于集中展示各个服务的feign调用的情况,也就是上面的各个服务的Hystrix Dashboard仪表盘。

【ms-member服务在一个接口中  分别调用ms-integral服务和ms-goods服务】

【ms-member port:9000】

【ms-integral port:9002】

【ms-goods port:9001】

1.pom.xml文件依赖有这些

<!--熔断器 健康检查-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--熔断器 Dashboard-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!--聚合依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

2.application.properties配置文件【注意,配置文件中turbine.instanceUrlSuffix=hystrix.stream 中配置的地址,是上面一中为每一个服务添加的spring boot2.0后需要自己添加的HystrixStreamServlet

spring.application.name=springcloud-ms-hystrix-turbine
server.port=10000
eureka.client.service-url.defaultZone=http://127.0.0.1:8000/eureka/ #turbine特定配置
#配置eureka中的服务列表,标明监控哪些服务
turbine.appConfig=springcloud-ms-integral,springcloud-ms-member,springcloud-ms-goods
#指定聚合哪些集群,多个使用”,”分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问
turbine.aggregator.clusterConfig= default
turbine.cluster-name-expression="default"
# 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称
# 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
# 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC #此处和每一个被监控服务中配置的HystrixStreamServlet自动加载Bean中配置的一样
turbine.instanceUrlSuffix=hystrix.stream #因为parent的pom.xml中 添加了连接数据库的依赖,所以 需要配置数据库连接相关配置
spring.datasource.continue-on-error=false
spring.datasource.url=jdbc:mysql://localhost:3306/springcloudtest?useSSL=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver #txmanager地址
tm.manager.url=http://127.0.0.1:7000/tx/manager/

3.启动类添加注解

package com.swapping.springcloud.ms.hystrix.turbine;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
import org.springframework.cloud.openfeign.EnableFeignClients; /**
*
* IP:turbine服务所在服务器IP localhost
* port:turbine服务所配置的服务端口 10000
* 监控项目访问: http://IP:port/turbine.stream
* 展示信息:
* ping:
* {.....}
*
*
*
* 图形化监控页面:http://IP:port/hystrix
*
* 图形化监控页面使用说明:
* 1.在进入豪猪主页后,在输入框输入http://localhost:10000/turbine.stream,点击Monitor Stream按钮
* 2.展示所有配置了Hystrix Dashboard仪表盘展示的 各个服务之间的feign调用情况
*/
@EnableTurbine//开启turbine
@EnableHystrixDashboard//开启仪表盘 @EnableDiscoveryClient
@SpringBootApplication
public class SpringcloudMsHystrixTurbineApplication { public static void main(String[] args) {
SpringApplication.run(SpringcloudMsHystrixTurbineApplication.class, args);
}
}

4.启动Turbine服务,并且分别启动 注册中心,ms-member服务,ms-integral服务,ms-goods服务,并访问调用服务的接口,真正的feign调用 调通一次。

5.访问Turbine的图形化访问界面

http://sxd:10000/hystrix

如上图,输入查看各个服务的图形化展示地址:

http://sxd:10000/turbine.stream

进入之后既可以看到集中展示的 图形化仪表盘监控页面

【spring cloud】spring cloud2.X spring boot2.0.4调用feign配置Hystrix Dashboard 和 集成Turbine 【解决:Hystrix仪表盘Unable to connect to Command Metric Stream】【解决:Hystrix仪表盘Loading...】的更多相关文章

  1. spring boot 2.0.3+spring cloud (Finchley)3、声明式调用Feign

    Feign受Retrofix.JAXRS-2.0和WebSocket影响,采用了声明式API接口的风格,将Java Http客户端绑定到他的内部.Feign的首要目标是将Java Http客户端调用过 ...

  2. Spring Cloud Zuul 网关使用与 OAuth2.0 认证授权服务

    API 网关的出现的原因是微服务架构的出现,不同的微服务一般会有不同的服务地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各个微服务通信,会有以下的问题: 客户端会 ...

  3. Spring Cloud 学习笔记(一)——入门、特征、配置

    [TOC] 0 放在前面 0.1 参考文档 http://cloud.spring.io/spring-cloud-static/Brixton.SR7/ https://springcloud.cc ...

  4. spring cloud 入门系列七:基于Git存储的分布式配置中心

    我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为 ...

  5. 一起来学spring Cloud | 第一章:spring Cloud 与Spring Boot

    目前大家都在说微服务,其实微服务不是一个名字,是一个架构的概念,大家现在使用的基于RPC框架(dubbo.thrift等)架构其实也能算作一种微服务架构. 目前越来越多的公司开始使用微服务架构,所以在 ...

  6. 译自如何将Spring Cloud应用程序从Spring Boot 1.2迁移到1.3

    前言 笔者第三个Spring Cloud(版本为Spring Boot 1.2)类项目升级最新版本时遇到不少问题,本文内容是作者翻译Spring Cloud官网一位国外友人文章产生. 原文地址: Mi ...

  7. spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config

    我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为 ...

  8. Spring Cloud(三):服务提供与调用 Eureka【Finchley 版】

    Spring Cloud(三):服务提供与调用 Eureka[Finchley 版]  发表于 2018-04-15 |  更新于 2018-05-07 |  上一篇文章我们介绍了 Eureka 服务 ...

  9. spring cloud (一):大话 Spring Cloud

    转自:http://www.ityouknow.com/springcloud/2017/05/01/simple-springcloud.html 研究了一段时间Spring Boot了准备向Spr ...

随机推荐

  1. 码云-中国的github

    # 域名城 https://www.domain.cn/ # 码云 https://gitee.com

  2. Redis (非关系型数据库) 数据类型 之 list列表类型

    Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边) list即可以作为“栈”也可以作为"队列". 操作: >lpush ...

  3. css兼容技巧

    CSS兼容常用技巧 请尽量用xhtml格式写代码,而且DOCTYPE影响 CSS 处理,作为W3C标准,一定要加DOCTYPE声明. 1.div的垂直居中问题 vertical-align:middl ...

  4. Tomcat架构解析(二)-----Connector、Tomcat启动过程以及Server的创建过程

    Connector用于跟客户端建立连接,获取客户端的Socket,交由Container处理.需要解决的问题有监听.协议以及处理器映射等等. 一.Connector设计   Connector要实现的 ...

  5. DocumentType类型

    并不常用 nodeType 10 nodeName doctype的名称 NodeValue 值为null parentNode Document 不支持子节点 DocumentType不能动态创建, ...

  6. servlet 解决乱码问题

    对于servlet大家应该都很熟悉了,今天再复习一下,如果有哪里写的不好或不对的地点希望广大的网友批评指正.今天只讨论get和post两w种方式,他们之间有很多的不同点,所以解决编码的方式也会不一样, ...

  7. 好文推荐系列--------(3)GruntJS 在线重载 提升生产率至新境界

    好文原文地址:http://segmentfault.com/a/1190000000354555 本文将首先介绍grunt-markdown插件如何配合HTML模板使用,接着我将介绍如何使用grun ...

  8. Android 全局搜索条写成自定义控件-曹永思

    图文: 1.Android 自定义控件的布局文件 2.编写Android 自定义控件的要处理的逻辑代码(曹永思) 3.在调用自定义控件的 Activity的布局文件中调用Android 称之为控件,控 ...

  9. 使用VBA宏批量修改表格

    一.批量修改表格,实现所有表格的宽度根据窗口自动调整. Sub test() ' ' test 宏 ' ' Dim i As Table, N As Integer On Error Resume N ...

  10. 属性动画和Activity、Fragment过渡动画等

    主题是关于动画的,但是不是什么动画的内容都包括.先泛泛的介绍一下,然后详细的介绍一下翻代码找见的一个好玩的动画的使用.以下的内容包括Android 3和Android 3.1等引入的API,在使用中请 ...