spring cloud 聚合监控(Turbine)

一、 简介

在使用Hystrix Dashboard组件监控服务的熔断情况时,每个服务都有一个Hystrix Dashboard主页,当服务数量很多时,监控非常不方便.为了同时监控多个服务的熔断器的状况,Netflix开源了Hystrix的另一个组件Turbine.Turbine用于聚合多个Hystrix Dashboard,将多个Hystrix Dashboard组件的数据放在一个页面上展示,进行集中监控. 

 

二、实例演示

1、创建一个新的服务(turbine-center)

2、添加pom.xml依赖

<!-- 继承spring-boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <!-- 继承spring-cloud -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- 添加turbine的依赖jar包 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-turbine</artifactId>
        </dependency>

        <!--断路器仪表盘依赖jar包-->
        <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>

        <!-- 客户端用来发送送请求到注册中心 依赖的jar包 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>


3、在application.yml配置

server:
  port: 8094

spring:
  application:
    name: turbine-center
eureka:
  client:
    service-url:
      defaultZone: http://10.0.1.65:8081/eureka/

turbine:
  aggregator:
    clusterConfig: default    # 指定聚合哪些集群,多个使用","分割,默认为default。
  appConfig: ribbon-center,feign-center   # 指定要监控的服务名
  clusterNameExpression: new String("default")

clusterConfig:指定聚合哪些集群,多个使用","分割,默认为default。

appConfig:指定要监控的服务名

clusterNameExpression:参数指定了集群名称为default,当服务数量非常多的时候,可以启动多个Turbine服务来构建不同的聚合集群,而该参数可以用来区分这些不同的聚合集群,同时该参数值可以再Hystrix仪表盘中用来定位不同的聚合集群,只需在Hystrix Stream的URL中通过cluster参数来指定;

 

4、创建一个启动类添加注解(@EnableTurbine)开启Turbine功能.

package cn;

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;

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

这里我启动了其他三个服务分别为:mail-center、feign-center、ribbon-center,并且对feign-center、ribbon-center做了熔断,开启了Hystrix Dashboard监控。

 

 这个时候给turbine-center服务也启动,然后访问:

http://localhost:8094/hystrix

 

输入:

http://localhost:8094/turbine.stream

参数解释:

这个时候就可以看到ribbon-center、feign-center这两个服务的方法都被监控了, 可见,生产者和消费者服务的熔断器状态都显示到了一个页面上,一个简单的turbine就配置成功了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值