Spring-cloud 微服务架构搭建 04 - Hystrix 监控配合turbine的配置使用

1. Hystrix仪表盘和Turbine集群监控简介

Hystrix仪表盘主要监控hystrix中的各项指标信息,以“桶”和“滚动时间窗的形式”,进行记录保存供外部调用。Hystrix仪表盘可以对单个服务进行监控,暴露hystrix.stream接口,Turbine整合所有服务进行监控。

2. hystrix-dashboard-turbine 模块快速搭建

注:本文项目采用idea工具进行搭建

  • 使用idea自身的spring initializr进行项目的初始化,项目名为:hystrix-dashboard-turbine。

  • 初始化完成项目之后进行pom文件导入

<!-- turbine 监控启动类 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<!-- hystrix-dashboard 仪表盘启动类 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- 注册eureka -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
  • 修改bootstrap.yml文件,添加如下配置:
management:
  endpoints:
    web:
      exposure:
        include: "*"  # 暴露所有服务监控端口,也可以只暴露 hystrix.stream端口
  endpoint:
    health:
      show-details: ALWAYS
#eureka.client.serviceUrl.defaultZone属性对应服务注册中心的配置内容,指定服务注册中心的位置。
eureka:
  client:
    registryFetchIntervalSeconds: 5
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    hostname: localhost
    preferIpAddress: true

turbine:
#  1.被监控的服务应用没有配置 context-path 的情况下
  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
#  app-config: SPRING-DEMO-SERVICE-FEIGN,SPRING-DEMO-SERVICE-RIBBON
#  aggregator:
#    cluster-config: default
#  # 指定集群名称
#  cluster-name-expression: "'default'"

#  2.被监控的服务应用配置了 context-path 的情况下,此时默认是集群里的应用都配置了 context-path
  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
#  app-config: SPRING-DEMO-SERVICE-FEIGN
#  aggregator:
#    cluster-config: default
#  # 指定集群名称
#  cluster-name-expression: "'default'"
#  instanceUrlSuffix: gateway/actuator/hystrix.stream

#  3.被监控的服务应用一部分配置了 context-path,一部分没有配置 context-path
  # 配置 Eureka 中的 serviceId 列表,指定要监控的服务
  app-config: feign-service,demo-service
  aggregator:
    cluster-config: default
  # 指定集群名称
  cluster-name-expression: "'default'"
  combine-host-port: true
  • 最后修改服务启动类:
@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardTurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
    }
}
  • 启动项目,访问http://localhost:8091/hystrix接口,弹出以下画面
    Hystrix监控画面

  • 在输入行中输入http://localhost:8091/turbine.stream 进入集群监控画面,如下:
    turbine集群监控画面

注意:我们在第一次进入时画面显示为loading…,只有在访问了接口之后才会出现上面的画面,监控台上的控制信息详细说明可以网上查找资料……^ _ ^

turbine可以继承amqp使用消息队列进行信息监控,只需要修改spring-cloud-starter-netflix-turbinespring-cloud-starter-netflix-turbine-amqp,然后进行rabbitmq的配置后就可以使用了,但是得确保消息队列的启动无误。

本文github代码地址:
spring-cloud 基础模块搭建 – 欢迎指正

猜你喜欢

转载自blog.csdn.net/allen_lu_hh/article/details/83150155