spring cloud hystrix Health Indicator健康指数监控和Metrics Stream

一.Health Indicator健康指数监控

当使用Hystrix时,项目可以通过“/actuator/health”服务查看相关项目的健康指数。

1.在pom文件中加:

     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

2.在配置文件中加:

#设置查看指标
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: "*"

3.启动服务:ms-eureka-center(8761)、ms-eureka-provider(9701)、ms-hystrix-consumer(8005)

4.访问:能正常访问,且通过“/health”访问hystrix的状态为up

5.将提供服务者停用ms-eureka-provider,多次连续http://localhost:8005/hystrix-consumer/1 访问此请求(F5多次刷新),来触发失败率达到阈值,再次访问:看到请求出发了hystrix机制,hystrix的状态为"CIRCUIT_OPEN”,即“电路开放”的意思。

 二.Metrics Stream指标流

1.pom文件:做metrics stream 指标测试,这3个依赖,缺一不可,一定要有,切记切记。

 <!-- hystrix 插件 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <!-- dashboard  -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>
        <!-- actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

3.启动服务:ms-eureka-center(8761)、ms-eureka-provider(9701)、ms-hystrix-consumer(8005)

4.访问:能正常访问

只要刷新一下:http://localhost:8005//hystrix-consumer/1 这个请求,http://localhost:8005/hystrix.stream 这个页面就不停变化

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值