Spring Cloud's circuit breaker aggregation monitoring

 1. Introduction to Hystrix Turbine

Looking at the data of a single Hystrix Dashboard does not have much value. If you want to see the Hystrix Dashboard data of this system, you need to use Hystrix Turbine. Hystrix Turbine integrates each service Hystrix Dashboard data. The use of Hystrix Turbine is very simple, you only need to introduce the corresponding dependencies and add annotations and configurations.

2. Preparation

The project used in this article is the project of the previous article, and it will be transformed on this basis. Because we need multiple service Dashboards, we need to build another service, named service-lucy, whose basic configuration is the same as service-hi, see the source code for details, and will not elaborate here.

3. Create service-turbine

Introduce the corresponding dependencies:

<dependencies>

 <dependency>

 <groupId>org.springframework.cloud</groupId>

 <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

 </dependency>

 <dependency>

 <groupId>org.springframework.boot</groupId>

 <artifactId>spring-boot-starter-web</artifactId>

 </dependency>

 <dependency>

 <groupId>org.springframework.boot</groupId>

 <artifactId>spring-boot-starter-actuator</artifactId>

 </dependency>

 <dependency>

 <groupId>org.springframework.cloud</groupId>

 <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>

 </dependency>

 <dependency>

 <groupId>org.springframework.cloud</groupId>

 <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>

 </dependency>

 <dependency>

 <groupId>org.springframework.cloud</groupId>

 <artifactId>spring-cloud-starter-netflix-turbine</artifactId>

 </dependency>

 

 </dependencies>

Add the annotation @EnableTurbine to its entry class ServiceTurbineApplication to open the turbine. The @EnableTurbine annotation contains the @EnableDiscoveryClient annotation, which opens the registration service.

@SpringBootApplication

@EnableEurekaClient

@EnableDiscoveryClient

@RestController

@EnableHystrix

@EnableHystrixDashboard

@EnableCircuitBreaker

@EnableTurbine

public class ServiceTurbineApplication {

 

 /**

     * http://localhost:8764/turbine.stream

     */

 

 public static void main(String[] args) {

        SpringApplication.run( ServiceTurbineApplication.class, args );

    }

}

Configuration file application.yml:

spring:

  application.name: service-turbine

server:

  port: 8769

security.basic.enabled: false

turbine:

  aggregator:

    clusterConfig: default   # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问

  appConfig: service-hi,service-la  ### 配置Eureka中的serviceId列表,表明监控哪些服务

  clusterNameExpression: new String("default")

  # 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称

  # 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default

  # 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC

eureka:

  client:

    serviceUrl:

      defaultZone: http://localhost:8761/eureka/

The configuration file comments are clearly written.

Turbine Demo


​Open the server, service-hi, service-la, and service-turbine projects in turn
Open the browser and enter: http://localhost:8769/turbine.stream,

Request in turn:

http://localhost:8762/hi?name=wh

http://localhost:8763/hi?name=wh

​Open
: http://localhost:8763/hystrix, enter the monitoring stream http://localhost:8769/turbine.stream

You can see that this page aggregates the hystrix dashbord data of 2 services.

Guess you like

Origin blog.csdn.net/2301_77700816/article/details/131914367