【spring cloud 第七篇】turbine 聚合监控

简介

  • 在使用hystrix dashboard组件进行监控服务的熔断情况时,每个服务都有一个hystrix dashboard主页,服务很多时,监控很不方便
  • turbine用于聚合多个hystrix dashboard,将多个hystrix dashboard组件的数据放在一个页面进行显示,进行集中监控

集成turbine

  • 在前面六篇的基础上在新建一个服务,命名为eureka-monitor-client
    在这里插入图片描述

对应的文件说明

pom.xml

  • 添加 spring-cloud-starter-netflix-turbine、spring-cloud-starter-hystrix-dashboard、spring-cloud-starter-netflix-eureka-client三个依赖
<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>eureka-master</artifactId>
        <groupId>com.qgg</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eureka-monitor-client</artifactId>


    <dependencies>

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

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

    </dependencies>


</project>

application.yml配置文件

spring:
  application:
    name: service-turbine

server:
  port: 8768

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

turbine:
  instanceUrlSuffix: /hystrix.stream  # instanceUrlSuffix 访问前缀默认为/actuator/hystrix.stream
  aggregator:
    cluster-config: default     #  指定聚合哪些集群,多个使用","分割,默认为default
  app-config: eureka-ribbon-client-1,eureka-feign-client # 配置监控服务的列表,表明监控哪些服务多个使用","分割
#or
  cluster-name-expression: new String("default")  # 集群名称默认为服务名的集群,当服务数量非常多的时候,可以启动多个
  combine-host-port: true
#  turbine.combine-host-port参数设置为true,可以让同一主机上的服务通过主机名与端口号的组合来进行区分,默认情况下会以host来区分不同的服务,这会使得在本机调试的时候,本机上的不同服务聚合成一个服务来统计。

启动文件

@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine  // 要启用Turbine,我们只需使用@EnableTurbine对主类进行注释
public class MonitorClientApplication {

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

页面访问

  • 先启动服务端再启动客户端,客户端启动顺序没要求,访问http://localhost:8761 服务注册中心
    在这里插入图片描述

  • 访问 http://localhost:8768/turbine.stream?cluster=default,如果没有对应的输出,先访问对应的hystrix的接口,如 http://localhost:8767/myFeign/getPort/feign测试
    在这里插入图片描述

  • 仪表盘显示操作,访问 http://localhost:8768/hystrix,填写对应的链接和信息
    在这里插入图片描述
    在这里插入图片描述

遇到的问题

  • 之前访问 http://localhost:8768/turbine.stream?cluster=default一直没有信息输出,一直打印ping…,并且仪表盘显示loading…,百度了很多文章,也查看了官网的demo,有版本问题,有配置问题,各种问题都会导致以上两个问题的出现,最后在 https://www.jianshu.com/p/590bad4c8947 博主查看到 在yml配置文件中,添加
    在这里插入图片描述
    解决了困扰半天的问题
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值