Teach you how to build a SpringCloud project (12) Integrating Hystrix's graphical Dashboard for real-time monitoring

What are microservices? A series will be seen at a glance!

1. Teach you how to build a SpringCloud project (1) Detailed explanation with pictures and texts, fool-like operation

2. Teach you how to build a SpringCloud project (2) Producers and consumers

3. Teach you how to build a SpringCloud project (3) Integrate the Eureka service registration center

4. Teach you how to build the SpringCloud project (4) Eureka cluster version construction

5. Teach you how to build the SpringCloud project (5) Build the producer cluster version

6. Teach you how to build a SpringCloud project (6) Eureka realizes service discovery

7. Teach you how to build a SpringCloud project (7) Integrate the Consul service registration center

8. Teach you how to build a SpringCloud project (8) Integrated Ribbon load balancer

9. Teach you how to build a SpringCloud project (9) Integrate OpenFeign service interface calls

10. Teach you how to build a SpringCloud project (10) Integrate Hystrix service downgrade

11. Teach you to build a SpringCloud project (11) Integrating Hystrix's service fuse

12. Teach you how to build a SpringCloud project (12) Integrate Hystrix's graphical Dashboard real-time monitoring

13. Teach you how to build a SpringCloud project (13) Integrate a new generation of Gateway

14. Teach you how to build a SpringCloud project (14) Integrated Config Distributed Configuration Center

15. Teach you how to build a SpringCloud project (15) Integrated Bus message bus

16. Teach you how to build a SpringCloud project (16) Integrated Stream message driver

17. Teach you how to build a SpringCloud project (17) Integrating Sleuth distributed link tracking

Continue to update, welcome to like and follow!
In this article teaching you how to build a SpringCloud project (10) integrating Hystrix service downgrade, the three major functions of Hystrix are introduced. Among them, the two articles on service downgrade and service downgrade have been studied, and this article should be in real time. Monitoring, in addition to isolating dependent service calls, Hystrix also provides timely call monitoring (Hystrix Dashboard) Hystrix will continuously record the execution information of all requests initiated through Hystrix, and display them to users in the form of statistical reports and graphics, including How many requests are executed per second, how many successes, how many failures, etc. Netflix has implemented the monitoring of the above indicators through the hystrix-metrics-event-stream project. Spring Cloud also provides the integration of Hystrix Dashboard, which converts monitoring content into a visual interface.

Don't talk nonsense, let's go straight to the liver! Let's get through it together and become a boss together! come on!
insert image description here

Create a new module named cloud-consumer-hystrix-dashboar service, the first step is to modify the pom.xml file. Mainly to introduce the dependency of hystrix dashboard. As shown below:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>mcroservice</artifactId>
        <groupId>com.study.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
 
    <artifactId>cloud-consumer-hystrix-dashboar</artifactId>
 
    <dependencies>
        <!--hystrix dashboard-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>com.study.springcloud</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.study.springcloud</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
 
 
</project>

Create a new configuration yml file, as shown below:

server:
  port: 9003

Create a new main startup class, mainly adding the @EnableHystrixDashboard annotation, as shown below:

package com.buba.springcloud;
 
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
 
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardMain {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(HystrixDashboardMain.class,args);
    }
}

We start the service, visit http://localhost:9003/hystrix, and the following successful interface appears, indicating that the configuration is successful. As shown below:
insert image description here

There is no problem with the hystrix-dashboar service. This service will continue to monitor the producer 8001 microservice cloud-provider-hystrix-payment8001. Let's see what charts will appear. Then you need to modify the cloud-provider-hystrix-payment8001 service. Since it is a new version of hystrix, you need to specify the monitoring path on the main startup class PaymentHystrixMain8001, otherwise an error will be reported. As shown below:

package com.buba.springcloud;
 
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
 
