Scheduled Check For Loaded Interfaces - MikroTik Script RouterOS
Scheduled Check For Loaded Interfaces (auto adding queue to some IP or interface)
If you have MikroTik as main router on your network (business and residential clients using the same downlink) and you want to create QoS for business users.
Simple: If your downlink is about 2Mbps and you want to grant the business clients 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
Credit: wiki.mikrotik.com