spring cloud 在初次使用 hystrix dashboard仪表盘的时候很容易出现hystrix dashboard Unable to connect to Command Metric Stream错误

如下图:

首先查看依赖时候添加全

        <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-hystrix</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

其次启动程序注解是否添加

@EnableCircuitBreaker
@EnableHystrixDashboard

如果都没问题那么检查下springboot 版本如果是2.0则需要添加 ServletRegistrationBean 因为springboot的默认路径不是 "/hystrix.stream",只要在自己的项目里配置上下面的servlet就可以了

    @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;
}

修改完成重启服务问题便会解决

分析:

首先,查看源码中 类 HystrixStreamEndpoint 从中可以看到 new EndpointServlet(HystrixMetricsStreamServlet.class)

package org.springframework.cloud.netflix.hystrix;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import java.util.Map;
import java.util.function.Supplier;
import org.springframework.boot.actuate.endpoint.web.EndpointServlet;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint; @ServletEndpoint(
id = "hystrix.stream"
)
public class HystrixStreamEndpoint implements Supplier<EndpointServlet> {
private final Map<String, String> initParameters; public HystrixStreamEndpoint(Map<String, String> initParameters) {
this.initParameters = initParameters;
} public EndpointServlet get() {
return (new EndpointServlet(HystrixMetricsStreamServlet.class)).withInitParameters(this.initParameters);
}
}

然后,我们再查看 HystrixMetricsStreamServlet 这个类 在方法的注释中我们可以看到

有提示 “Adding the following to web.xml”

而在springboot中是采用bean的形式配置就可以解决问题了

package com.netflix.hystrix.contrib.metrics.eventstream;

import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet;
import com.netflix.hystrix.metric.consumer.HystrixDashboardStream;
import com.netflix.hystrix.serial.SerialHystrixDashboardData;
import rx.Observable;
import rx.functions.Func1; import java.util.concurrent.atomic.AtomicInteger; /**
* Streams Hystrix metrics in text/event-stream format.
* <p>
* Install by:
* <p>
* 1) Including hystrix-metrics-event-stream-*.jar in your classpath.
* <p>
* 2) Adding the following to web.xml:
* <pre>{@code
* <servlet>
* <description></description>
* <display-name>HystrixMetricsStreamServlet</display-name>
* <servlet-name>HystrixMetricsStreamServlet</servlet-name>
* <servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
* </servlet>
* <servlet-mapping>
* <servlet-name>HystrixMetricsStreamServlet</servlet-name>
* <url-pattern>/hystrix.stream</url-pattern>
* </servlet-mapping>
* } </pre>
*/
public class HystrixMetricsStreamServlet extends HystrixSampleSseServlet { private static final long serialVersionUID = -7548505095303313237L; /* used to track number of connections and throttle */
private static AtomicInteger concurrentConnections = new AtomicInteger(0);
private static DynamicIntProperty maxConcurrentConnections =
DynamicPropertyFactory.getInstance().getIntProperty("hystrix.config.stream.maxConcurrentConnections", 5); public HystrixMetricsStreamServlet() {
this(HystrixDashboardStream.getInstance().observe(), DEFAULT_PAUSE_POLLER_THREAD_DELAY_IN_MS);
} /* package-private */ HystrixMetricsStreamServlet(Observable<HystrixDashboardStream.DashboardData> sampleStream, int pausePollerThreadDelayInMs) {
super(sampleStream.concatMap(new Func1<HystrixDashboardStream.DashboardData, Observable<String>>() {
@Override
public Observable<String> call(HystrixDashboardStream.DashboardData dashboardData) {
return Observable.from(SerialHystrixDashboardData.toMultipleJsonStrings(dashboardData));
}
}), pausePollerThreadDelayInMs);
} @Override
protected int getMaxNumberConcurrentConnectionsAllowed() {
return maxConcurrentConnections.get();
} @Override
protected int getNumberCurrentConnections() {
return concurrentConnections.get();
} @Override
protected int incrementAndGetCurrentConcurrentConnections() {
return concurrentConnections.incrementAndGet();
} @Override
protected void decrementCurrentConcurrentConnections() {
concurrentConnections.decrementAndGet();
}
}

