日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Cloud实战小贴士:turbine如何聚合设置了context-path的hystrix数据

發布時間:2024/7/5 javascript 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud实战小贴士:turbine如何聚合设置了context-path的hystrix数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

之前在spring for all社區看到這樣一個問題:當actuator端點設置了context-path之后,turbine如何聚合數據?首先,我們要知道actuator端點設置了context-path是什么意思?也就是說,此時spring boot actuator的端點都有了一個前綴,比如:

management.context-path=/xxx

如果設置了上面的參數,那個對于收集hystrix數據的端點將變為:/xxx/hystrix.stream,如果我們還是拿上一篇Spring Cloud構建微服務架構:Hystrix監控數據聚合【Dalston版】中構建你的turbine應用,那么將會看到如下錯誤:

INFO 7812 --- [ Timer-0] c.n.t.monitor.instance.InstanceMonitor : Url for host: http://172.15.0.18:9020/hystrix.stream default
ERROR 7812 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor : Could not initiate connection to host, giving up: [{"timestamp":1499941336284,"status":404,"error":"Not Found","message":"No message available","path":"/hystrix.stream"}]
WARN 7812 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor : Stopping InstanceMonitor for: 172.15.0.18:9020 default

com.netflix.turbine.monitor.instance.InstanceMonitor$MisconfiguredHostException: [{"timestamp":1499941336284,"status":404,"error":"Not Found","message":"No message available","path":"/hystrix.stream"}]
at com.netflix.turbine.monitor.instance.InstanceMonitor.init(InstanceMonitor.java:318) ~[turbine-core-1.0.0.jar:na]
at com.netflix.turbine.monitor.instance.InstanceMonitor.access$100(InstanceMonitor.java:103) ~[turbine-core-1.0.0.jar:na]
at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:235) [turbine-core-1.0.0.jar:na]
at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:229) [turbine-core-1.0.0.jar:na]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]

從上述錯誤中我們可以知道,turbine在收集的時候由于訪問的是/hystrix.stream,而此時收集端點卻是/xxx/hystrix.stream,所以報了404錯誤。

那么我們要如何解決呢?通過之前的配置內容,我們可能找不到相關的配置信息,所以只能遍歷一下源碼,最后找到這個類:org.springframework.cloud.netflix.turbine.SpringClusterMonitor。它的具體內容如下:

public static InstanceUrlClosure ClusterConfigBasedUrlClosure = new InstanceUrlClosure() {

private final DynamicStringProperty defaultUrlClosureConfig = DynamicPropertyFactory
.getInstance().getStringProperty("turbine.instanceUrlSuffix",
"hystrix.stream");
private final DynamicBooleanProperty instanceInsertPort = DynamicPropertyFactory
.getInstance().getBooleanProperty("turbine.instanceInsertPort", true);

@Override
public String getUrlPath(Instance host) {
if (host.getCluster() == null) {
throw new RuntimeException(
"Host must have cluster name in order to use ClusterConfigBasedUrlClosure");
}

// find url
String key = "turbine.instanceUrlSuffix." + host.getCluster();
DynamicStringProperty urlClosureConfig = DynamicPropertyFactory.getInstance()
.getStringProperty(key, null);
String url = urlClosureConfig.get();
if (url == null) {
url = this.defaultUrlClosureConfig.get();
}
if (url == null) {
throw new RuntimeException("Config property: "
+ urlClosureConfig.getName() + " or "
+ this.defaultUrlClosureConfig.getName() + " must be set");
}

// find port and scheme
String port;
String scheme;
if (host.getAttributes().containsKey("securePort")) {
port = host.getAttributes().get("securePort");
scheme = "https";
} else {
port = host.getAttributes().get("port");
scheme = "http";
}
if (host.getAttributes().containsKey("fusedHostPort")) {
return String.format("%s://%s/%s", scheme, host.getAttributes().get("fusedHostPort"), url);
}

// determine if to insert port
String insertPortKey = "turbine.instanceInsertPort." + host.getCluster();
DynamicStringProperty insertPortProp = DynamicPropertyFactory.getInstance()
.getStringProperty(insertPortKey, null);
boolean insertPort;
if (insertPortProp.get() == null) {
insertPort = this.instanceInsertPort.get();
}
else {
insertPort = Boolean.parseBoolean(insertPortProp.get());
}

// format url with port
if (insertPort) {
if (url.startsWith("/")) {
url = url.substring(1);
}
if (port == null) {
throw new RuntimeException(
"Configured to use port, but port or securePort is not in host attributes");
}

return String.format("%s://%s:%s/%s", scheme, host.getHostname(), port, url);
}

//format url without port
return scheme + "://" + host.getHostname() + url;
}
};

從上述源碼中,我們可以找到這個參數turbine.instanceUrlSuffix,由此該問題就迎刃而解了,我們只需要在turbine應用的配置文件中增加如下配置信息,就能正確的收集之前配置了management.context-path=/xxx的微服務的hystrix數據了。

turbine.instanceUrlSuffix=/xxx/hystrix.stream

相關閱讀

  • Spring Cloud構建微服務架構:服務注冊與發現(Eureka、Consul)
  • Spring Cloud構建微服務架構:服務消費者(基礎)
  • Spring Cloud構建微服務架構:服務消費者(Ribbon)
  • Spring Cloud構建微服務架構:服務消費者(Feign)
  • Spring Cloud構建微服務架構:分布式配置中心
  • Spring Cloud構建微服務架構:服務容錯保護(hystrix服務降級)
  • Spring Cloud構建微服務架構:服務容錯保護(hystrix依賴隔離)
  • Spring Cloud構建微服務架構:服務容錯保護(hystrix斷路器)
  • Spring Cloud構建微服務架構:Hystrix監控面板
  • Spring Cloud構建微服務架構:Hystrix監控數據聚合
  • 更多Spring Cloud內容…

總結

以上是生活随笔為你收集整理的Spring Cloud实战小贴士:turbine如何聚合设置了context-path的hystrix数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。