SpringCloud: Fuse monitoring Hystrix Dashboard and Turbine

SpringCloud: Fuse monitoring Hystrix Dashboard and Turbine

Hystrix-dashboard is a tool for real-time monitoring of Hystrix. Through Hystrix Dashboard, we can visually see the request response time, request success rate and other data of each Hystrix Command. But if you only use Hystrix Dashboard, you can only see the service information in a single application, which is obviously not enough. We need a tool that allows us to aggregate the data of multiple services in the system and display it on the Hystrix Dashboard. This tool is Turbo.

Hystrix Dashboard

We changed the circuit breaker example project spring-cloud-consumer-hystrix and renamed it to: spring-cloud-consumer-hystrix-dashboard.

1. Add dependencies

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

These three packages must be added

2. Startup

Startup class added to enable Hystrix Dashboard and fuse

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerApplication {

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


3. Test

After starting the project, visit http://localhost:9001/hystrix, You will see the following interface:

&amp;amp;amp;lt;img src="https://pic4.zhimg.com/v2-c68f1433500b5e84302cb332480e010f_b.jpg" data-rawwidth="911" data-rawheight="490" class="origin_image zh- lightbox-thumb" width="911" data-original="https://pic4.zhimg.com/v2-c68f1433500b5e84302cb332480e010f_r.jpg"&amp;amp;amp;gt;


There will be some hints in the picture:

Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream
Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
Single Hystrix App: http://hystrix-app:port/hystrix.stream

It probably means that if you view the default cluster using the first url, view the specified cluster using the second url, and use the last one for monitoring of a single application, we will only demonstrate a single application for the time being, so enter: http://localhost: 9001/hystrix.stream , Click monitor after input to enter the page.

If there is no request, Loading... will be displayed first, visit http://localhost:9001/hystrix.stream Will continue to display ping.

Request service http://localhost:9001/hello/neo, You can see the effect of monitoring, first visit http://localhost:9001/hystrix.stream, Displayed as follows:

ping: 
data: {"type":...}
data: {"type":...} 
 

Explain that the monitoring results have been returned

To the monitoring page, the following picture will be displayed:

&amp;amp;amp;lt;img src="https://pic4.zhimg.com/v2-e34321ac04020982ad7c4456a4c6c9ef_b.jpg" data-rawwidth="581" data-rawheight="387" class="origin_image zh- lightbox-thumb" width="581" data-original="https://pic4.zhimg.com/v2-e34321ac04020982ad7c4456a4c6c9ef_r.jpg"&amp;amp;amp;gt;It s actually

In fact, it is http://localhost:9001/hystrix.streamThe graphical display of the returned results. The Hystrix Dashboard Wiki explains the meaning of each indicator on the graph in detail, as shown in the figure below:

&amp;amp;amp;lt;img src="https://pic4.zhimg.com/v2-c2e13b9bac1bc1ea15a38552e0648383_b.png" data-rawwidth="640" data-rawheight="411" class="origin_image zh- lightbox-thumb" width="640" data-original="https://pic4.zhimg.com/v2-c2e13b9bac1bc1ea15a38552e0648383_r.png"&amp;amp;amp;gt;The fuse monitoring of this single application has been completed.

So far, the fuse monitoring of a single application has been completed.

Turbine

In a complex distributed system, hundreds or even thousands of nodes with the same service often need to be deployed. In many cases, the operation and maintenance personnel hope to display the status of the nodes with the same service in the form of an overall cluster, so that it can be better Grasp the status of the entire system. To this end, Netflix provides an open source project (Turbine) to provide aggregation of multiple hystrix.stream content into a data source for Dashboard display.

1. Add dependencies

<dependencies>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-turbine</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-netflix-turbine</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-hystrix-dashboard</artifactId>
	</dependency>
</dependencies>
 

2. Configuration file

spring.application.name=hystrix-dashboard-turbine
server.port=8001
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
 
  • turbine.appConfig: Configure the serviceId list in Eureka, indicating which services to monitor
  • turbine.aggregator.clusterConfig: Specify which clusters to aggregate, multiple use "," segmentation, the default is default. You can use http://.../turbine.stream?cluster={One of the clusterConfig} access
  • turbine.clusterNameExpression: 1. clusterNameExpression specifies the name of the cluster, the default expression is appName; at this time: turbine.aggregator.clusterConfig needs to configure the name of the application that you want to monitor; 2. When clusterNameExpression: default, turbine.aggregator.clusterConfig does not need to be written. Because the default is default; 3. When clusterNameExpression: metadata['cluster'], assuming that the application you want to monitor is configured with eureka.instance.metadata-map.cluster: ABC, you need to configure it, and turbine.aggregator.clusterConfig: ABC

3. Startup

Add @EnableTurbine to the startup class to activate support for Turbine

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class DashboardApplication {

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

}
 

At this point Turbine (hystrix-dashboard-turbine) configuration is complete


4. Test

Based on the sample project spring-cloud-consumer-hystrix, it is modified as the caller of the two services spring-cloud-consumer-node1 and spring-cloud-consumer-node2

The changes to the spring-cloud-consumer-node1 project are as follows: Application.properties file content

spring.application.name=node01
server.port=9001
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
 

The changes to the spring-cloud-consumer-node2 project are as follows: Application.properties file content

spring.application.name=node02
server.port=9002
feign.hystrix.enabled=true

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
 

HelloRemote class modification:

@FeignClient(name= "spring-cloud-producer2", fallback = HelloRemoteHystrix.class)
public interface HelloRemote {

    @RequestMapping(value = "/hello")
    public String hello2(@RequestParam(value = "name") String name);

}
 

Corresponding HelloRemoteHystrix and ConsumerController classes follow to modify, see the code for details

After modification, start spring-cloud-eureka, spring-cloud-consumer-node1, spring-cloud-consumer-node1, hystrix-dashboard-turbine (Turbine) in turn

Open the eureka background and you can see that three services are registered:

&amp;amp;amp;lt;img src="https://pic3.zhimg.com/v2-da8ebbe011568fb37a369ed9f0bcb13a_b.jpg" data-rawwidth="1361" data-rawheight="638" class="origin_image zh- lightbox-thumb" width="1361" data-original="https://pic3.zhimg.com/v2-da8ebbe011568fb37a369ed9f0bcb13a_r.jpg"&amp;amp;amp;gt;

Visit http://localhost:8001/turbine.stream

return:

: ping
data: {"reportingHostsLast10Seconds":1,"name":"meta","type":"meta","timestamp":1494921985839}
 
 

And it will be constantly refreshed to obtain real-time monitoring data, indicating that it is similar to a single monitoring, and returns the information of the monitored item. For graphical monitoring and viewing, enter: http://localhost:8001/hystrix, Return to the cool bear interface, enter: http://localhost:8001/turbine.stream, And then click Monitor Stream, you can see two monitoring lists appear

&amp;amp;amp;lt;img src="https://pic4.zhimg.com/v2-ee78d0034b3ed38b98948dc5a90c6977_b.jpg" data-rawwidth="599" data-rawheight="382" class="origin_image zh- lightbox-thumb" width="599" data-original="https://pic4.zhimg.com/v2-ee78d0034b3ed38b98948dc5a90c6977_r.jpg"&amp;amp;amp;gt; Sample code

Author: pure smile
Source: springcloud (V): fuse monitoring Hystrix Dashboard and Turbine
The copyright belongs to the author, please indicate the source for reprinting