14. Ribbon Integrated Circuit Breaker Monitoring Hystrix Dashboard

Keywords: Java Spring Maven xml

Public number: java paradise

The last article just gave a brief introduction to Hystrix Dashboard monitoring, how to use Hystrix Dashboard to monitor the status of microservices? This article looks at how Ribbon integrates circuit breakers to monitor Hystrix Dashboard. Today's project mainly integrates sc-eureka-client-consumer-ribbon-hystrix project and sc-hystrix-dashboard project.

1. New project sc-ribbon-hystrix-dashboard, corresponding pom.xml file

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>spring-cloud</groupId>
  <artifactId>sc-ribbon-hystrix-dashboard</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <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-ribbon</artifactId> 
                <version>1.4.5.RELEASE</version> 
            </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-web</artifactId>
        </dependency>


        <!--         
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.5.RELEASE</version>
        </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-hystrix-dashboard</artifactId>
            <version>1.4.5.RELEASE</version>
        </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>

    </dependencies>
</project>

You can see that this pom.xml file is a combination of the pom.xml of the sc-eureka-client-ribbon-hstrix project and the sc-hystrix-dashboard project.

2. New spring boot startup class HystrixDashboard Application. Java

package sc.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
public class HystrixDashboardApplication {
    
    public static void main(String[] args) {
        
        SpringApplication.run(HystrixDashboardApplication.class, args);
        
    }

}

You can see that the annotation for this startup class is also a union of the startup classes of the sc-eureka-client-consumer-ribbon-hstrix project and the sc-hystrix-dashboard project.

3. The other java classes are not much to say. The project interface is as follows.

4. Start the configuration center and sc-eureka-server and sc-eureka-client-provider respectively

5. Start project sc-ribbon-hystrix-dashboard
Mode 1: http://127.0.0.1 5600/hystrix verifies that the startup is successful

Mode 2: Visit http://127.0.0.1:5600/hystrix.stream

This is the address for accessing the Dashboard ServletConfig. java servlet
In the last part, I talked about the general meaning of the following paragraph in English.

6. Demonstrate the circuit breaker monitoring Hystrix Dashboard in single application mode
Enter in url: http://127.0.0.1 5600/hystrix.stream (IP and port correspond to service consumer's IP and port)

Then click the Monitor Stream button

7. Use postman to access any interface, for example, to get a list of users( http://127.0.0.1 5600/cli/user/listUser, visit the corresponding monitoring interface several times

It is found that the graph of the monitoring interface changes dynamically, which is the monitoring of service invocation. The meanings of the relevant units in the figure can be seen as follows:
https://github.com/Netflix-Sk...

http://127.0.0.1 The interface corresponding to 5600/hystrix.stream also has a large amount of data, which is also the data monitored for service invocation.

Other interfaces are self-tested.

Posted by solarith on Sun, 01 Sep 2019 06:20:26 -0700