Spring Cloud 入门——6.1 Turbine 集群数据监控

24 篇文章 0 订阅
22 篇文章 3 订阅

代码信息

本篇文章涉及代码版本

组件版本
Spring Boot2.0.8.RELEASE
Spring CloudFinchley.SR1

本篇文章涉及应用

应用说明
base-eureka服务发现
base-producer服务提供方
base-hystrix-cluster熔断器集群
base-hystrix-turbine熔断器集群数据监视

集群数据的监控

之前在Hystrix使用dashboard的时候说过对集群的监控只有等我们引入Turbine 组件之后才能使用,那么今天就尝试把Turbine 组件引入Hystrix

在之前我们需要把之前编写的base-hystrix进行修改,变更成多个服务集群的base-hystrix-cluster项目。修改后的配置文件

spring:
  profiles: hystrix1
  application:
    name: base-hystrix-cluster
server:
  port: 8405

eureka:
  client:
    service-url: 
      defaultZone: http://localhost:8000/eureka/
logging:
  file: ${spring.application.name}.log
  # 配置监控端点
management:
  endpoints:
    web:
      exposure:
        # 默认配置中只有"health","info",假如不进行hystrix.stream这个参数配置会出现无法连接情况
        include: ["health","info","hystrix.stream"]

---
    
spring:
  profiles: hystrix2
  application:
    name: base-hystrix-cluster
server:
  port: 8406

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8000/eureka/
logging:
  file: ${spring.application.name}.log
  # 配置监控端点
management:
  endpoints:
    web:
      exposure:
        # 默认配置中只有"health","info",假如不进行hystrix.stream这个参数配置会出现无法连接情况
        include: ["health","info","hystrix.stream"]
---

spring:
  profiles: hystrix3
  application:
    name: base-hystrix-cluster
server:
  port: 8407

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8000/eureka/
logging:
  file: ${spring.application.name}.log
  # 配置监控端点
management:
  endpoints:
    web:
      exposure:
        # 默认配置中只有"health","info",假如不进行hystrix.stream这个参数配置会出现无法连接情况
        include: ["health","info","hystrix.stream"]

引入Turbine组件

构建maven依赖

首先需要引入的依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
    </dependency>

参数配置application.yml

base-hystrix-turbine的配置需要指定监控的服务base-hystrix-cluster,以及给这个监控提供一个自定义的名称

spring:
  application:
    name: base-hystrix-turbine
server:
  port: 8410

eureka:
  client:
    service-url: 
      defaultZone: http://localhost:8000/eureka/
logging:
  file: ${spring.application.name}.log
turbine:
# 指定了需要收集监控信息的服务名
  app-config: base-hystrix-cluster
  # 此集群监控的名字
  cluster-name-expression: new String("default")
  # 让同一主机上的服务通过主机名与端口号的组合来进行区分
  combine-host-port: true

代码编写

启动类上需要配置@EnableTurbine注解这个时候一个简单的集群监控系统就完成了。

@EnableTurbine
@EnableEurekaClient
@SpringBootApplication
public class HystrixTurbineApplication {

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

测试

现在让我们测试一下目前这些个配置是否发挥了作用

启动数据监视器

因为这次的项目都没有开启@EnableHystrixDashboard所以我们还是用之前的base-hystrix-dashboard的项目。
我们访问base-hystrix-dashboard项目的/hystrix可以看到熟悉的页面。

在这里插入图片描述

这次我们监控的内容修改为base-hystrix-turbine项目的turbine.stream地址,然后可以进入下面的页面

在这里插入图片描述
然后我们依次访问base-hystrix-cluster项目的三个应用接口会发现无论访问那一个都会被系统监控到。

到目前为止看起来Turbine开始发挥作用了。

需要注意的是,dashboard监控的原理是因为hystrix接口实现使用了@HystrixCommand修饰,所以这个接口的调用情况会被Hystrix记录下来。所以你上面的接口假如并没有被这个注解修饰,使用dashboard就什么都看不到了


本篇文章并未贴出所有代码,涉及的源码下载地址:https://gitee.com/daifylearn/cloud-learn

ps.上述的所有项目都是可以成功运行的。但是在后期为了实现每个应用端口尽量不冲突会有些许调整,而后续某次作死调整结构和名称可能会导致部分项目无法运行o(╯□╰)o,如果发现请留言我进行修改。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大·风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值