【问题标题】:Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud无法使用 Spring Cloud 连接到 Hystrix Dashboard 的 Command Metric Stream
【发布时间】:2018-09-22 08:31:27
【问题描述】:

我有 Spring Cloud 的微服务项目,来自父级的 sn-p:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.SR3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

所有服务都在Eureka服务器下运行:

所有服务都运行良好。我可以打电话给邮递员打适当的电话,一切正常。

我有单独的服务来处理 Hystrix 仪表板,来自pom 的 sn-p:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>

配置主类:

@SpringBootApplication
@EnableHystrixDashboard
public class DashboardApp {
    public static void main(String[] args) {
        SpringApplication.run(DashboardApp.class, args);
    }
}

并配置yaml文件:

spring:
  application:
    name: Dashboard

server:
  port: 8000

eureka:
  client:
    fetchRegistry: true
    registerWithEureka: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka

我正在查看下一个仪表板:

来自控制台的完整堆栈跟踪是here。以下是一些sn-p:

2018-04-12 11:28:25.089 ERROR 15762 --- [qtp295055909-16] ashboardConfiguration$ProxyStreamServlet : Error proxying request: http://localhost:8082/hystrix.stream
java.lang.RuntimeException: org.eclipse.jetty.io.EofException
    at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:208)
....
Caused by: org.eclipse.jetty.io.EofException: null
...
Caused by: java.io.IOException: Broken pipe
...

服务本身可以通过弹簧执行器访问:

sn-p 从它的pom:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

配置类外观:

@EnableHystrix
@EnableEurekaClient
@SpringBootApplication
public class TableApp {
    public static void main(String[] args) {
        SpringApplication.run(TableApp.class, args);
    }
}

如何解决这个问题?

【问题讨论】:

标签: spring spring-boot spring-cloud runtimeexception hystrix


【解决方案1】:
  1. 将您的 hystrix.stream 网址更正为 http://localhost:8082/actuator/hystrix.stream
  2. 在 hystrix 应用程序的配置文件中公开“hystrix.steam”网络端点:
management:
  endpoints:
    web:
      exposure:
        include: 'hystrix.stream'
  1. 确保您已将主机添加到hystrix.dashboard.proxyStreamAllowList,在您的 hystrix-dashboard 应用程序的配置文件中,如下所示:
hystrix:
  dashboard:
    proxy-stream-allow-list:
      - 'localhost'

【讨论】:

    【解决方案2】:

    我在使用最新版本的 Spring-boot(2.3.3-XXX) 和 spring-cloud (Hoxton.SR7) 时遇到了同样的问题,但是当我在 pom.xml 文件中降级版本时,它开始正常工作对我来说。

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.16.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR6</spring-cloud.version>
    </properties>
    

    希望,这会有所帮助:)

    【讨论】:

      【解决方案3】:

      通过在 application.properties 中添加以下两个属性,我能够为 spring-boot-starter-parent 版本 2.0.7.RELEASEspring-cloud-dependencies 版本 Finchley.SR2 解决此问题。

      management.endpoints.web.exposure.include=*
      management.endpoints.web.base-path=/
      

      【讨论】:

        【解决方案4】:

        对于使用 Spring Boot 2 的用户,hystrix.stream 端点已移至 /actuator/hystrix.stream

        对我来说,这个网址有效:

        http://localhost:8082/actuator/hystrix.stream
        

        是的,通过以下属性启用此执行器端点:

        management.endpoints.web.exposure.include=hystrix.stream
        

        当然,您的项目中必须包含执行器依赖项。

        【讨论】:

        【解决方案5】:

        终于找到了解决办法。

        问题是控制器 API 必须通过 HystrixCommand 注释来销售。

        来自文档的片段:

        Turbine AMQP by Spring Cloud offers a different model where each
        application instance pushes the metrics from Hystrix commands to
        Turbine through a central AMQP broker.
        

        我将它不带任何参数添加到所有 Controller 的方法中,如下所示:

        @RestController
        @AllArgsConstructor
        public class GuestController {
            private DinnerService dinnerService;
        
            @HystrixCommand
            @PostMapping("/dinner")
            public Integer startDinner(@RequestBody List<Integer> menuItems) {
                return dinnerService.startDinner(menuItems);
            }
        
            @HystrixCommand
            @DeleteMapping("/dinner/{tableId}")
            public void finishDinner(@PathVariable Integer tableId) {
                dinnerService.finishDinner(tableId);
            }
        }
        

        现在一切都很迷人:

        现在我明白了,我是如此接近它。

        【讨论】:

        【解决方案6】:

        Hystrix 仪表板本身不能用于同时监控多个实例。你需要的是turbine+dashboard。简而言之,turtle 是几个 hystrix 指标流的聚合器。

        实例配置:

        management:
          endpoints:
            web:
              exposure:
                include: hystrix.stream, info, health
        
        spring:
          application:
            name: WRITING
        eureka:
          client:
            serviceUrl:
              defaultZone: http://localhost:8761/eureka
        

        这里重要的是暴露 hystix.stream 执行器。涡轮机将使用此端点来读取指标。另外,不要忘记添加执行器启动器。

           <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-actuator</artifactId>
           </dependency>
        

        如果你做的一切都正确http://localhost:8080/actuator/hystrix.stream端点应该可用。

        涡轮配置如下所示:

        server:
              port: 8888
        
        spring:
          application:
            name: TURBINE
        
        eureka:
          client:
            registerWithEureka: true
            fetchRegistry: true
            serviceUrl:
              defaultZone: http://localhost:8761/eureka/
        
        turbine:
          appConfig: WRITING,READING
          clusterNameExpression: new String('default')
        

        appConfig 中,您应该指定用于监控的服务名称。

        启动涡轮机后,localhost:8888/turbine.stream 将可用。

        您可以将此 URL 传递到仪表板并监控所有为已发现实例的 hystrix 命令聚合的数据。

        Github 项目示例。

        附言 您使用的依赖项已被弃用。请查看maven repo

        【讨论】:

        • 我在服务的配置文件中添加了management 部分。已添加执行器依赖项。但是,http://localhost:8082/actuator/hystrix.stream 显示 Whitelabel Error Page。此外,http://localhost:8082/healthhttp://localhost:8082/hystrix.stream 显示的信息与我在问题中提到的相同。
        • @nazar_art 似乎我已经注意到了不同之处。当我使用 spring-cloud-starter-netflix-hystrix 时,您正在使用 spring-cloud-starter-hystrix。 hystrix-dashboard 也一样。可以换吗?
        • 我试图改变它,我的服务失败了Exception in thread "main" java.lang.NoClassDefFoundError: com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect
        • @nazar_art 用 github repo 链接和工作示例更新了我的答案。
        • 长话短说,失败的原因有几个:ReadingApplication, Dashboard
        猜你喜欢
        • 2016-03-20
        • 2019-02-07
        • 2020-05-01
        • 2019-06-15
        • 2018-10-05
        • 2020-08-22
        • 2016-12-08
        • 1970-01-01
        • 2014-12-04
        相关资源
        最近更新 更多