[5] Hystrix Dashboard circuit break monitoring dashboard

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.

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

  1. Create a new module mvn project based on m-parentm-cloud-hystrix-dashboard-9000
  2. 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>
  1. Start class to add @EnableHystrixDashboardactivation dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrixDashboard //开启HystrixDashboard
public class HystrixDashboard9000 {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(HystrixDashboard9000.class, args);
    }
}
  1. 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@



  1. 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;
    }
  1. Start the project, visit http://localhost:8090/actuator/hystrix.stream
    Insert image description here
    Insert image description here
    postMan to call the consumer service
    Insert image description here
  2. Access test http://localhost:9000/hystrix
    Insert image description here
    8. postMan calls consumer service retry Insert image description here

Interpretation of Dashboard

Insert image description here

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.

Insert image description here

Prepare environment

  1. Create a new module mvn project based on m-parentm-cloud-hystrix-turbine-9001
  2. 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>
  1. Start class to add @EnableTurbineactivation dashboard
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine //开启 Turbine 
public class HystrixTurbine9001 {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(HystrixTurbine9001.class,args);
    }
}
  1. 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'" # 集群默认名称
  1. Access the Turbine project with a browser, http://localhost:9001/turbine.stream , and you can see the monitoring data (no data postMan retry)
    Insert image description here

  2. Viewing data through the dashboard page is more intuitive. Enter the address you just entered into the dashboard address bar.
    Insert image description here
    Insert image description here

  3. 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

  4. Restart the service
    Insert image description here
    and stop the above services in order. The restart sequence is 8090-8091-9000-9001.

  5. Access interfaceInsert image description here

  6. Monitoring page
    Insert image description here

Guess you like

Origin blog.csdn.net/u014535922/article/details/129951943