nacos限流查询的脚本

9、 限流的sql

select date_sub(now(), interval 3 hour); -- 向前退3个小时

-- 大于指定时间的记录

select * from log l where l.log_method='redisIncr' and DATE_FORMAT(l.log_time, "%Y-%m-%d")>='2021-12-30' limit 1;

-- 查询指定天的限流记录

select * from log l where l.log_method='redisIncr' and DATE_FORMAT(l.log_time, "%Y-%m-%d")='2021-12-30' limit 1;

-- 查询大于指定的时间的记录

select * from log l where l.log_method='redisIncr' and l.log_time > date_sub(now(), interval 80 hour);

-- 限流次数场景排序

select o.prt_no '阈值',

SUM(o.log_data) date_sum,

o.prt,

o.log_msg,

o.log_time

from (select distinct l.log_time,l.prt_no,l.log_data,l.prt,l.log_msg from log l where l.log_method='redisIncr' and log_time > date_sub(now(), interval 72 hour)) o

group by o.prt

order by date_sum desc;

-- 查询某个场景限流次数排序

select o.prt_no,

o.log_data ,

o.prt,

o.log_msg

from (select distinct l.log_time,l.prt_no,l.log_data,l.prt,l.log_msg from log l where l.log_method='redisIncr' and DATE_FORMAT(l.log_time, "%Y-%m-%d")>='2021-12-30') o

where o.prt='bind'

group by o.prt

order by o.log_data desc;

{

    "2021-12-30 14:18:42":1,

    "2021-12-30 14:18:18":1,

    "2021-12-30 14:18:04":19,

    "2021-12-30 14:18:28":1,

    "2021-12-30 14:18:09":1,

    "2021-12-30 14:18:35":1,

    "2021-12-30 14:18:37":1,

    "2021-12-30 14:18:38":1,

    "2021-12-30 14:18:08":27,

    "2021-12-30 14:18:00":2,

    "2021-12-30 14:18:22":3,

    "2021-12-30 14:18:43":1,

    "2021-12-30 14:18:06":33,

    "2021-12-30 14:18:45":1,

    "2021-12-30 14:18:10":3,

    "2021-12-30 14:18:52":1,

    "2021-12-30 14:18:02":4,

    "2021-12-30 14:18:24":1,

    "2021-12-30 14:18:07":7,

    "2021-12-30 14:18:25":1,

    "2021-12-30 14:18:59":1,

    "2021-12-30 14:18:01":4

}

Sentinel 是阿里巴巴开源的一个流量控制框架,它支持热点限流功能。要通过 Nacos 配置 Sentinel 的热点限流,首先需要在 Nacos 中管理 Sentinel 相关的服务发现配置。 1. **创建Nacos配置**: - 登录到 Nacos 控制台,进入 `配置` 或者 `Config Center` 页面。 - 创建一个新的数据源,用于存放 Sentinel 的配置文件,比如命名空间为 `sentinel-config`。 2. **配置热点规则**: - 编辑一个名为 `hot_rule.yaml` 或类似名称的配置文件,添加如下内容: ```yaml # 热点限流配置示例 rule: # 定义一个应用名,如your-app-name app: your-app-name # 规则组名,可以自定义 group: default # 开启热点规则 enabled: true # 热点阈值,例如每分钟访问次数超过50次,则触发限流 count: 50 # 时间窗口,例如1分钟内计数 window: 60s # 激活模式,可以是固定阈值(fixed)、滑动平均(movingAverage) mode: fixed # 如果激活模式是 movingAverage,还可以配置滑动平均周期,单位秒 smoothWindow: 60s # 具体策略,这里通常是 error 或者 slow strategy: error ``` - 将这个配置文件发布到 Nacos 数据源。 3. **在应用中引用配置**: - 在你的 Spring Boot 应用中,通过 Sentinel 提供的自动配置类(如 `SentinelProperties`)来获取 Nacos 中的热点限流配置。你可以在 `application.properties` 或者 `application.yml` 文件中设置 Sentinel 自动发现 Nacos 地址: ```properties sentinel.config-center=nacos://<your-nacos-server>:8848/sentinel-config ``` 完成以上步骤后,Sentinel 会从 Nacos 获取热点限流配置,并根据配置对指定的应用、组别和接口进行限流
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值