无法使用Spring Cloud连接到Hystrix仪表板的Command Metric Stream

时间:2018-04-12 09:00:14

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

我有Spring Cloud的微服务项目,来自父母的片段:

<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服务器上运行:

enter image description here

所有服务都运行正常。我可以打电话给Postman打电话,一切正常。

我有单独的服务来处理Hystrix仪表板,这是pom的一个片段:

<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);
    }
}

和config yaml文件:

spring:
  application:
    name: Dashboard

server:
  port: 8000

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

我有下一个仪表板看:

enter image description here

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

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
...

弹簧执行器可以使用本身的服务:

enter image description here

摘自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>

Config类看起来:

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

如何解决此问题?

6 个答案:

答案 0 :(得分:6)

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

对我来说这个网址有效:

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

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

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

当然,您必须在项目中包含actutator依赖项。

答案 1 :(得分:2)

Hystrix仪表板本身不能同时用于监控多个实例。您需要的是turbine +仪表板。用两个词来说,Turb是几个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端点应该可用。

Turbine配置看起来像:

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项目示例。

P.S。 您已使用的依赖项已弃用。请检查maven repo

答案 2 :(得分:1)

最后,我找到了解决方案。

问题是Controller 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);
    }
}

现在一切都像迷人一样:

enter image description here

现在我知道我非常接近它。

答案 3 :(得分:1)

通过在 recycler.setLayoutManager(new LinearLayoutManager(this));中添加以下两个属性,我能够解决spring-boot-starter-parent版本2.0.7.RELEASEspring-cloud-dependencies版本Finchley.SR2的此问题

application.properties

enter image description here

答案 4 :(得分:0)

我在使用最新版本的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>

希望,这会有所帮助:)

答案 5 :(得分:0)

  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'