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* ...
随机推荐
- 3d图像识别基础论文:pointNet阅读笔记
PointNet 论文阅读: 主要思路:输入独立的点云数据,进行变换不变性处理(T-net)后,通过pointNet网络训练后,最后通过最大池化和softMax分类器,输出评分结果. 摘要: 相较于之 ...
- 2017-2018-2 20155303『网络对抗技术』Exp7:网络欺诈防范
2017-2018-2 『网络对抗技术』Exp7:网络欺诈防范 --------CONTENTS-------- 一.原理与实践说明 1.实践目标 2.实践内容概述 3.基础问题回答 二.实践过程记录 ...
- Arduino语法详解_含示例详解
Arduino 的程序可以划分为三个主要部分:结构.变量(变量与常量).函数. 结构部分 一.结构 1.1 setup() 1.2 loop() 二.结构控制 2.1 if 2.2 if...else ...
- 【转】理解*(void**)
#include <stdio.h> int main() { int *p; ; unsigned ; p = &a; printf("%d\n", *p); ...
- Hyper-V虚拟机上安装一个图形界面的Linux系统
这件事情呢,一直想干但又觉得太陌生和麻烦,无奈现在到了非装不可的时候,只好硬着头皮去装.在此之前,我不懂什么叫做虚拟机,linux也接触甚少.经过3天的折腾,终于装好了带有图形界面的linux(字符版 ...
- 基于 OpenSSL 的 CA 建立及证书签发
http://rhythm-zju.blog.163.com/blog/static/310042008015115718637/ 建立 CA 建立 CA 目录结构 按照 OpenSSL 的默认配置建 ...
- Go语言规格说明书 之 通道类型(Channel types)
go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,介绍Go语言的 ...
- Android开发之Activity转场动画
引子 相信开发过iOS的程序员都知道iOS ViewController之间的跳转动画非常多,很酷对不对?这让开发Android的羡慕不已,曾几何时,Android中的Activity跳转是何等的生硬 ...
- 使用Springboot快速搭建SSM框架
Spring Boot设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 一.环境准备 Idea 2017 或 201 ...
- react之自定义迷你redux的实现
export function createStore(reducer){ let currentState={} let currentListeners=[] function getState( ...