第十篇: 断路器聚合监控(Hystrix Turbine)

上一篇文章讲述了如何利用Hystrix Dashboard去监控断路器的Hystrix command。当我们有很多个服务的时候,这就需要聚合所以服务的Hystrix Dashboard的数据了。这就需要用到Spring Cloud的另一个组件了,即Hystrix Turbine。

一、Hystrix Turbine简介

看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务Hystrix Dashboard数据进行了整合。Hystrix Turbine的使用非常简单,只需要引入相应的依赖和加上注解和配置就可以了。

二、准备工作

本文使用的工程为上一篇文章 第九篇: 断路器监控(Hystrix Dashboard) 的工程,在此基础上进行改造。因为我们需要多个服务的Dashboard,准备的服务有 leopard-eureka,leopard-feign ,具体项目代码查看之前,在这里就不详细说明。

三、创建 leopard-turbine

创建 spring-boot工程,以下为依赖文件 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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.leopard</groupId>
	<artifactId>leopard-turbine</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	
	<parent>
		<groupId>com.leopard</groupId>
		<artifactId>leopard-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<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.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

</project>

在其入口类TurbineServiceApplication加上注解@EnableTurbine,开启turbine,@EnableTurbine注解包含了@EnableDiscoveryClient注解,即开启了注册服务。

如对 @EnableDiscoveryClient  @EnableEurekaClient 两个注解有疑问的,

可参考 spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient 

package com.leopard.turbine;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@EnableTurbine
@SpringBootApplication
public class TurbineServiceApplication {

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

}

application.yml

spring:
  application.name: leopard-turbine

server:
  port: 8281

#验证关闭
#security.basic.enabled: false

turbine:
  aggregator:
    clusterConfig: default   
  appConfig: leopard-service-feign,leopard-service-feign1
  clusterNameExpression: new String("default")

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

turbine.aggregator.clusterConfig:指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问

turbine.aggregator.appConfig:配置Eureka中的serviceId列表,表明监控哪些服务

turbine.aggregator.clusterNameExpression:

#1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称
#2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default
#3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC

四、Turbine演示

依次开启leopard-eureka(8761)、leopard-service-feign(8181)、leopard-service-feign1(8182) 、leopard-turbine(8281)工程。

leopard-service-feign1 可通过原先项目 leopard-service-feign 改配置后再次启动,等同于启动两个不同的服务,无需多创建。

打开浏览器输入:http://localhost:8281/turbine.stream

依次请求:

http://localhost:8181/test/getPort

http://localhost:8182/test/getPort

打开 http://localhost:8182/hystrix 

输入监控流:http://localhost:8769/turbine.stream , 2000 , leopard-look

点击monitor stream 进入页面:

 

文章转载:https://blog.csdn.net/forezp/article/details/70233227

参考文献:

https://springcloud.cc/spring-cloud-netflix.html

https://www.cnblogs.com/EddieBlog/p/8820370.html

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值