11.Spring-Cloud-Hystrix the fuse monitoring Turbine

   On Bowen learned Hystrix Board to monitor a single application, in addition to monitoring points /trubine.stream a Turbine is provided to monitor the use of the cluster. In complex distributed systems, nodes with the same services often need to deploy hundreds or even thousands, many times, operation and maintenance personnel wants to bring the same service node status to show up in the form of a whole cluster, so you can better grasp the status of the entire system. For this purpose, Netflix provides an open source program (Turbine) to provide the content of a plurality of data aggregation hystrix.stream source Dashboard for display.

A: Build Turbine Project

1.pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>8.spring-cloud-turbine</groupId>
<artifactId>turbine</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-cloud Maven Webapp</name>
<url>http://maven.apache.org</url>
<!--springboot采用1.5.x 对应springcloud版本为 Dalston -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
</properties>
<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>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 这样变成可执行的jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>


2. Start class

package com.niugang;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
/**
 * 
 * Turbine监控
 * @author niugang
 *
 */
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine //启动turbine
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

 

 


3. Configuration

# Specify the name of service subsequent micro only need to use this name when calling the service can be accessed 
spring.application.name = hystrix-dashboard- Turbine 
server.port = 9004 
serviceId list # configuration in Eureka, which demonstrate that the monitoring service 
turbine.appConfig = RIBBON-CONSUMER1, Ribbon- CONSUMER2 
turbine.aggregator.clusterConfig = default 
turbine.clusterNameExpression = new new String ( "default" ) 
# turbine.combine -host-Port = to true 
# registry address 
eureka.client.serviceUrl.defaultZone HTTP =: // testhost: 8000 / Eureka /
  • turbine.appConfig: serviceId list configuration in Eureka, which demonstrate that the monitoring service
  • turbine.aggregator.clusterConfig: specify which clusters polymerization, using a plurality of "," split default is default. Can use http:? //.../Turbine.stream cluster = {visit one of clusterConfig}
  • turbine.clusterNameExpression: 1. clusterNameExpression specify the cluster name, the default expression appName;

In this case: turbine.aggregator.clusterConfig need to configure the application name you want to monitor;
2. When clusterNameExpression: When default, turbine.aggregator.clusterConfig can not write, because the default is the default;
3. When clusterNameExpression: metadata [ 'cluster'] when, suppose you want to monitor applications configured eureka.instance.metadata-map.cluster: ABC, you need to configure, while turbine.aggregator.clusterConfig: ABC

II: additional preparation

Prepare ribbon-consumer1, ribbon-consumer2 two services.

1.ribbon-consumer1

# Specify the name of service subsequent micro only need to use this name when calling the service can be accessed 
spring.application.name = Ribbon- consumer1 
server.port = 9002 
spring.cloud.loadbalancer.retry.enabled = to true 
# registry address 
eureka.client.serviceUrl.defaultZone = HTTP: // testhost: 8000 / Eureka /
 
HelloService.java
@CacheResult

@HystrixCommand(fallbackMethod = "queryUserBackMethod",commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000"),
@HystrixProperty(name = "requestCache.enabled", value = "true")
})
public String queryUser( String id) {
String body = restTemplate
.postForEntity("http://service-provide/queryUser/{1}", String.class, String.class,id)
.getBody();
return  body;
}

 

 

2.ribbon-consumer2

# Specify the name of service subsequent micro only need to use this name when calling the service can be accessed 
spring.application.name = Ribbon- consumer2 
server.port = 9003 
spring.cloud.loadbalancer.retry.enabled = to true 
# registry address 
eureka.client.serviceUrl.defaultZone = HTTP: // testhost: 8000 / Eureka /
HelloService2.java
@CacheResult
@HystrixCommand(fallbackMethod = "queryUserBackMethod",commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000"),
@HystrixProperty(name = "requestCache.enabled", value = "true")
})
public String queryUser2( String id) {
String body = restTemplate
.postForEntity("http://service-provide/queryUser/{1}", String.class, String.class,id)
.getBody();
return  body;
}

 

the whole frame:

 

The above configuration, start the registration center, the caller to start the service, start the service consumer, start Turbine, as follows:

访问 http://localhost:9004/turbine.stream

Refresh HTTP: // localhost: 9003 / queryUser / 5 , HTTP: // localhost: 9002 / queryUser / 5 ; let the monitor data information;

Access: HTTP: // localhost: 9004 / hystrix , red box enter the address, click on the Monitor Stream

 

 

                                                                             Micro-channel public number: 

                                               

                                                                             JAVA program ape growth path

                          Resource sharing, recording program ape growing little by little. Focus on Java, Spring, SpringBoot, SpringCloud, distributed, slightly services.

Guess you like

Origin www.cnblogs.com/niugang0920/p/12194882.html