天天看点

Spring Cloud(Finchley.RELEASE版本)微服务学习实践:4.3Hystrix监控数据集群-Turbine

环境:

jdk1.8;spring boot2.0.3;spring cloud(Finchley.RELEASE版本);Maven3.3

摘要说明:

Spring Cloud Turbine:当Hystrix消费者多个时需要先将各个消费者的执行信息聚合在一起再展示到展示面板。

步骤:

1.创建turbine(Hystrix监控数据集群)子项目

通过

SPRING INITIALIZR

工具选择Cloud Circuit Breaker:Turbine模块构建turbine子项目引入依赖(pom.xnl):

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>pers.cc</groupId>
		<artifactId>springCloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>turbine</artifactId>
	<name>turbine</name>
	<description>turbine(Hystrix数据进行聚合展示)</description>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
	</dependencies>
</project>
           

2.配置turbine

使用@EnableTurbine和@EnableAutoConfiguration注解开启Turbine的监控数据集群配置:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableDiscoveryClient
@EnableAutoConfiguration
@EnableTurbine
public class TurbineApplication {
	public static void main(String[] args) {
		SpringApplication.run(TurbineApplication.class, args);
	}
}
           

配置application.properties:

#指定服务名和端口
spring.application.name=turbine
server.port=7001
#注册到注册中心
eureka.client.serviceUrl.defaultZone=http://localhost:1001/eureka/


#指定收集路径
turbine.instanceUrlSuffix=/hystrix.stream
#指定了需要收集监控信息的服务名,多个以“,”进行区分
turbine.app-config=hystrix-consumer
# 指定集群名称,若为default则为默认集群,多个集群则通过此配置区分
turbine.cluster-name-expression="default"
#此配置默认为false,则服务是以host进行区分,若设置为true则以host+port进行区分
turbine.combine-host-port=true
           

3.使用turbine

先后启用:

服务注册中心(eurekaServer):eureka-server(1001)

服务提供者(eurekaDiscovery):eureka-client(2001)

服务消费者(hystrix):hystrix-consumer(5001)

服务消费者(hystrix):hystrix-consumer(5002)

Hystrix监控面板(hystrixDashboard):hystrix-dashboard(6001)

监控数据集群(turbine):turbine(7001)

在浏览器输入http://localhost:6001/hystrix进入监控面板主页面,输入http://localhost:7001/turbine.stream进入默认集群面板页如下,可以看到test接口有多个host;

Spring Cloud(Finchley.RELEASE版本)微服务学习实践:4.3Hystrix监控数据集群-Turbine

4.源码地址

github地址:https://github.com/cc6688211/springCloud.git

继续阅读