import javax.swing.*;
 
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001 {
    
    
    public static void main(String[] args) {
    
    
 
        SpringApplication.run(PaymentHystrixMain8001.class, args);
    }
    /**
     * 此配置是为了服务监控而配置,与服务容错本身无观,springCloud 升级之后的坑
     * ServletRegistrationBean因为springboot的默认路径不是/hystrix.stream
     * 只要在自己的项目中配置上下面的servlet即可
     * @return
     */
    @Bean
    public ServletRegistrationBean getServlet(){
    
    
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}

Next, start the Eureka7001 service, and then start the producer service 8001 to ensure that the producer service 8001 is registered in Eureka, as shown in the figure below:
insert image description here

Then start the monitoring service 9003 to monitor the producer service 8001, and fill in the monitoring path, as shown in the figure below:

insert image description here

After the configuration is successful, the following interface appears:
insert image description here

Let's first understand the meaning of each display parameter, which we call 7 colors, 1 ball and 1 line. As shown below:
insert image description here

insert image description here

The solid circle on the left has two meanings. Its color change represents the health of the instance. Its health decreases from green<yellow<orange<red. In addition to the color change of the solid circle, its The size will also change according to the request flow of the instance. The larger the flow, the larger the solid circle. Therefore, through the display of the solid circle, you can quickly find faulty instances and high-stress instances in a large number of instances.

The curve on the left is used to record the relative change of the flow within 2 minutes, and the rising and falling trends of the flow can be observed through it.

We test the http://localhost:8001/payment/circuit/1 and http://localhost:8001/payment/circuit/-1 paths, because the passed parameter ids are different, one is a positive number and the other is a negative number, so one It will return a successful serial number, and a prompt that returns a runtime exception, as shown in the figure below:

insert image description here

insert image description here

Then let's click to access the http://localhost:8001/payment/circuit/1 path crazily, and take a look at the diagram of this method, as shown below:

insert image description here

Let's analyze the solid circle on the left. Its color is green, indicating that the current instance is very healthy without any failures. With our frantic click access requests, it gradually becomes larger, indicating that the current traffic is also increasing, and as the requests become fewer, the circle will gradually become smaller. The curve on the left is always rising as we request more, and it will show a downward trend when the request decreases. It can also be seen that 34 successful requests have been made, and the circuit breaker is currently closed (Circuit Closed).

Then let's visit the http://localhost:8001/payment/circuit/-1 path crazily, and look at the diagram of this method, as shown below:

insert image description here

Because we have been accessing errors, the color of the solid circle on the left has changed from green to red, indicating that the current instance is unhealthy, and as we frantically click on access requests, it gradually becomes larger, indicating that the current traffic is also get bigger. The curve on the left is always rising as we request more, and it will show a downward trend when the request decreases. With our crazy click access requests, the circuit breaker changed from Close to Open. There has been a service circuit breaker, and the number of circuit breakers has been increasing. However, the number of failures we visit in 10 seconds has been increasing, and the failure rate is 100%.

Next, let's go crazy and visit the path that returns the correct http://localhost:8001/payment/circuit/1, then visit the path http://localhost:8001/payment/circuit/-1 that returns the wrong information, and then visit The correct http://localhost:8001/payment/circuit/1 path, let's take a look again, as shown below:

insert image description here

We can see that the correct path has been accessed at the beginning, the color of the solid circle is green, the error rate and the number of fuses are both 0, and the circuit breaker is also in the closed state, but as we click on the wrong path to access, the solid circle The color has changed from green > yellow > orange > red, all the way to red, the failure rate is also increasing, and the number of fuses is also increasing. When the failure rate of our configuration reaches 60%, the circuit breaker changes from Closed to Open. , the current service is downgraded and blown. When we switch to the correct path, the wrong information is returned at the beginning, but as the number of times increases, the failure rate is also reduced, and the number of blown is also reduced. The current state of the circuit breaker is Half-open state, with the correct access, the state of the circuit breaker changes to the fully-open state.

At this point, the real-time monitoring of Hystrix's graphical Dashboard is over, so easy!

insert image description here

Next articleContinue to learn the new generation gateway GateWay! The article is continuously updated, welcome to pay attention!

Supongo que te gusta

Origin blog.csdn.net/weixin_39570655/article/details/131824429
Recomendado
Clasificación