Editing script

How may I edit this script to monitor bandwidth on interface and if average of bandwidth will exceed 1Mbps for 60s, may activate queue simple rule, and deactivating queue rule if average of bandwidth will be under 950kbs for 60s


Scheduled check for loaded interfaces (auto adding queue to some IP or interface)
From MikroTik Wiki

If you have MikroTik as main router on your network (business and residential clients using the same downlink) and you wont to make QoS for business users.

Simple: If your downlink is about 2Mbps and you grants business client min 1Mbit. But on the same MikroTik you have connected residential users.
This script can check out-interface (for $sent-bits-per-second/$received-bits-per-second) and if sent/received bits > 1Mbps, script can add queue for some interface or IP address(es).

/system script
add name=“tl_down” source=“/interface monitor-traffic [/interface find name “interface”] once do {
:if ($received-bits-per-second > 1048576) do {
/queue simple add name=(username . “_” . [:pick [/system clock get date] 4 6] . “-” . [:pick [/system clock get date] 0 3]
. “-” . [:pick [/system clock get date] 7 11] . “-” . [:pick [/system clock get time] 0 9]) limit-at=262144/262144
max-limit=262144/262144 target-addresses=“ip address” priority=1
:log warning “Traffic limit added for ip address/network/interface”
}
}”
add name=“tl_remove_down” source=“/interface monitor-traffic [/interface find name “interface”] once do {
:if ($received-bits-per-second < 1048576) do {
/queue simple remove [/queue simple find target-addresses=“ip address”]
:log warning “Traffic limit removed for ip address/network/interface”
}
}”


/system scheduler
add name=“name-unloaded” on-event=tl_remove_down start-date=jan/01/2007 start-time=00:00:00 interval=9m comment=“” disabled=no
add name=“name-loaded” on-event=tl_down start-date=jan/01/2007 start-time=00:00:00 interval=10m comment=“” disabled=no



Thank you for helping me.

Anyone please help in this script…


please can anyone provide the example using this script.

Thanks..

This is the example script.

/system script


add name=“tl_down” source={
/interface monitor-traffic [find name=“To-Internet”] once do={
:if ($“rx-bits-per-second” > 1048576) do={
/queue simple add name=(“username” . “test” . [:pick [/system clock get date]
4 6] . “test1”
. [:pick [/system clock get date] 0 3] . “test2” . [:pick [/system clock get date] 7 11]
. “test3” . [:pick [/system clock get time] 0 9])
limit-at=262144/262144 max-limit=262144/262144
target-addresses=192.168.11.0/24 priority=1;

:log warning “Traffic limit added for ip address/network/interface”
}
}
}



add name=“tl_remove_down” source={
/interface monitor-traffic [find name=“To-Internet”] once do={
:if ($“rx-bits-per-second” > 1048576) do={
/queue simple remove [find target-addresses=192.168.11.0/24]
:log warning “Traffic limit removed for ip address/network/interface”
}
}
}