Circuit breaker monitors the use of Hystrix Dashboard

一、Hystrix Dashboard

effect:
  • Real-time monitoring of various indicator values ​​of each Hystrix commandKey
  • Dynamically modify various configurations through real-time monitoring of Dashboards
dash board:

Alt

2. Start Hystrix Dashboard

1、下载 standalone-hystrix-dashboard-1.5.3-all.jar

2. Start Hystrix Dashboard

java -jar -DserverPort=7979 -DbindAddress=localhost standalone-hystrix-dashboard-1.5.3-all.jar

Note: the serverPort and bindAddress are optional parameters, if not added, the default is 7979 and localhost

3. Check whether the startup is successful

  • Enter http://localhost:7979/hystrix-dashboard/ in the browser and the bear page is correct.

Three, the code

1 、 pom.xml

        <!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-core</artifactId>
            <version>${
    
    hystrix-version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-javanica -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-javanica</artifactId>
            <version>${
    
    hystrix-version}</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-metrics-event-stream -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-metrics-event-stream</artifactId>
            <version>${
    
    hystrix-version}</version>
        </dependency>

Description:

  • hystrix-core: Hystrix core interface package.
  • hystrix-metrics-event-stream: As long as the client is still connected, hystrix-metrics-event-stream will continuously push the counting results to the client in the form of text/event-stream.

2、HystrixConfig.java

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixConfig {
    
    

    @Bean
    @HystrixProperty(name = "circuitBreaker.enabled", value = "true")
    public HystrixCommandAspect hystrixCommandAspect() {
    
    
        return new HystrixCommandAspect();
    }

    /**
     * Send stream message to Hystrix-dashboard
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
    
    
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/hystrix.stream");
        return registrationBean;
    }
}

3. Controller code

4. Test the
browser visit http://localhost:7979/hystrix-dashboard/ , enter the monitoring address of the spring-boot application in the console.
Alt
Note: After starting the service, enter http://localhost:8080/hystrix.stream , then click "Add Stream", and finally click "Monitor Stream".

Alt

Description:

  • hystrix2/test1-commandKey (The default is the method name, which can be specified by the attribute commandKey of @HystrixCommand. It must be specified when there are two methods with the same name )
  • HystrixController2-ThreadPoolKey (the default class name can be specified by the attribute threadPoolKey of @HystrixCommand)

Guess you like

Origin blog.csdn.net/fomeiherz/article/details/89315148
Recommended