catalogue
1. Introduction
Although the Hystrix Dashboard is easy to use, it has one disadvantage: a Hystrix Dashboard can only collect the Hystrix stream of one microservice. In other words, for each micro service, we need to open a Hystrix Dashboard to monitor its health. As you can see, the Hystrix Dashboard can only enter one actor endpoint address.
Can you bear it? I can't stand it anyway.
If we can't stand it, we can use Turbine; The Turbine project of Netfilx provides to aggregate the hytrix stream data of multiple microservices into one stream and display it through a hytrix dashboard, so that the health status of multiple microservices can be monitored at the same time!
The general structure diagram of Turbine project is as follows:
Before there is no Turbine, each microservice needs to open a Hystrix Dashboard page to monitor the health of the current microservices. With Turbine, the information of multiple microservices is aggregated through Turbine and then displayed on a Hystrix Dashboard page.
2. Text
2.1 rapid construction
Service list:
I have set up six services here, including Eureka server as the registry, turbo server as the turbo service, hystrix dashboard server as the hystrix dashboard service (these services can also be started in one service if necessary), and user server, order server and message server are services protected by hystrix.
<modules> <module>eureka-server</module> <module>turbine-server</module> <module>hystrix-dashboard-server</module> <module>user-server</module> <module>order-server</module> <module>message-server</module> </modules>
Service dependency:
All dependencies and versions are listed below. Select the required dependencies in the specified service
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> </parent> <properties> <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version> </properties> <dependencies> <!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--actuator--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--eureka server--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!--eureka client--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!--hystrix--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <!--turbine--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency> <!--hystrix-dashboard--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Eureka server service setup:
application.yml configuration file
server: port: 4010 spring: application: name: eureka-server eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
Service startup class
@SpringBootApplication @EnableEurekaServer public class EurekaServerApp { public static void main(String[] args) { SpringApplication.run(EurekaServerApp.class, args); } }
User server, order server and message server services:
User server service application.yml configuration file (the other two are similar)
server: port: 22222 spring: application: name: user-server eureka: client: service-url: defaultZone: http://localhost:4010/eureka ## Open the hystrix.stream endpoint management: endpoints: web: exposure: include: 'hystrix.stream'
User server service startup class (the other two are similar)
@SpringBootApplication @EnableEurekaClient // Turn on Hystrix @EnableHystrix public class UserServerApp { public static void main(String[] args) { SpringApplication.run(UserServerApp.class, args); } }
User server writes the hystrix protected controller (the other two are similar)
@RestController @RequestMapping(value = "/user") public class UserController { @GetMapping @HystrixCommand(fallbackMethod = "fallback") public String userDemo() { return "user-98"; } // Two methods are written to demonstrate that the method names are different, hystrix dashboard creates different circuit s @GetMapping("/demo1") @HystrixCommand(fallbackMethod = "fallback") public String userDemo1() { return "user-98"; } private String fallback() { return "user-NaN"; } }
Turbine server service setup:
application.yml configuration file
server: port: 11111 spring: application: name: turbine-server eureka: client: service-url: defaultZone: http://localhost:4010/eureka turbine: ## List of service names in eureka app-config: order-server,user-server,message-server ## eureka cluster name, default cluster-name-expression: "'default'" ## Enable the host + port composite aggregation service. By default, turbine will aggregate the services under the unified host into one service for statistics combine-host-port: true
Start class, add @ EnableTurbine and start turbine
@SpringBootApplication// open turbine@EnableTurbinepublic class TurbineServerApp { public static void main(String[] args) { SpringApplication.run(TurbineServerApp.class, args); }}
Establishment of hystrix dashboard server service:
application.yml configuration file
server: port: 55555eureka: client: service-url: defaultZone: http://localhost:4010/eureka ## Do not register register-with-eureka: false
Start the class, add @ EnableHystrixDashboard, and start the HystrixDashboard
@SpringBootApplication@EnableHystrixDashboardpublic class HystrixDashboardServerApp { public static void main(String[] args) { SpringApplication.run(HystrixDashboardServerApp.class, args); }}
2.2 service startup
To start the service, first start the registration center Eureka server, then start the user server, order server and message server services, and finally start turbine server and hystrix dashboard server.
After startup, check whether the service on the Eureka server registry is registered normally
After that, access the hystrix endpoint of the hystrix dashboard server service and ensure that you see the following hystrix dashboard interface
http://localhost:55555/hystrix
Enter the turbine.stream endpoint provided by turbine server in the hystrix dashboard
http://localhost:11111/turbine.stream
At the time of initial entry, since each method protected by hystrix is not called, no data is reported, so it is necessary to call each interface to trigger data reporting.
After that, you can see the following interface, which indicates that the service is started successfully and the integration of the whole monitoring service is completed
2.3 precautions
The circuit data displayed in the hystrix dashboard will be created according to the method name. Therefore, no matter whether it is in the same service or not, as long as the methods protected by hystrix have the same method name, they will be aggregated and displayed together. Note here!
In addition, it should not be understood that a circuit corresponds to a thread pools
- The number of circuit s is the same as the number of method names
- thread pools a thread pool will be created for the class of each method protected by hystrix
👇🏻 Official account Let's go into the big factory together 👇🏻