环境:

<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. 【搜索】Shuffle'm Up

    运用第i个s12和第i+1个s12中,每个位置具有的确定的映射关系: pos = pos * 2 + 1 (pos < c) pos = pos * 2 - c * 2 (pos >= c ...

  2. [C#.NET]最简单的实现文本框的水印效果

    C#项目开发中在设计登录界面时,经常会遇到TextBox的水印提示要求.这里简单描述一下项目在实现水印提示的过程设置.如下图图1所示. 图1  窗体布局 一.窗体布局(如图1所示) 1.  在窗体中放 ...

  3. ubuntu samba共享后windows读写文件都是以nogroup问题

    添加smb账号 sudo smbpasswd -a xxx 如果报错:Failed to add entry for user xxx 则是因为这个账号不存在 添加成功以后,过一会就可以重新登陆了(u ...

  4. python学习 day1 (3月1日)

    01 cpu 内存 硬盘 操作系统 CPU:中央处理器,相当于人大脑. 飞机 内存:临时存储数据. 8g,16g, 高铁 1,成本高. 2,断电即消失. 硬盘:长期存储大量的数据. 1T 512G等等 ...

  5. css中元素的位置

    一.display 1.display:none 隐藏标签 2.display:inline 将块级标签改为内联标签 3.display:block 将内联标签改为块级标签 4.display:inl ...

  6. 【转】linux tar 压缩

    tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...

  7. shell 常见面试

    1.求100以内的质数 #!/bin/bash n= ;i<=n;i++)) do ;x<=i;x++)) do b=$(( $i%$x )) ]]; then a=$a+ fi done ...

  8. GAME PROGRAMM

    SetConsoleTextAttribute consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE); GetStdHandle(nStdHandle)//是返回 ...

  9. 振动器(Vibrator)

    package com.wwj.serviceandboardcast;   import android.app.Activity; import android.app.Service; impo ...

  10. bzoj3262(cdq分治模板)

    裸的cdq,注意去重: #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...