什么是Sentinel?
A lightweight powerful flow control component enabling reliability and monitoring for microservices. (轻量级的流量控制、熔断降级 Java 库)
github官网地址:https://github.com/alibaba/Sentinel wiki:https://g
如何在工程中快速整合Sentinel
- 1.添加依赖包
<!--加入sentinel-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!--加入actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
添加Sentinel后,会暴露/actuator/sentinel端点http://localhost:8080/actuator/sentinel
而Springboot默认是没有暴露该端点的,所以我们需要自己设置
management:
endpoints:
web:
exposure:
include: '*'
访问 http://localhost:9999/actuator/sentinel
我们需要整合Sentinel-dashboard(哨兵流量卫兵)
下载地址:https://github.com/alibaba/Sentinel/releases
第一步:执行 java -jar sentinel-dashboard-1.7.0.jar 启动(就是一个Springboot工程)
第二步: 访问我们的sentinel控制台(1.6版本加入登陆页面) http://192.168.159.8:8080/
默认账号密码 sentinel/sentinel
第三步:我们的微服务tulingvip04-ms-alibaba-sentinel-order 也整合好了sentinel,我们也搭建 好了Sentinel控制台了,临门一脚 为微服务添加sentinel的控制台地址
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8080
sentinel监控性能指标详解
-
- 实时监控面板
在这个面板中我们监控我们接口的通过的QPS和拒绝的QPS 在没有设置流控规则 我们是看不到拒绝的QPS
- 实时监控面板
- 2.流控设置
簇点链路 选择具体的访问的API 然后点击流控按钮
含义:
资源名称:为我们接口的API /selectOrderInfoById/1
针对来源:这里是默认的default(标示不针对来源),还有一种情况就是
假设微服务A需要调用这个资源,微服务B也需要调用这个资源,那么我们就可以单独的为 微服务A和微服务B进行设置阈值。
阈值类型: 分为QPS和线程数 假设阈值为2
QPS类型:只得是每秒钟访问接口的次数>2就进行限流
线程数:为接受请求该资源 分配的线程数>2就进行限流.