gpt4 book ai didi

java - Hystrix 仪表板不工作

转载 作者:行者123 更新时间:2023-11-30 02:47:11 26 4
gpt4 key购买 nike

我在 springboot 应用程序中使用 REST 服务。我正在使用 Hystrix 来启用指标。因此,我在版本7的tomcat服务器中部署了hystrix仪表板 war 。我能够打开页面http://localhost:8080/hystrix-dashboard/ 。添加流 url 并单击“监视流”按钮后,它会将我带到监视页面,我在其中只能看到消息“无法连接到命令 metrix 流”。当我查看 hystrix 控制台时,我反复看到以下消息。请帮助我!

2016-10-04 07:23:28 INFO  com.netflix.turbine.discovery.InstanceObservable$1:289 [InstanceObservable$1] [run]: Hosts up:1, hosts down: 0
2016-10-04 07:23:28 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:28 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:30 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:30 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:31 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:31 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:32 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:32 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:33 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:33 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:35 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:460 [InstanceMonitor] [getNextStatsData]: no more data from c
onnection to 138.12.51.246
2016-10-04 07:23:35 INFO com.netflix.turbine.monitor.instance.InstanceMonitor:477 [InstanceMonitor] [retryHostConnection]: Re-initing host
connection: 138.12.51.246 default
2016-10-04 07:23:36 INFO

最佳答案

找到了答案..我们需要在响应头中添加 MIME 类型作为 text/event-stream 。我在这里编写的修复程序专门针对 Springboot 与 Hystrix 仪表板的集成。您需要做的就是,

1) 在 pom.xml 中添加指标事件流依赖项

<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-metrics-event-stream</artifactId>
<version>1.5.5</version>
</dependency>

2) 在 SpringApplication 类中添加带有 Bean 注释的新 servlet

@Bean
public ServletRegistrationBean servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet(), "/hystrix.stream");
return registration;
}

3) 返回具有文本/事件流 MIME 类型的响应 header 的响应。即使您有另一种内容类型,例如 application/xml,也没关系,您也可以使用这个新内容类型。

HttpHeaders resHeaders = new HttpHeaders();
resHeaders.add("Content-Type", "application/xml; charset=utf-8");
resHeaders.add("Content-Type", "text/event-stream; charset=utf-8");
if(!isError){
return new ResponseEntity<String>(responseXml, resHeaders, HttpStatus.OK);
}
else{
return new ResponseEntity<com.test.pack.fault.Error>(error, resHeaders,HttpStatus.CREATED);
}

4)在版本7及以上的Tomcat服务器中下载并部署Hystrix仪表板war文件并启动服务器。

5) 使用 url http://localhost:port/hystrix-dashboard 打开仪表板

6) 在hystrix主页中,添加应用程序url为http://localhost:port/contextPath(if任何)/hystrix.stream。然后单击添加流按钮并单击监视流按钮。hystrix.stream 是我们在 servlet 注册中给出的 url 映射。

关于java - Hystrix 仪表板不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39851057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com