SpringBoot e-Commerce project mall (20K + STAR) address: github.com/macrozheng/…
Abstract
The Hystrix Dashboard is a Dashboard component in the Spring Cloud to view Hystrix instance execution. You can view both a single instance and a cluster instance. This article describes its usage in detail.
Introduction to the
Hystrix provides the Hystrix Dashboard to monitor the execution of HystrixCommand methods in real time. The Hystrix Dashboard can effectively reflect the performance of each Hystrix instance, helping us quickly identify problems in the system and take action accordingly.
Hystrix single instance monitoring
Let’s take a look at how it works by monitoring a single Hystrix instance using the Hystrix Dashboard.
Create a Hystrix-Dashboard module
Used to monitor the execution of hystrix instances.
- Add dependencies to pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Copy the code
- Configure in application.yml:
server:
port: 8501
spring:
application:
name: hystrix-dashboard
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
Copy the code
- Add @enablehystrixDashboard to the startup class to enable monitoring:
@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); }}Copy the code
Start related services
This time, we need to start the following services: Eureka-server, user-service, Hystrix-service, and Hystrix-Dashboard. After starting, the registry is displayed as follows.
Hystrix instance monitoring demo
- Visit Hystrix Dashboard: http://localhost:8501/hystrix
- After filling in the information, click the monitoring button. What we need to note here is that since we do not support HTTPS locally, we need to fill in HTTP as our address, otherwise monitoring information cannot be obtained.
- It is also worth noting that the monitored Hystrix-service requires that the hystrix.stream endpoints of the Actuator be enabled. The configuration information is as follows:
management:
endpoints:
web:
exposure:
include: 'hystrix.stream' Expose hystrix monitor endpoints
Copy the code
- Call several hystrix – service interface: http://localhost:8401/user/testCommand/1
- You can see that the commandKey and threadPoolKey properties that we added to @hystrixCommand are displayed on it, and 7 of the calls were successful.
Hystrix Dashboard chart interpretation
The diagram is interpreted as follows. It should be noted that the small ball represents the health status and flow of the instance. The more prominent the color is, the less healthy the instance is. The curve represents real-time traffic changes for Hystrix instances.
Hystrix cluster instance monitoring
Here, we use Turbine to aggregate the monitoring information of Hystrix-service service, and then our Hystrix-Dashboard service can obtain the aggregated monitoring information from Turbine and show it to us.
Create a turbine-service module
This command is used to aggregate monitoring information about hystrix-Service.
- Add dependencies to pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Copy the code
- For configuration in application.yml, Turbine configuration is mainly added:
server:
port: 8601
spring:
application:
name: turbine-service
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
turbine:
app-config: hystrix-service # Specify the name of the service whose information you want to collect
cluster-name-expression: new String('default') # Specify the cluster to which the service belongs
combine-host-port: true # Distinguish services by host name and port number
Copy the code
- Add @enableturbine to your startup class to EnableTurbine:
@EnableTurbine
@EnableDiscoveryClient
@SpringBootApplication
public class TurbineServiceApplication {
public static void main(String[] args) { SpringApplication.run(TurbineServiceApplication.class, args); }}Copy the code
Start related services
Use the application-replica1. Yml configuration to start a hystrix-service service. Start turbine-service.
Hystrix cluster monitoring demo
-
Visit Hystrix Dashboard: http://localhost:8501/hystrix
-
To add the cluster monitoring address, note that we need to add the monitoring endpoint address of turbine-service:
- Call several hystrix – service interface: http://localhost:8401/user/testCommand/1 and http://localhost:8402/user/testCommand/1
- You can see that our number of Hystrix instances has gone to two.
The module used
Springcloud - learning ├ ─ ─ eureka - server-- Eureka Registry├ ─ ─ the user - service-- a service that provides the User object CRUD interface├ ─ ─ hystrix - serviceHystrix service calls the test service├ ─ ─ turbine - serviceAggregate services that collect hystrix instance monitoring information└ ─ ─ hystrix - dashboard-- A dashboard that displays hystrix instance monitoring information
Copy the code
Project source code address
Github.com/macrozheng/…
The public,
Mall project full set of learning tutorials serialized, attention to the public number the first time access.