SpringCloud Hystrix的超时时间配置以及监控平台搭建

一、Hystrix接口调用超时时间配置

在application.yml 中设置 hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 来指定接口间调用的超时时间。当接口调用时超过该时间未响应则执行降级逻辑。

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 1000

二、Hystrix监控平台搭建

在使用HystrixCommand 或 HystrixObservableCommand 包裹的接口依赖被调用时,Hystrix会生成运行结果和运行指标,比如每秒请求数,成功数量等这些状态会暴露在actuator的、health的端点中。

  • 1,通过Actutor获取Hystrix监控数据

步骤一、pom中添加Hystrix与actuator依赖。

<!-- 服务监控 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

步骤二、启动类上添加@EnableCircuitBreaker 注解激活Hystrix

@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
public class OrderApplication {
    public static void main(String[] args) {

步骤三、在配置文件中配置需要记录的端点信息

#actuator配置暴露的端点 * 表示全部。 还有 info、health、beans等
management:
  endpoints:
    web:
      exposure:
        include: '*'

步骤四、访问启动的应用ip端口+actuator/hystrix.stream

  • 2,搭建Hystrix DashBoard 监控(本过程是在上一种监控方式的基础上搭建)

步骤一、添加依赖

<!-- 服务监控 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

步骤二、启动类添加@EnableHystrixDashboard 激活Hystrix仪表盘

@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
/**
 * 激活HystrixDashboard仪表盘
 */
@EnableHystrixDashboard
public class OrderApplication {
    public static void main(String[] args) {

步骤三、打开dashboard监控首页地址(http://ip:port/hystrix),输入需要监控的页面流地址

点击监控流按钮跳转到新的界面,当有请求发生时,通过监控界面可以看到不同服务的请求结果信息,以及请求的请求数。通过不同颜色可以看到不同的请求结果处理数量(数据都为当前实时的数量展示)

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值