无法使用Spring Cloud连接到Hystrix Jmeter 板的命令度量流

k10s72fa  于 2022-11-21  发布在  Spring
关注(0)|答案(8)|浏览(153)

我有一个使用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 服务器下运行:

所有的服务都运行良好。我可以打电话给 Postman 打适当的电话,一切都很好。
我有一个单独的服务来处理Hystrix dashboard,这是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);
    }
}

和配置yaml文件:

spring:
  application:
    name: Dashboard

server:
  port: 8000

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

我有下一个 Jmeter 板看:

来自控制台的完整堆栈跟踪是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
...

使用Spring执行机构可进行维修:

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

如何解决此问题?

uoifb46i

uoifb46i1#

对于使用Sping Boot 2的用户,hystrix.stream端点已移至/actuator/hystrix.stream
对我来说,这个网址工作:

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

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

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

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

iqxoj9l9

iqxoj9l92#

Hystrix dashboard本身不能用于同时监控多个示例。您需要的是turbine +dashboard。简而言之,涡轮机是多个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传递到 Jmeter 板,并监视为发现的示例的hystrix命令聚合的所有数据。
Github项目示例。
p.s.您使用的依赖项已过时。请检查maven repo

htrmnn0y

htrmnn0y3#

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

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

lyfkaqu1

lyfkaqu14#

最后,我找到了解决办法。
问题是控制器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);
    }
}

而现在一切都像迷人的作品:

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

of1yzvn4

of1yzvn45#

请确定您已将此项目加入application.properties中。

hystrix.dashboard.proxy-stream-allow-list=localhost
6za6bjd0

6za6bjd06#

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

希望,这会很有帮助:)

fnvucqvd

fnvucqvd7#

1.将您的hystrix.stream网址更正为http://localhost:8082/actuator/hystrix.stream

  1. hystrix应用程序的配置文件中暴露“hystrix.steam”Web终结点:
management:
  endpoints:
    web:
      exposure:
        include: 'hystrix.stream'

1.确保已将主机添加到hystrix-dashboard应用程序的配置文件中的hystrix.dashboard.proxyStreamAllowList,如下所示:

hystrix:
  dashboard:
    proxy-stream-allow-list:
      - 'localhost'
a8jjtwal

a8jjtwal8#

查看github上的详细信息:https://github.com/HuiyingWang0108/hystrix-dashboard相关微服务:https://github.com/HuiyingWang0108/cloud-gatewayhttps://github.com/HuiyingWang0108/registry-service在我的例子中:像这样的应用程序:

步骤1:(1)修改pom.xml:

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

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>

(2)添加到下面的应用程序中。yml

hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

(3)然后启动应用程序,打开:

http://localhost:9295/hystrix

作品:
步骤2:(1)在pom.xml中添加以下内容

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

(2)在应用程序中添加以下内容.yml

management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream, info, health

(3)打开:显示:

相关问题