The simplest SpringCloud tutorial in history | Part 12: Circuit Breaker Monitoring (Hystrix Dashboard)

forward from:

http://blog.csdn.net/forezp/article/details/70217283 This article is from Fang Zhipeng's blog 

In my fourth article , Circuit Breakers , I described how to use circuit breakers and briefly introduced the Hystrix Dashboard components. This article introduces Hystrix Dashboard in more detail.

1. Introduction to Hystrix Dashboard

Take the microservice architecture as an example to ensure the availability of the program and prevent program errors from causing network congestion, and the circuit breaker model appears. The status of a circuit breaker reflects the availability and robustness of a program and is an important indicator. Hystrix Dashboard is a component of circuit breaker status, providing data monitoring and a friendly graphical interface.

2. Preparations

The engineering chestnuts in this article are derived from the chestnuts in the first article , and are transformed on its basis.

3. Start to transform service-hi

Introduce the corresponding dependencies in the pom project file:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>

 Among them, these three dependencies are necessary and indispensable.

In the ServiceHiApplication class at the entry point of the program, add the @EnableHystrix annotation to turn on the circuit breaker, this is necessary, and you need to declare the breakpoint HystrixCommand in the program; add the @EnableHystrixDashboard annotation to enable HystrixDashboard

@SpringBootApplication
@EnableEurekaClient
@RestController
@EnableHystrix
@EnableHystrixDashboard
public class ServiceHiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceHiApplication.class, args);
    }

    @Value("${server.port}")
    String port;
    @RequestMapping("/hi")
    @HystrixCommand(fallbackMethod = "hiError")
    public String home(@RequestParam String name) {
        return "hi "+name+",i am from port:" +port;
    }

    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}

 Run the program: Open eureka-server and service-hi in turn.

4. Graphic display of Hystrix Dashboard

Open http://localhost:8762/hystrix.stream , you can see some specific data:



 Open locahost:8762/hystrix and you can see the following interface:



 Enter in sequence in the interface: locahost:8762/hystrix.stream , 2000 , miya 

; click OK.

In another window type:  http://localhost:8762/hi?name=forezp

Refresh the hystrix.stream web page and you will see a nice graphical interface:



 Source code download: 

https://github.com/forezp/SpringCloudLearning/tree/master/chapter12

5. References

hystrix-dashboard

Excellent article recommendation:

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326965246&siteId=291194637