原创

SpringCloud Turbine启动报错,收集端点找不到

温馨提示:
本文最后更新于 2019年12月03日,已超过 1,816 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

报错信息

com.netflix.turbine.monitor.instance.InstanceMonitor$MisconfiguredHostException: [{"timestamp":"2019-12-03T15:29:29.526+0000","status":404,"error":"Not Found","message":"No message available","path":"/actuator/hystrix.stream"}]

从上述错误中我们可以知道,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

参考文章:http://blog.didispace.com/spring-cloud-tips-4/

或者,还有一种办法就是随着它,

在Turbine的Spring boot 工程下,application.properties里添加

turbine.instanceUrlSuffix.default = /hystrix.stream 此次的配置依据你的服务实例的收集端点。

参考文章:https://blog.csdn.net/Keith_Walker/article/details/80579190

本文目录