集群监控之Spring Cloud Turbine快速入门

介绍

Spring Cloud Turbine是对集群中微服务信息的统一监控收集监控信息,我们在每个微服务中添加了对Hystrix熔断器功能的支持,可以通过/hystrix.stream对每个微服务的运行状况进行监控,如果在集群中去对每一个微服务去进行单个访问是行不通的,这时候turbine就发挥了它的优势,他可以将多个微服务的hystrix.stream聚合到一起使用turbine.stream进行聚合监控。

Spring Cloud Turbine快速入门

  1. 添加依赖项,spring-cloud-starter-turbine,使用HystrixDashboard对Hystrix熔断进行图形化监控。

    1
    2
    3
    4
    5
    6
    7
    8
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-turbine</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>
  2. 在Spring Boot的主类上添加@EnableTurbine注解开启Turbine功能。

    1
    2
    3
    4
    5
    6
    7
    8
    @SpringBootApplication
    @EnableTurbine
    @EnableHystrixDashboard
    public class SpringCloudHystrixTurbineApplication {
    public static void main(String[] args) {
    SpringApplication.run(SpringCloudHystrixTurbineApplication.class, args);
    }
    }
  3. 修改配置文件信息,修改如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    server:
    port: 8031
    spring:
    application:
    name: springhystrixturbine
    eureka:
    client:
    serviceUrl:
    defaultZone: http://admin:password@localhost:8761/eureka
    instance:
    prefer-ip-address: true
    turbine:
    aggregator:
    clusterConfig: default
    #turbine.app-config指定了要收集监控信息的服务名
    appConfig: spring-cloud-user,spring-cloud-service
    #turbine.cluster-name-expression 指定集群名称
    clusterNameExpression: "'default'"
    combine-host-port: true #使同一主机上的多个服务实例可以通过主机名和端口号的组合来进行区分

配置信息参数描述:

  • turbine.appConfig:制定要收集监控信息的服务名,意思就是代表这些服务的hystrix.stream由turbine来进行收集监控。
  • turbine.cluster-name-expression:指定集群的名称。
  • combine-host-port:默认是true,代表同一台主机上多个服务实例可通过主机名和端口号组合来进行区分,因为同一个服务器可能部署多台微服务实例。
  1. 集群监控,可以通过访问http://localhost:8031/hystrix 对单个服务进行监控
    turbine页面
    可以清晰的看到下面的需要进行turbine监控的url的写法http://localhost:8031/turbine.stream?cluster=default,其中cluster是我们在指定集群的名称。可以看到如下页面进行集群监控:
    turbine页面
    这说明我们集群监控配置成功。
文章目录
  1. 1. 介绍
  2. 2. Spring Cloud Turbine快速入门
|
载入天数...载入时分秒...