微服务熔断限流Hystrix之Dashboard
简介
Hystrix Dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard可以直观地看到各Hystrix Command的请求响应时间,请求成功率等数据。
快速上手
工程说明
| 工程名 | 端口 | 作用 |
|---|---|---|
| eureka-server | 8761 | 注册中心 |
| service-hi | 8762 | 服务提供者 |
| service-consumer | 8763 | 服务消费者 |
核心代码
eureka-server 工程
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:/${server.port}/eureka/
spring:
application:
name: eureka-server
启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run( EurekaServerApplication.class, args );
}
}
service-hi 工程
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
application.yml
server:
port: 8762
spring:
application:
name: service-hi
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
HelloController
@RestController
public class HelloController {
@GetMapping("/hi")
public String hi() {
return "hello ~";
}
@GetMapping("/hey")
public String hey() {
return "hey ~";
}
@GetMapping("/oh")
public String oh() {
return "ah ~";
}
@GetMapping("/ah")
public String ah() {
//模拟接口1/3的概率超时
Random rand = new Random();
int randomNum = rand.nextInt(3) + 1;
if (3 == randomNum) {
try {
Thread.sleep( 3000 );
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "来了老弟~";
}
}
启动类
@SpringBootApplication
@EnableEurekaClient
public class ServiceHiApplication {
public static void main(String[] args) {
SpringApplication.run( ServiceHiApplication.class, args );
}
}
service-consumer 工程
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<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>
application.yml
server:
port: 8763
tomcat:
uri-encoding: UTF-8
max-threads: 1000
max-connections: 20000
spring:
application:
name: service-consumer
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
management:
endpoints:
web:
exposure:
include: "*"
cors:
allowed-origins: "*"
allowed-methods: "*"
HelloService
@Service
public class HelloService {
@Autowired
private RestTemplate restTemplate;
/**
* 简单用法
*/
@HystrixCommand
public String hiService() {
return restTemplate.getForObject("http://SERVICE-HI/hi" , String.class);
}
/**
* 定制超时
*/
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000") })
public String heyService() {
return restTemplate.getForObject("http://SERVICE-HI/hey" , String.class);
}
/**
* 定制降级方法
*/
@HystrixCommand(fallbackMethod = "getFallback")
public String ahService() {
return restTemplate.getForObject("http://SERVICE-HI/ah" , String.class);
}
/**
* 定制线程池隔离策略
*/
@HystrixCommand(fallbackMethod = "getFallback",
threadPoolKey = "studentServiceThreadPool",
threadPoolProperties = {
@HystrixProperty(name="coreSize", value="30"),
@HystrixProperty(name="maxQueueSize", value="50")
}
)
public String ohService() {
return restTemplate.getForObject("http://SERVICE-HI/oh" , String.class);
}
public String getFallback() {
return "Oh , sorry , error !";
}
}
HelloController
@RestController
public class HelloController {
@Autowired
private HelloService helloService;
@GetMapping("/hi")
public String hi() {
return helloService.hiService();
}
@GetMapping("/hey")
public String hey() {
return helloService.heyService();
}
@GetMapping("/oh")
public String oh() {
return helloService.ohService();
}
@GetMapping("/ah")
public String ah() {
return helloService.ahService();
}
}
启动类
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableHystrix
@EnableCircuitBreaker
public class ServiceConsumerApplication {
public static void main(String[] args) {
SpringApplication.run( ServiceConsumerApplication.class, args );
}
@LoadBalanced
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Hystrix Dashboard 的使用
JSON格式监控信息
先访问http://localhost:8762/hi
再打开http://localhost:8763/actuator/hystrix.stream,可以看到一些具体的数据:

Hystrix仪表盘监控信息
单纯的查看json数据,很难分析出结果,所以,要在Hystrix仪表盘中来查看这一段json,在hystrix仪表盘中输入监控地址进行监控:
打开仪表盘地址:http://localhost:8762/hystrix

在界面依次输入:http://localhost:8763/actuator/hystrix.stream 、2000 、service-consumer;点确定。

Hystrix仪表盘指标含义

测试
编一个测试脚本curl.sh
while true;
do
curl "http://localhost:8763/hi";
curl "http://localhost:8763/hey";
curl "http://localhost:8763/oh";
curl "http://localhost:8763/ah";
done
执行测试脚本,查看Hystrix仪表盘:

可以看出 ahService 因为模拟了1/3的概率超时,所以监控中呈现了30%左右的错误百分比。
源码
https://github.com/gf-huanchupk/SpringCloudLearning/tree/master/chapter17
欢迎扫码或微信搜索公众号《程序员果果》关注我,关注有惊喜~

微服务熔断限流Hystrix之Dashboard的更多相关文章
- 微服务熔断限流Hystrix之流聚合
简介 上一篇介绍了 Hystrix Dashboard 监控单体应用的例子,在生产环境中,监控的应用往往是一个集群,我们需要将每个实例的监控信息聚合起来分析,这就用到了 Turbine 工具.Turb ...
- 微服务容错限流Hystrix入门
为什么需要容错限流 复杂分布式系统通常有很多依赖,如果一个应用不能对来自依赖 故障进行隔离,那么应用本身就处在被拖垮的风险中.在一个高流量的网站中,某个单一后端一旦发生延迟,将会在数秒内导致 所有应用 ...
- 微服务组件--限流框架Spring Cloud Hystrix分析
Hystrix的介绍 [1]Hystrix是springCloud的组件之一,Hystrix 可以让我们在分布式系统中对服务间的调用进行控制加入一些调用延迟或者依赖故障的容错机制. [2]Hystri ...
- 聊聊微服务熔断降级Hystrix
在现在的微服务使用的过程中,经常会遇到依赖的服务不可用,那么如果依赖的服务不可用的话,会导致把自己的服务也会拖死,那么就产生了熔断,熔断顾名思义就是当服务处于不可用的时候采取半开关的状态,达到一定数量 ...
- 阿里熔断限流Sentinel研究
1. 阿里熔断限流Sentinel研究 1.1. 功能特点 丰富的应用场景:例如秒杀(即突发流量控制在系统容量可以承受的范围).消息削峰填谷.集群流量控制.实时熔断下游不可用应用等 完备的实时监控:S ...
- Spring-cloud微服务实战【七】:服务熔断与降级hystrix
在之前的文章中,我们先后介绍了eureka,ribbon,feign,使用eureka集群的方式来保证注册中心的高可用,在eureka中使用ribbon进行负载均衡,使用feign接口替换手动编码 ...
- springcloud3(六) 服务降级限流熔断组件Resilience4j
代码地址:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo/spb-gateway/src/test/java/com/ ...
- Envoy熔断限流实践(二)Rainbond基于RLS服务全局限流
Envoy 可以作为 Sevice Mesh 微服务框架中的代理实现方案,Rainbond 内置的微服务框架同样基于 Envoy 实现.本文所描述的全局限速实践也是基于 Envoy 已有的方案所实现. ...
- 微服务(二)hystrix
特性 1.延迟和失败容忍 防止级联错误,错误回退,优雅降级.快速失败和恢复 线程和信号量隔离 2.实时监控和配置更改 3.并发 并行执行,请求缓存,自动批处理失败请求 总运行流程 当你发出请求后,hy ...
随机推荐
- 【转载】COM文件与EXE文件的区别与联系
COM文件是一种可执行程序的内存映象文件,它与只有16位地址线的8位机上的CP/M操作系统下的可执行程序结构相似.在COM程序执行过程中,除了调用DOS功能和 ROM BIOS 功能,以及用户特意安排 ...
- Tcl学习之--列表|字典
[列表|字典] Tcl使用列表来处理各种集合,比方一个目录中的全部文件,以及一个组件的全部选项.最简单的列表就是包括由随意个空格.制表符.换行符.分隔的随意多个元素的字符串.比方: JerryAlic ...
- Python爬虫开发【第1篇】【动态HTML、Selenium、PhantomJS】
JavaScript JavaScript 是网络上最常用也是支持者最多的客户端脚本语言.它可以收集用户的跟踪数据,不需要重载页面直接提交表单,在页面嵌入多媒体文件,甚至运行网页游戏. 我们可以在网页 ...
- web 界面设计---js设置txt值
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312&quo ...
- 初识 flask
1,Python现阶段三大主流web框架Django, Tornado, Flask对比 Django主要特点是大而全,集成了很多组件,列如:Models Admin Form等等,不管用得用不着反正 ...
- java8--NIO(java疯狂讲义3复习笔记)
NIO采用内存映射文件的方式处理输入输出,NIO将文件或文件的一段区域映射到内存中,这样就可以像访问内存一样来访问文件了(这种方式模拟了操作系统上的虚拟内存的概念),通过这种方式来进行输入输出比传统的 ...
- CRM 配置 ADFS后,使用自定义STS遇到的问题总结
1 登录ADFS服务查看 ADFS日志 2 根据日志提示的错误,设置ADFS对应的属性 (Get-ADFSRelyingPartyTrust) | Set-ADFSRelyingPartyTrust ...
- YTU 1075: Time
1075: Time 时间限制: 1 Sec 内存限制: 128 MB 提交: 7 解决: 7 [提交][状态][讨论版] 题目描述 Digital clock use 4 digits to e ...
- ”吐槽“qemu的块设备驱动
花点时间来总结一下前阵子的工作. qemu的底层块设备无疑是我所见过的最复杂的模块了,说得好像我很精通很多模块一样(大雾). 它的raw镜像格式文件的驱动的核心代码主要都是在raw-posix.c文件 ...
- 浅谈Linux Kernel 中循环链表的实现
前阵子在弄缓存的时候,我们需要将qemu对于磁盘镜像文件写请求串成一个链表,最终将这个链表里面的写请求全部刷回到镜像文件里面,那么我们便需要一个强健,可靠的链表的接口,于是我们仿照Linux 2.4. ...