hystrix dashboard Unable to connect to Command Metric Stream解决办法的更多相关文章

  1. springboot1.4下hystrix dashboard Unable to connect to Command Metric Stream解决办法

    搜索了好多资料,最后查看了官网.但是还是解决了.和大家分享下喜悦心情 在 此项目properties中添加如下信息 修改完信息后再浏览器输入:http://localhost:9875/hystrix ...

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

    环境: <java.version>1.8</java.version><spring-boot.version>2.0.4.RELEASE</spring- ...

  3. Hystrix dashboard - Unable to connect to Command Metric Stream.

    在使用boot 2.0.*以上版本 + cloud Finchley.RELEASE 查看仪表盘的时候会报错 Unable to connect to Command Metric Stream &l ...

  4. SpringCloud-Hystrix Dashboard 之 Unable to connect to Command Metric Stream

    实践hystrix dashboard仪表盘的时候,不管是按照书上的还是网上的,都提示Unable to connect to Command Metric Stream. 查了好久发现,如果使用sp ...

  5. 升级10.11后使用CocoaPod出现-bash: pod: command not found 解决办法-备

    升级10.11后,运行pod命令出现: -bash: pod: command not found 解决办法: sudo gem install -n /usr/local/bin cocoapods ...

  6. 服务器发送邮件出现Could not connect to SMTP host错误 解决办法

    服务器发送邮件出现Could not connect to SMTP host错误 解决办法 功夫不负有心人,最后了解到,除了google的smtp服务器收到请求“smtp”会接受,其他服务器比如qq ...

  7. Unable to connect to your virtual device!解决方法

    使用Genymotion安卓模拟器的用户,很多朋友在启动安卓系统的时候就弹出了以下英文,不知道如何处理,今天电脑知识网小编来教您处理Genymotion安卓模拟器启动出错的问题. Error Unab ...

  8. Unable to execute dex: java.nio.BufferOverflowException.解决办法

    异常提示: [2014-01-16 09:27:35 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Ch ...

  9. Unable to find the ncurses libraries的解决办法

    我们在更新CentOS或者Ubuntu的内核时,执行make menuconfig可能看如这样的错误: *** Unable to find the ncurses libraries or the* ...

随机推荐

  1. 简单透彻理解JSONP原理及使用

    首先提一下JSON这个概念,JSON是一种轻量级的数据传输格式,被广泛应用于当前Web应用中.JSON格式数据的编码和解析基本在所有主流语言中都被实现,所以现在大部分前后端分离的架构都以JSON格式进 ...

  2. V4L2学习记录【转】

    转自:http://blog.chinaunix.net/uid-30254565-id-5637600.html V4L2学习记录 这个还没有分析完,先在这放着,防止电脑坏掉丢了,以后再完善 V4L ...

  3. Ubuntu/Debian apt-get 404 Not Found Package Repository Errors,无法找到包的错误

    最简单最常用的方法是,使用如下命令更新到新的版本: sudo apt-get dist-upgrade 但是这个方法有时候不一定能起作用,那么可以使用以下直接替换的命令: sudo sed -i -e ...

  4. HTML学习笔记04-样式

    HTML<style>属性 style属性的作用: 提供了一种改变所有HTML元素样式的通用方法 background-colco属性为元素定义了背景颜色: <!DOCTYPE HT ...

  5. Python select IO多路复用

    一.select介绍 Python的select()函数是底层操作系统实现的直接接口.它监视套接字,打开文件和管道(任何带有返回有效文件描述符的fileno()方法),直到它们变得可读或可写,或者发生 ...

  6. Expm 9_1 有向图中环的判断问题

    [问题描述] 给定一个有向图,要求使用深度优先搜索策略,判断图中是否存在环. package org.xiu68.exp.exp9; public class Exp9_1 { //用深度优先搜索判断 ...

  7. 解决Idea运行testng套件无testoutput文件夹问题

    说明:testNG的工程我是使用eclipse创建的,直接导入到idea中,运行test时不会生产test-output,只能在idea的控制台中查看运行结果,然后到处报告,经过不懈的百度终于找到怎么 ...

  8. xshell xftp免费版下载方法

    第一步:进入官网 https://www.netsarang.com/ 第二步:选中Free License 第三步:选中你要下的xftp或者xsell (l两个好像不能一块下,都要单独操作) 第四步 ...

  9. 转:MySQL如何修改密码

    转:https://www.cnblogs.com/yang82/p/7794712.html. 第一种方式: 最简单的方法就是借助第三方工具Navicat for MySQL来修改,方法如下: 1. ...

  10. vue系列之webpack

    webpack 地址: https://github.com/vuejs-templates/webpack 注意里面的template,用webpack创建的项目,结构就是这样的