Spring Cloud Turbine使用

目录


  • 待补

Turbine简介


  • hystrix只能实现单个微服务的监控,可是一般项目中是微服务是以集群的形式搭建,一个一个的监控不现实。而Turbine的原理是,建立一个turbine服务,并注册到eureka中,并发现eureka上的hystrix服务。通过配置turbine会自动收集所需hystrix的监控信息,最后通过dashboard展现,以达到集群监控的效果。

Turbine实现


1.搭建一个springboot的项目
2.添加依赖

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

3.入口程序增加注解

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

4.填写配置文件信息

  • clusterNameExpression 指定集群名称,默认表达式appName; 此时 turbine.aggregator.clusterConfig 需要配置要监控的应用名称
  • clusterNameExpression: “‘default’” 时 clusterConfig: default 同时设置为default
  • clusterNameExpression: metadata[‘cluster’]时 应用配置 eureka.instance.metadata-map.cluster:ABC 则 clusterConfig 也配置成ABC
spring:
  application:
    name: turbine
server:
  port: 8061
turbine:
  aggregator:
    clusterConfig: default # 指定聚合哪些集群“,” 分割,默认为default。可用
  appConfig:microservice-consumer-hystrix,microservice-consumer-ribbon-hystrix
  # appConifg 配置Euraka中的serviceId列表,表明监控哪些服务
  clusterNameExpression: "'default'"

eureka:
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://user:1234@localhost:8761/eureka
  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}

5.查看监控信息

http://localhost:8061/turbine.stream 地址查看接口信息

6.结合hystrix Dashboard 查看信息

7.turbine只能监控hystrix服务,不是hystrix服务,不能监控。查看监控信息时,先访问以下hystrix服务

猜你喜欢

转载自blog.csdn.net/u014296316/article/details/80824364