The Hystrix dashboard can display the status of each circuit breaker (method annotated with @HystrixCommand), Hystrix related data, such as how many requests, how many successes, how many failures, how many degradations, etc.
Table of contents
Preface
The normal state is UP, and the trip state is CIRCUIT_OPEN, which can be viewed through /health. The premise is that SpringBoot's actuator (health monitoring) needs to be introduced into the project . Added to parent project
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Dashboard control dashboard preparation
Prepare environment
- Create a new module mvn project based on m-parent
m-cloud-hystrix-dashboard-9000
- Import dependencies
<dependencies>
<!--hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--hystrix 仪表盘-->
<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-eureka-client</artifactId>
</dependency>
</dependencies>
- Start class to add
@EnableHystrixDashboard
activation dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrixDashboard //开启HystrixDashboard
public class HystrixDashboard9000 {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboard9000.class, args);
}
}
- application.yml
server:
port: 9000
spring:
application:
name: m-cloud-hystrix-dashboard
#注册发现
eureka:
client:
service-url:
defaultZone: http://CloudEurekaServerA:8761/eureka,http://CloudEurekaServerB:8762/eureka
instance:
prefer-ip-address: true
instance-id: ${
spring.cloud.client.ip-address}:${
spring.application.name}:${
server.port}:@project.version@
- Register the monitoring servlet in the monitored microservice (such as: m-service-autodeliver)
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new
HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new
ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
- Start the project, visit http://localhost:8090/actuator/hystrix.stream
postMan to call the consumer service
- Access test http://localhost:9000/hystrix
8. postMan calls consumer service retry
Interpretation of Dashboard
Percentage , percentage of erroneous requests within 10 seconds.
Filled circle :
Size : represents the size of the request traffic. The greater the traffic, the larger the ball.
Color : represents the health status of request processing, decreasing from green to red. Green represents health. Red represents a very unhealthy
curve fluctuation graph :
it records the fluctuation graph of the traffic on this method within 2 minutes, and determines the upward or downward trend of the traffic.
Dashboard aggregation monitoring interpretation
Previously, we focused on Hystrix data query and analysis of a microservice instance. Under the microservice architecture, there are often multiple instances of a microservice (clustered), such as automatic
delivery
of microservice
instance 1 (hystrix) ip1 :port1/actuator/hystrix.stream
instance 2 (hystrix) ip2:port2/actuator/hystrix.stream
instance 3 (hystrix) ip3:port3/actuator/hystrix.stream
According to the existing method, we can combine it with the dashboard Each time you enter a monitoring data flow URL, go in and check
whether the manual operation can be replaced by an automatic function? Hystrix Turbine aggregation (aggregation of hystrix monitoring data on each instance) monitoring
Turbine (Turbine)
thinking: Under the microservice architecture, a microservice often deploys multiple instances. If you can only view the monitoring of a single instance at a time, you need to switch frequently
. It is very inconvenient. In such a scenario, we can use Hystrix Turbine for aggregate monitoring, which can aggregate the
monitoring data of related microservices for easy viewing.
Prepare environment
- Create a new module mvn project based on m-parent
m-cloud-hystrix-turbine-9001
- Import dependencies
<dependencies>
<!--hystrix turbine聚合监控-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
- Start class to add
@EnableTurbine
activation dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine //开启 Turbine
public class HystrixTurbine9001 {
public static void main(String[] args) {
SpringApplication.run(HystrixTurbine9001.class,args);
}
}
- application.yml
server:
port: 9001
spring:
application:
name: m-cloud-hystrix-turbine
#注册发现
eureka:
client:
service-url:
defaultZone: http://CloudEurekaServerA:8761/eureka,http://CloudEurekaServerB:8762/eureka
instance:
prefer-ip-address: true
instance-id: ${
spring.cloud.client.ip-address}:${
spring.application.name}:${
server.port}:@project.version@
#turbine配置
turbine:
# appCofing配置需要聚合的服务名称,⽐如这⾥聚合⾃动投递微服务的hystrix监控数据
# 如果要聚合多个微服务的监控数据,那么可以使⽤英⽂逗号拼接,⽐如 a,b,c
appConfig: m-service-autodeliver
clusterNameExpression: "'default'" # 集群默认名称
-
Access the Turbine project with a browser, http://localhost:9001/turbine.stream , and you can see the monitoring data (no data postMan retry)
-
Viewing data through the dashboard page is more intuitive. Enter the address you just entered into the dashboard address bar.
-
Copy m-service-autodeliver-8090 and modify it to m-service-autodeliver-8091, add it to the m-parent project, postMan accesses the interface of 8090 and 8091
-
Restart the service
and stop the above services in order. The restart sequence is 8090-8091-9000-9001. -
Access interface
-
Monitoring page