1. An overview of the

To better monitor Hystrix performance, Spring Cloud provides the Hystrix Dashboard and Turbin for this purpose. The Hystrix Dashboard monitors Hystrix running status in real time. But the Hystrix dashboard can only monitor a single device. However, in actual systems, there is usually more than one service. To facilitate monitoring, we need to aggregate the data of multiple Hystrix dashboards into one dashboard and display it. The tool is Turbine. This article demonstrates the use of the Hystrix dashboard and Turbine

2. Hystrix dashboard

The Hystrix Dashboard monitors Hystrix running status in real time. But the Hystrix dashboard can only monitor a single device.

2.1. Related engineering

Relevant engineering description

  • Cloud-registration-center: indicates the registration center
  • Cloud-service-hystrix: Project as a service provider
  • Cloud-consumer-hystrix: The interface to invoke cloud-service-hystrix through hystrix

The project used in this section is the same as the Spring Cloud series 11@Feign integrated Hystrix for personalized configuration and integration principle. Cloud-registration-center and cloud-service-Hystrix are exactly the same. Please refer to the previous article

2.2. Configure Hystrix log monitoring

The following configurations are in project Cloud-consumer-Hystrix. In order to add support for Hystrix dashboard to the service, we modified cloud-consumer-Hystrix (this project is described in the Spring Cloud series 11 @Feign Hystrix personalization and integration principles). This excerpt), only the changes are listed here:

Add the Hystrix Dashboard dependency JAR to POM.xml

<! -- hystrix dashboard --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId> </dependency> <! Unable to connect to Command Metric Stream. > <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>Copy the code

Add the @enablecircuitbreaker annotation to the startup class. This annotation is required

@springBootApplication @enableFeignClients @enableeurekaclient // Configure this application to use service registration and service discovery @enablecircuitbreaker // Start a circuit breaker, If you want to monitor the flow of hystrix must open the annotation, even fegin already through property public class HystrixFeignCloudConsumerApplication {... .}Copy the code

Test startup service

  • Start project cloud-registration-Center:

    • The configuration center address is http://127.0.0.1:10761
  • Start the project cloud – service – hystrix HystrixCloudServiceApplication start classes
  • Start the project cloud – consumer – hystrix HystrixFeignCloudConsumerApplication start classes

Go to http://127.0.0.1:12082/hystrix.stream

The following information is constantly updated

ping: data: {" type ":" HystrixCommand ", "name" : "IMyHystrixClient# simpleHystrixClientCall (long)", "group" : "cloud - hystrix - service"... .Copy the code

If there is no more than print information, please perform monitoring URL, such as in this case, http://127.0.0.1:12082//hystrix-feign/simple

2.3. Enable the Hystrix-Dashboard monitoring function

The log information is not intuitive. You can use hystrix-Dashboard to display monitoring graphs. @enableHystrixDashboard Add @enableHystrixDashboard to the startup class to enable the HystrixDashboard function

@springBootApplication @enableFeignClients @enableeurekaclient // Configure this application to use service registration and service discovery @enablecircuitbreaker // Start a circuit breaker, This annotation must be enabled to monitor hystrix streams, even though Fegin has enabled Dashboard via the @enableHystrixDashboard // to monitor graphically: See http://127.0.0.1:12082/hystrix.stream public class HystrixFeignCloudConsumerApplication {... }Copy the code

test

Enter:http://127.0.0.1:12082//hystrix, the following screen is displayed

Type http://127.0.0.1:12082/hystrix.stream in the first space, click on the “Monitor Stream”, Into the monitoring interface Current you constantly refresh http://127.0.0.1:12082//hystrix-feign/simple, the following interface will change accordingly

Note: If there is no data in this interface, please refresh this interface.

Refer to the official figure for the meanings of each field

3. Turbine

The Hystrix Dashboard enables Hystrix monitoring of a single service. However, in actual systems, there is usually more than one service. To facilitate monitoring, we need to aggregate the data of multiple Hystrix dashboards into one dashboard and display it. The tool is Turbine.

3.1. New project: Cloud-Dashboard-Hystrix

We set up a separate project as Turbine’s service

Pom.xml introduces the HystrixDashboard jar as well as the Turbin package

<! -- hystrix dashboard --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId> </dependency> <! Unable to connect to Command Metric Stream. > <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <! -- turbine --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-turbine</artifactId> </dependency>Copy the code

Property configuration – Bootstrap-dashboard.yml: Register yourself with the service center

# port server: port: 12086 Spring: Application: Cloud-dashboard-hystrix Eureka: client: serviceUrl: # Server register/obtain server zone defaultZone: Instance: http://127.0.0.1:10761/eureka/ -- - IP - address: trueCopy the code

Yml Configure turbine’s services and specify cloud-consumer-hystrix and aggregation clusters to monitor

Turbine: # configure the serviceId list in Eureka to indicate which services to monitor. Separate multiple services with '," to separate appConfig: cloud-consumer-hystrix Aggregator: # specify which cluster to aggregate, use ", "split, default. You can use http://... /turbine.stream? Cluster ={clusterConfig one} Access clusterConfig: default clusterNameExpression: New String("default")Copy the code

Start class HystrixDashboardCloudApplication @ EnableTurbine: start the Turbine

@springBootApplication @enableEurekaclient // Configure this application to use service registration and service discovery @enablehystrixDashboard @enableturbine // http://127.0.0.1:12086/hystrix public class HystrixDashboardCloudApplication {public static void main (String [] args) { args = new String[1]; args[0] = "--spring.profiles.active=dashboard"; SpringApplication.run(HystrixDashboardCloudApplication.class, args); }}Copy the code

3.2 test

Test a single service monitor

Enter the interface:http://127.0.0.1:12086/hystrix



This interface allows us to monitor either a single service or a cluster. To monitor the services of a single service, just type the Hystrix stream address of the service in the URL bar. For example, to monitor the services of the previous section, just typehttp://127.0.0.1:12082//hystrix.streamClick Monitor

To make it easier for turbin users, we need to start two Cloud-consumer-Hystrix

Modification project: Cloud – consumer – hystrix, plus on HystrixSimpleCloudConsumerApplication @ EnableEurekaClient and start, For more information, please refer to this article. Spring Cloud Series 10 Using @HystrixCommand Using Hystrix and @Enablecircuitbreaker

We then restart HystrixDashboardCloudApplication service Then we input to monitor http://127.0.0.1:12086/turbine.stream in http://127.0.0.1:12086/hystrix interface

Then keep refreshing:http://127.0.0.1:12082/hystrix-feign/simpleandhttp://127.0.0.1:12083/hystrix/simple

The hystrix information of the two services is displayed on the monitoring interface

Code 4.

Please use tag V0.9 instead of master as I can’t guarantee that the master code will always be the same