Hystrix- Dashboard is a real-time monitoring tool for Hystrix. Through the Hystrix Dashboard, you can intuitively view the request response time and request success rate of each Hystrix Command. But with the Hystrix Dashboard, you can only see service information within a single app, which isn’t enough. We needed a tool to aggregate data from multiple services within the system and display it on the Hystrix Dashboard. That tool was Turbine.

Hystrix Dashboard

We changed from the fuse sample project spring-Cloud-Consumer-Hystrix and renamed it: 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>
Copy the code

These three packages must be added

2. Start classes

Startup class added to enable Hystrix Dashboard and fuses

@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients @EnableHystrixDashboard @EnableCircuitBreaker public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); }}Copy the code





3, test,

Start the project after the visit http://localhost:9001/hystrix, you will see the following interface:

&amp; 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; amp; gt;




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

Use the first URL to view the default cluster, use the second URL to view the specified cluster, and use the last url to monitor individual applications. We will only demonstrate individual applications for the moment, so enter: http://localhost:9001/hystrix.stream, click the monitor after input into the page.

Loading… is displayed if there is no request. Visit http://localhost:9001/hystrix.stream, also will continue to show the ping.

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

ping: data: {"type":... } data: {"type":... }Copy the code

The monitoring results are returned

The following picture will be displayed on the monitoring page:

&amp; 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; amp; gt; In fact, is


http://localhost:9001/hystrix.stream

&amp; 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; amp; gt; Fusing monitoring is complete for this single application.

Turbine

In a complex distributed system, hundreds or even thousands of nodes of the same service need to be deployed. In many cases, o&M personnel hope to display the status of nodes of the same service as a whole cluster to better understand the status of the whole system. To that end, Netflix provided an open source project (Turbine) to aggregate multiple Hystrix.streams into a single 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>
Copy the code

2. Configuration files

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/
Copy the code
  • Turbine. AppConfig: Configure the serviceId list in Eureka to indicate which services to monitor
  • Turbine. Aggregator. ClusterConfig: specify the polymerization which cluster, multiple use “, “split, the default for the default. You can use http://… /turbine.stream? Cluster ={clusterConfig one} access
  • Turbine. The clusterNameExpression: 1. ClusterNameExpression to specify the name of the cluster, the default expression appName; At this point: turbine. Aggregator. ClusterConfig need to be configured to monitor application name; 2. When clusterNameExpression: default, turbine. Aggregator. ClusterConfig can not write, because the default is the default; 3. When clusterNameExpression: metadata[‘ cluster ‘] is used, the application to be monitored is configured with Eureka.instance.metadata-map. cluster: ABC, you need to configure and turbine. The aggregator. ClusterConfig: ABC


3. Start classes

The start class added @enableTurbine to activate support for Turbine

@SpringBootApplication @EnableHystrixDashboard @EnableTurbine public class DashboardApplication { public static void main(String[] args) { SpringApplication.run(DashboardApplication.class, args); }}Copy the code

To complete the configuration of Turbine (Hystrix-Dashboard-Turbine)


4, test,

Based on the example project Spring-Cloud-consumer-Hystrix, change to spring-Cloud-consumer-node1 and Spring-Cloud-consumer-node2, the callers of the two services

The spring-cloud-consumer-node1 project is modified 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/
Copy the code

The spring-cloud-consumer-node2 project changes as follows: application.properties file contents

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

eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
Copy the code

HelloRemote class change:

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

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

}
Copy the code

The corresponding HelloRemoteHystrix and ConsumerController classes follow the modifications, looking at the code

After modification, start spring-Cloud-Eureka, spring-Cloud-consumer-node1, spring-Cloud-consumer-node1, and Hystrix-dashboard -turbine (turbine) in order.

If you open the eureka background, you can see that three services are registered:

Go to http://localhost:8001/turbine.stream

Returns:

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

In addition, the system continuously refreshes monitoring data to obtain real-time monitoring data. Similar to a single monitoring, the system returns monitoring item information. Monitored the graphical view, enter: http://localhost:8001/hystrix, to return to the interface of cool little bear, input: http://localhost:8001/turbine.stream, and then click the Monitor the Stream, you can see the two monitoring list


The sample code

The Hystrix Dashboard and Turbine are designed to monitor the flow of electricity