根据流量限速的又一办法
感谢kuwin“ROS用流量监控动态控制限速点(新方法)”,yiguangqiang88“使用简单限速的动态改变限速值的脚本”小区网是接电信的,6M/512K 带宽,我把单机下行流量分为4个等级1536/1024/512/256,上行分5个等级128/96/80/64/32
/ system script
##当流量监视下行大于4M时的动作(单机下行1024K)
add name="4M" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1536000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1536000/32000 \] do={:set m \(\$m+1\)}
\n
\n:if \
\(\$m>0\) do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\) \
max-limit=1024000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视下行大于5M时的动作(单机下行512K)
add name="5M" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1536000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1536000/32000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1024000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1024000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n
\n:if \(\$m>0\) do={:for ip from 2 to 254do={/queue simple \
set \(SYZX . \$ip\)max-limit=512000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视下行大于6M时的动作(单机下行256K)
add name="6M" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1536000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1536000/32000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1024000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1024000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n
\n:foreach b in=\[/queue simple find max-limit=512000/128000 \
\] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n
\n:if \(\$m>0\) do={:for ip from 2 to 254\
do={/queue simple set \(SYZX . \$ip\)max-limit=256000 } }
\n" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视下行小于512K时的动作(单机恢复下行1536K)
add name="check" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1024000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1024000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1024000/32000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=512000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n
\n:foreach b in=\[/queue simple find max-limit=256000/128000 \
\] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n
\n
\n:if \(\$m>1\) do={:for ip from 2 to 254\
do={/queue simple set \(SYZX . \$ip\)max-limit=1536000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
[ 本帖最后由 htqt 于 2008-1-25 23:38 编辑 ] ##当流量监视上行大于360K时的动作(单机96K上行)
add name="360K" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/128000 \] do={:set m \(\$m+1\)}
\n
\n
\n:if \(\$m>0\) \
do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\)\
max-limit=/96000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视上行大于410K时的动作(单机80K上行)
add name="410K" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/128000 \] do={:set m \(\$m+1\)}
\n
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n
\n
\n:if \
\(\$m>0\) do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\) \
max-limit=/80000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视上行大于450K时的动作(单机64K上行)
add name="450K" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/128000 \] do={:set m \(\$m+1\)}
\n
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/80000 \] do={:set m \(\$m+1\)}
\n
\n:if \
\(\$m>0\) do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\) \
max-limit=/64000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视上行大于480K时的动作(单机32K上行)
add name="480K" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/128000 \] do={:set m \(\$m+1\)}
\n
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/80000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/64000 \] do={:set m \(\$m+1\)}
\n
\n
\n:if \
\(\$m>0\) do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\) \
max-limit=/32000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
##当流量监视上行小于50K时的动作(恢复单机128K上行)
add name="check2" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1536000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/80000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/64000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/32000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/32000 \] do={:set m \(\$m+1\)}
\n
\n
\n:if \
\(\$m>0\) do={:for ip from 2 to 254do={/queue simple set \(SYZX . \$ip\) \
max-limit=/128000 } }" policy=ftp,reboot,read,write,test,winbox,password 再做流量监视规则
/ tool traffic-monitor
add name="4M" interface=ether2 traffic=received trigger=above \
threshold=4000000 on-event=4M comment="" disabled=no
add name="5M" interface=ether2 traffic=received trigger=above \
threshold=5000000 on-event=5M comment="" disabled=no
add name="360K" interface=ether2 traffic=transmitted trigger=above \
threshold=360000 on-event=360K comment="" disabled=no
add name="410K" interface=ether2 traffic=transmitted trigger=above \
threshold=410000 on-event=410K comment="" disabled=no
add name="450K" interface=ether2 traffic=transmitted trigger=above \
threshold=450000 on-event=450K comment="" disabled=no
add name="dd" interface=ether2 traffic=received trigger=below threshold=500000 \
on-event=check comment="" disabled=no
add name="du" interface=ether2 traffic=received trigger=above \
threshold=5800000 on-event=6M comment="" disabled=no
add name="ud" interface=ether2 traffic=transmitted trigger=below \
threshold=50000 on-event=check2 comment="" disabled=no
add name="uu" interface=ether2 traffic=transmitted trigger=above \
threshold=490000 on-event=480K comment="" disabled=no
add name="6M" interface=ether2 traffic=received trigger=above \
threshold=5500000 on-event=6M comment="" disabled=no
add name="480K" interface=ether2 traffic=transmitted trigger=above \
threshold=480000 on-event=480K comment="" disabled=no 关于此脚本的说明
首先是看了kuwin“的文章,我尝试做了流量监视的脚本限速,但是发现当流量变化大时,几个脚本同时运行,得出来的单机限制不一致,不知道算不算BUG,另外每运行一次脚本,CPU都是100%的,好怕死机
然后就想能不能用脚本关闭已经运行过的的流量监视,比如说流量大于6M时,脚本就关闭前面4M,5M的监视,但是现在还没办法解决。
后来看了yiguangqiang88的文章,有个取值的代码,想到了判断规则是否需要更变的方法,因为同一个流量监视动作时,限速脚本不会重复运行,而且一旦多个脚本同时运行时如果得出来的单机限制不一致,脚本再次本激活时会自动修正,
如果规划的速度等级多点,脚本确实是复杂点,不过效果还是不错的 ,另外如果没有限速规则更改的动作,CPU的占用率也低许多,我的是C3 1。0G,在多个脚本被激活的情况下,没有限速规则更改的话,占用率大概是20~35
[ 本帖最后由 htqt 于 2008-1-25 23:53 编辑 ] 楼主的研究精神值得学习,我现在用的是固定限速。你的方法可以采用一下。 我用的是PCQ,但是上行一直不理想。上行好你限不了。 楼主有没有图最好的说服力就是贴上几个图让我们看看!感谢中。。。。 ##当流量监视下行小于512K时的动作(单机恢复下行1536K)
add name="check" source=":delay 3
\n
\n:set m 0
\n
\n:foreach b in=\[/queue \
simple find max-limit=1024000/128000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=1024000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=1024000/32000 \] do={:set m \(\$m+1\)}
\n
\n:foreach \
b in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=512000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=512000/64000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n
\n:foreach b in=\[/queue simple find max-limit=256000/128000 \
\] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue simple find \
max-limit=256000/96000 \] do={:set m \(\$m+1\)}
\n:foreach b in=\[/queue \
simple find max-limit=256000/80000 \] do={:set m \(\$m+1\)}
\n:foreach b \
in=\ do={:set m \
\(\$m+1\)}
\n:foreach b in=\ \
do={:set m \(\$m+1\)}
\n
\n
\n:if \(\$m>1\) do={:for ip from 2 to 254\
do={/queue simple set \(SYZX . \$ip\)max-limit=1536000 } }" \
policy=ftp,reboot,read,write,policy,test,winbox,password
这个脚本用不了。用了出错,楼主检查下,不能用 ## 看我的,PPPOE用户自动调速度 #####
#定义变量
:local RxCurRate 0
:local RxCurSet 0
:local TxCurSet 0
#下行即时流量
interface monitor ydwan once do={:set RxCurRate $received-bits-per-second}
#interface monitor ydwan once do={:set RxCurRate $sent-bits-per-second}
#下行当前设置
#:set TxCurSet pcq-rate]
:set RxCurSet pcq-rate]
#:set TxCurSet (($RxCurSet+0)/2)
#下行 加大限制带宽
:if($RxCurRate<27000000&&$RxCurSet<=8000000) do={
:set RxCurSet ($RxCurSet+100000)
:if($RxCurSet>8000000) do={:set RxCurSet 8000000}
:set TxCurSet (($RxCurSet+0)/2)
/queue simple set max-limit=(($TxCurSet/4) . "/" . ($RxCurSet/4)) priority=7 burst-limit=(($TxCurSet/4+100000) . "/" . ($RxCurSet/4+100000)) burst-threshold=(($TxCurSet/8) . "/" . ($RxCurSet/8)) burst-time=5s/10s
/queue simple set max-limit=($TxCurSet . "/" . $RxCurSet) priority=6 burst-limit=(($TxCurSet+500000) . "/" . ($RxCurSet+500000)) burst-threshold=(($TxCurSet/2) . "/" . ($RxCurSet/2)) burst-time=5s/10s
/queue type set "PCQ-Download" kind=pcq pcq-rate=$RxCurSet pcq-classifier=dst-address
#/queue type set "PCQ-Upload" kind=pcq pcq-rate=$TxCurSet pcq-classifier=src-address
}
#下行 减少限制带宽
:if($RxCurRate>27000000&&$RxCurSet>1000000) do={
:set RxCurSet ($RxCurSet+-100000)
:set TxCurSet (($RxCurSet+0)/2)
:if($RxCurSet<900000) do={:set RxCurSet 1000000}
/queue simple set max-limit=(($TxCurSet/4) . "/" . ($RxCurSet/4)) priority=7 burst-limit=(($TxCurSet/4+100000) . "/" . ($RxCurSet/4+100000)) burst-threshold=(($TxCurSet/8) . "/" . ($RxCurSet/8)) burst-time=5s/10s
/queue simple set max-limit=($TxCurSet . "/" . $RxCurSet) priority=6 burst-limit=(($TxCurSet+500000) . "/" . ($RxCurSet+500000)) burst-threshold=(($TxCurSet/2) . "/" . ($RxCurSet/2)) burst-time=5s/10s
/queue type set "PCQ-Download" kind=pcq pcq-rate=$RxCurSet pcq-classifier=dst-address
#/queue type set "PCQ-Upload" kind=pcq pcq-rate=$TxCurSet pcq-classifier=src-address
}
页:
[1]