Spring Cloud's Way to Advance|11: Circuit Breaker Monitoring (Hystrix Dashboard)

 

For reprinting, please indicate the author and source:

Author: Galactic Architect

Original Link: https://blog.csdn.net/liuminglei1987/article/details/104004613

Preface

stay The Way to Advance with Spring Cloud|6: Circuit Breaker (Hystrix) In this paper, service fuse demotion and circuit breaker components are introduced.However, these data are ultimately invisible and difficult to monitor.

Therefore, a component for circuit breaker monitoring is needed, that is, the HSRIX Dashboard circuit breaker monitoring component, which provides a friendly graphical interface for the data of each circuit breaker.

 

Dead work

multiplexing The Way to Advance with Spring Cloud|6: Circuit Breaker (Hystrix) All projects in this article: xmall-product, xmall-product-clients-ribbon, xmall-product-clients-feign.

 

ribbon mode circuit breaker monitoring


Modify the xmall-product-clients-ribbon project to add dependencies and configurations.

 

Dependent on Transformation

Add dependencies on spring-boot-starter-actuator, spring-cloud-starter-netflix-hystrix-dashboard.The modified pom file is as follows.

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
​
    <parent>
        <groupId>com.luas.cloud</groupId>
        <artifactId>java-boot-parent-2.1</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../../java-boot-parent-2.1</relativePath>
    </parent>
​
    <groupId>com.luas.xmall</groupId>
    <artifactId>xmall-product-clients-ribbon</artifactId>
    <version>0.0.1-SNAPSHOT</version>
​
    <name>xmall-product-clients-ribbon</name>
    <description>product service clients by ribbon</description>
​
    <properties>
        <java.version>1.8</java.version>
    </properties>
​
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
​
        <!-- nacos cloud -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
​
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</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-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
​
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
​
</project>

Note: Be sure to add a spring-boot-starter-actuator dependency or the / actuator/hystrix.stream endpoint will not be created.

 

Turn on breaker monitoring

The boot class adds the @EnableHystrixDashboard annotation to turn on the breaker monitoring component.

package com.luas.xmall.product.clients;
​
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
​
@EnableHystrix
@EnableHystrixDashboard
@SpringBootApplication
public class XmallProductClientsRibbonApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(XmallProductClientsRibbonApplication.class, args);
    }
​
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
​
}

 

Monitor

Start the project xmall-product and xmall-product-clients-ribbon with ports 8080 and 8082, respectively.

If configured correctly, the console prints/actuator/hystrix.stream endpoint registration success information.

Visit http://localhost:8082/actuator/hystrix.stream, and if configured correctly, a series of ping s will occur.

Visit http://localhost:8082/hystrix and enter the following parameters:

Click Monitor Stream to open the circuit breaker monitoring interface.

You can see that loading occurs for both monitors.Don't panic, it's because there's no data.

Access http://localhost:8082/sku/1122, normal commodity information appears.

At this point, looking at hystrix.stream, there is already data.

The hystrix monitoring interface has displayed graphically.

The console also displays the connection success information.

 

feign mode circuit breaker monitoring

 

Dependent on Transformation

Add dependencies on spring-boot-starter-actuator, spring-cloud-starter-netflix-hystrix-dashboard.The modified pom file is as follows.

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
​
    <parent>
        <groupId>com.luas.cloud</groupId>
        <artifactId>java-boot-parent-2.1</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../../java-boot-parent-2.1</relativePath>
    </parent>
​
    <groupId>com.luas.xmall</groupId>
    <artifactId>xmall-product-clients-feign</artifactId>
    <version>0.0.1-SNAPSHOT</version>
​
    <name>xmall-product-clients-feign</name>
    <description>product service clients by ribbon</description>
​
    <properties>
        <java.version>1.8</java.version>
    </properties>
​
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
​
        <!-- nacos cloud -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
​
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
​
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</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-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
​
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
​
</project>

Note: Be sure to add a spring-boot-starter-actuator dependency or the / actuator/hystrix.stream endpoint will not be created.

 

Turn on breaker monitoring

Startup class adds annotation @EnableCircuitBreaker, @EnableHystrixDashboard.

package com.luas.xmall.product.clients;
​
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
​
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableFeignClients("com.luas.xmall.product.clients.clients")
@SpringBootApplication
public class XmallProductClientsFeignApplication {
​
    public static void main(String[] args) {
        SpringApplication.run(XmallProductClientsFeignApplication.class, args);
    }
​
}

Note: Although feign integrates hystrix and can manually turn on the breaker by configuring it, the @EnableCircuitBreaker annotation is required to turn on the breaker-related monitoring function.

 

Monitor

Start project xmall-product, xmall-product-clients-feign with ports 8080 and 8083, respectively.

If configured correctly, the console prints/actuator/hystrix.stream endpoint registration success information.

Visit http://localhost:8083/actuator/hystrix.stream, and if configured correctly, a series of ping s will still occur.

Visit http://localhost:8083/hystrix, change the monitoring address to http://localhost:8083/actuator/hystrix.stream, click Monitor Stream to open a new breaker monitoring interface.

You can see whether both monitors are still loading or because there is no data.

Access http://localhost:8083/sku/1122, normal commodity information appears.Then, looking at hystrix.stream, there is already data.

At this point, the hystrix monitoring interface has displayed graphical interface normally.

The console also displays the connection success information.

At this point, the integration of circuit breaker monitoring components is completed.

 

Monitoring Indicators

The meaning of breaker monitoring indicators is shown in the following figure.

This figure is based on ribbon mode of circuit breaker monitoring, feign mode is the same, the only difference is the short circuit name format.The ribbon method is the method name directly, while the feign method has both the service name and the parameter type, which is more detailed.

 

Source code


github

https://github.com/liuminglei/SpringCloudLearning/tree/master/11/

gitee

https://gitee.com/xbd521/SpringCloudLearning/tree/master/11/

 

 

WeChat Search [Galaxy Architect] found more exciting content.

 

Twenty-one original articles have been published. Zan 1. Visits 1713
Private letter follow

Tags: Spring Maven Java Apache

Posted on Sat, 18 Jan 2020 21:54:52 -0500 by farel