Hystrix Dashboard 学习

Hystrix Dashboard断路监控仪表盘

正常状态是UP,跳闸是⼀种状态CIRCUIT_OPEN,可以通过/health查看,前提是⼯程中需要引⼊SpringBoot的actuator(健康监控),它提供了很多监控所需的接⼝,可以对应⽤系统进⾏配置查看、相关功能统计等。

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

基于springboot的健康检查观察跳闸状态(⾃动投递微服务暴露健康检查细节)

# springboot中暴露健康检查等断点接⼝
management:
 endpoints:
 	web:
 		exposure:
 			include: "*"
 # 暴露健康接⼝的细节
 endpoint:
	 health:
 		show-details: always

hystrix正常⼯作状态
在这里插入图片描述
跳闸状态
在这里插入图片描述
活动窗⼝内⾃我修复
在这里插入图片描述

如果我们想看到Hystrix相关数据,⽐如有多少请求、多少成功、多少失败、多少降级等,那么引⼊SpringBoot健康监控之后,访问/actuator/hystrix.stream接⼝可以获取到监控的⽂字信息,但是不直观,所以Hystrix官⽅还提供了基于图形化的DashBoard(仪表板)监控平 台。Hystrix仪表板可以显示每个断路器(被@HystrixCommand注解的⽅法)的状态。
在这里插入图片描述
**加粗样式**
1)新建⼀个监控服务⼯程,导⼊依赖

<!--hystrix-->
<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--hystrix 仪表盘-->
<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-netflix-hystrixdashboard</artifactId>
</dependency>
<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-netflix-eurekaclient</artifactId>
</dependency>

2)启动类添加@EnableHystrixDashboard激活仪表盘

@SpringBootApplication
@EnableHystrixDashboard // 开启hystrix dashboard
public class HystrixDashboardApplication9000 {
 public static void main(String[] args) {
 SpringApplication.run(HystrixDashboardApplication.class, args);
  }
}
  1. application.yml
server:
 port: 9000
Spring:
 application:
 name: lagou-cloud-hystrix-dashboard
eureka:
 client:
 serviceUrl: # eureka server的路径
 defaultZone:
http://lagoucloudeurekaservera:8761/eureka/,http://lagoucloudeurekaserverb:8762/eureka/ #把 eureka 集群中的所有 url 都填写了进来,也可以只写⼀台,因为各个 eureka server 可以同步注册表
 instance:
 #使⽤ip注册,否则会使⽤主机名注册了(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
 prefer-ip-address: true
 #⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address,早期版本是ipAddress
 instance-id: ${spring.cloud.client.ipaddress}:${spring.application.name}:${server.port}:@project.version@

4)在被监测的微服务中注册监控servlet(⾃动投递微服务,监控数据就是来⾃于这
个微服务)

@Bean
 public ServletRegistrationBean getServlet(){
	 HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
	 ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
	 registrationBean.setLoadOnStartup(1);
	 registrationBean.addUrlMappings("/actuator/hystrix.stream");
	 registrationBean.setName("HystrixMetricsStreamServlet");
	 return registrationBean;
 }

被监控微服务发布之后,可以直接访问监控servlet,但是得到的数据并不直观,后期可以结合仪表盘更友好的展示
在这里插入图片描述
5)访问测试http://localhost:9000/hystrix
在这里插入图片描述

输⼊监控的微服务端点地址,展示监控的详细数据,⽐如监控服务消费者http://localhost:8090/actuator/hystrix.stream在这里插入图片描述

  • 百分⽐,10s内错误请求百分⽐
  • 实⼼圆:
    ⼤⼩:代表请求流量的⼤⼩,流量越⼤球越⼤
    颜⾊:代表请求处理的健康状态,从绿⾊到红⾊递减,绿⾊代表健康,红⾊就代表很不健康
  • 曲线波动图:
    记录了2分钟内该⽅法上流量的变化波动图,判断流量上升或者下降的趋势
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值