SpringCloud 服务调用监控 Hystrix Dashboard、Turbine


 

概述

actuator可以监控应用状态,但数据展示不直观,springboot admin、hystrix dashboard、turbine都集成了actuator,并提供了UI界面来展示应用状态。
 

springboot admin、hystrix dashboard、turbine都可以监控应用,但监控的维度不同

  • springboot admin:关注应用本身的状态,可以监控所有服务,可以看到cpu、内存、线程、硬盘、jvm的情况,可以看到应用输出的日志
  • hystrix dashboard:关注服务之间的调用情况,服务消费者 -> 服务提供者,监控的是服务消费者。以节点为单位进行监控,不能统计服务集群的信息
  • turbine:和hystrix dashboard基本一样,区别是turbine是以集群为单位进行监控,可以看到服务集群的整体信息

 

hystrix dashboard的使用

依赖

  • Spring Cloud Discovery -> Eureka Discovery Client
  • Spring Cloud Circuit Breaker -> Hystrix DashBoard [Maintenance]

也可以手动添加依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
        
<!-- 包含了spring-boot-start-web、spring-boot-starter-actuator -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

单独作为一个服务只需要添加这两个依赖即可,如果不注册到eureka server上,也可以不要eureka client,但更推荐都把服务注册到注册中心上,通过网关统一访问。
 

引导类
加@EnableEurekaClient、@EnableHystrixDashboard
 

yml

server:
  port: 7501

spring:
  application:
    name: hystrix-dashboard


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


#允许访问dashboard的web页面
hystrix:
  dashboard:
    #也可以指定具体的域名|ip
    proxy-stream-allow-list: "*"

 

运行

启动应用,访问 localhost:7501/hystrix (hystrix dashboard的ip:port)进入hystrix dashboard的页面。

输入要监控的服务消费者的流,eg. http://localhost:8781/actuator/hystrix.stream
在这里插入图片描述
 

turbine的使用

依赖

勾选Spring Cloud Circuit Breaker的2个依赖

  • Hystrix DashBoard [Maintenance]
  • Turbine [Maintenance]

也可以手动添加依赖

<!-- 已经包含了spring-boot-start-web、spring-boot-starter-actuator -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

<!-- 已经包含了eureka client -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>

只添加这2个依赖即可。

turbine监控的服务集群信息是对hystrix dashboard监控的服务节点信息的聚合、统计,是建立在hystrix dashboard之上的,使用的仍是hystrix dashboard的web页面。
 

引导类
加@EnableEurekaClient、@EnableHystrixDashboard、@EnableTurbine
 

yml

server:
  port: 7502

spring:
  application:
    name: turbine


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


#允许访问dashboard的web页面
hystrix:
  dashboard:
    #也可以指定具体的域名|ip
    proxy-stream-allow-list: "*"


turbine:
  #要监控的服务,有多个时逗号分隔
  app-config: user-server,order-server
  cluster-name-expression: new String("default")
  #以host+port区分服务节点。默认只以host来区分服务节点
  combine-host-port: true

 

运行

启动应用,访问 localhost:7502/hystrix (turbine的ip:port)进入turbine的页面。

输入turbine的流,eg. http://localhost:7501/turbine.stream,会显示yml中配置的所有服务集群的信息。

 

说明

  • hystrix dashboard是输入要监控的服务节点的流,http://localhost:7504(要监控的服务节点的host+port)/actuator/hystrix.stream
  • turbine是输入turbine自身的流,http://localhost:7502(turbine本身的host+port)/turbine.stream

可直接在浏览器地址栏输入流的url查看原始数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值