hystrix dashboard Unable to connect to Command Metric Stream解决办法
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解决办法的更多相关文章
- springboot1.4下hystrix dashboard Unable to connect to Command Metric Stream解决办法
搜索了好多资料,最后查看了官网.但是还是解决了.和大家分享下喜悦心情 在 此项目properties中添加如下信息 修改完信息后再浏览器输入:http://localhost:9875/hystrix ...
- 【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- ...
- Hystrix dashboard - Unable to connect to Command Metric Stream.
在使用boot 2.0.*以上版本 + cloud Finchley.RELEASE 查看仪表盘的时候会报错 Unable to connect to Command Metric Stream &l ...
- SpringCloud-Hystrix Dashboard 之 Unable to connect to Command Metric Stream
实践hystrix dashboard仪表盘的时候,不管是按照书上的还是网上的,都提示Unable to connect to Command Metric Stream. 查了好久发现,如果使用sp ...
- 升级10.11后使用CocoaPod出现-bash: pod: command not found 解决办法-备
升级10.11后,运行pod命令出现: -bash: pod: command not found 解决办法: sudo gem install -n /usr/local/bin cocoapods ...
- 服务器发送邮件出现Could not connect to SMTP host错误 解决办法
服务器发送邮件出现Could not connect to SMTP host错误 解决办法 功夫不负有心人,最后了解到,除了google的smtp服务器收到请求“smtp”会接受,其他服务器比如qq ...
- Unable to connect to your virtual device!解决方法
使用Genymotion安卓模拟器的用户,很多朋友在启动安卓系统的时候就弹出了以下英文,不知道如何处理,今天电脑知识网小编来教您处理Genymotion安卓模拟器启动出错的问题. Error Unab ...
- Unable to execute dex: java.nio.BufferOverflowException.解决办法
异常提示: [2014-01-16 09:27:35 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Ch ...
- Unable to find the ncurses libraries的解决办法
我们在更新CentOS或者Ubuntu的内核时,执行make menuconfig可能看如这样的错误: *** Unable to find the ncurses libraries or the* ...
随机推荐
- http raw post 之理解
参考链接: https://imququ.com/post/four-ways-to-post-data-in-http.html http://blog.csdn.net/leyangjun/art ...
- C# ASP.NET MVC 配置允许跨域访问
在web.config文件中的 system.webServer 节点下 增加如下配置 <httpProtocol> <customHeaders> <add name= ...
- Python中的__init__()和__call__()函数
Python中的__init__()和__call__()函数 在Python的class中有一些函数往往具有特殊的意义.__init__()和__call__()就是class很有用的两类特殊的函数 ...
- caffe源码阅读(1)_整体框架和简介(摘录)
原文链接:https://www.zhihu.com/question/27982282 1.Caffe代码层次.回答里面有人说熟悉Blob,Layer,Net,Solver这样的几大类,我比较赞同. ...
- 利用capability特征加强Linux系统安全【转】
转自:https://blog.csdn.net/fivedragon/article/details/676849 1.简介 UNIX是一种安全操作系统,它给普通用户尽可能低的权限,而把全部的系统权 ...
- C++:MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStart
在VS2013中Build一个C++程序报这个错,解决方案如下: 在解决方案管理器中选择该项目,项目/属性/连接器/系统/子系统 把控制台 (/SUBSYSTEM:CONSOLE)改为 窗口 (/SU ...
- WebRTC服务器——Licode 环境搭建
WebRTC服务器--Licode 环境搭建 系统配置 阿里云服务器 Ubuntu 14.04.5 LTS Docker 环境搭建 在一台空的机器上搭建docker环境,先要安装docker,执行下面 ...
- centos重启报错Umounting file systems:umount:/opt:device is busy
系统重启报错: Umounting file systems:umount:/opt:device is busy 只能硬关机,回想一下最近刚安装了nod32 for linux x64的杀毒软件,开 ...
- Expm 9_3 无向图的双连通分量问题
[问题描述] 给定一个无向图,设计一个算法,判断该图中是否存在关节点,并划分双连通分量. package org.xiu68.exp.exp9; import java.util.Stack; p ...
- SQL表链接