微服务spring cloud-使用Turbine聚合监控数据

使用Turbine聚合监控数据

使用/hystrix.stream端点监控单个微服务实例。然而,使用微服务架构的应用系统一般会
包含若干个微服务,每个微服务通常都会部署多个实例。如果每次只能查看单个实例的监控
数据,就必须在Hystrix Dashboard上切换想要监控的地址,这显然很不方便。如何解决该问题呢?

Turbine简介

Turbine是一个聚合Hystrix监控数据的工具,他可以将所有相关/hystrix.stream端点的数据聚合
到一个组合的道一个组合的/turbine.streeam中,从而让集群的监控更加方便。
在这里插入图片描述

使用Turbine监控多个微服务

1.为了让Turbine监控两个以上的微服务,现将项目microservice-consumer-movie-feign-

hystrix-fallback-stream的application.yml改成如下内容:

server:
    port: 8020                  #端口号
spring:
    application:
        name: movie-feign-hystrixstream     #服务名称
eureka:
    instance:
         prefer-ip-address: true
    client:
        serviceUrl:
            defaultZone: http://localhost:8761/eureka/

2.创建一个Maven项目,ArtifactId是

	   <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-turbine</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>

3.在启动类上添加@EnableTurbine

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

4.编写配置文件application.yml

server:
    port: 8031
spring:
    application:
        name: turbine
eureka:
    client:
        service-url:
            defaultZone: http://localhost:8761/eureka
    instance:
        prefer-ip-address: true
turbine:
    app-config: movie-hystrix,movie-feign-hystrixstream
    cluster-name-expression: new String('default')
    combine-host-port: true
    instanceUrlSuffix: /actuator/hystrix.stream

使用以上配置,Turbine会在Eureka Server中找到movie-hystrix、movie-feign-hystrixstream这两个微服务,并聚合两个微服务的监控数据。

5.测试

1.启动项目microservice-discovery-eureka。
2.启动项目microservice-provider-user。
3.启动项目microservice-consumer-movie-ribbon-hystrix。
4.启动项目microservice-consumer-movie-feign-hystrix-fallback-stream。
5.启动项目microservice-hystrix-turbine。
6.启动microservice-hystrix-dashboard。
7.访问http://localhost:8010/user1,让microservice-consumer-movie-ribbon-hystrix微服务产生监控数据
8.访问http://localhost:8020/user1,让microservice-consumer-movie-feign-hystrix-fallback-stream微服务产生监控数据
9.打开Hystrix Dashboarad首页http://localhost:8030/hystrix.stream,在URL一栏填入http://localhost:8031/turbine.stream,随意指定一个Title并点击Monitor Stream按钮。
在这里插入图片描述

本文大部分内容转载自周立的《Spring Cloud与Docker微服务架构实战》

猜你喜欢

转载自blog.csdn.net/weixin_43439494/article/details/83793694