Mikrotik Script: Alert on queue tree limit exceeded

Hi guys,

This is my first post here, I’m a Network Engineer who works a lot with Mikrotik devices and Server Administration and you can see more of my posts on my website. I found this blog some time ago and was invited to contribute with some of my own scripts that may help others!

Today i’ll show you a little script for RouterOS to check if queue tree exceed the limit you set.

For. Example I’ve got a queue tree that limits the amount of total traffic (Upload+Download) to 50Mbps.

I want to know whenever this queue exceed the limit, and I want the system to send me an email.

This is the script:

:global checkrate [/queue tree get total-traffic rate]
:local limit 50000000

:if ( $checkrate < $limit ) do={
:log info ("Queue not Exceeded")
:if ( $checkrate > $limit ) do={
:log info ("Queue Exceeded")
/tool e-mail send server=xxx.xxx.xxx.xxx from="[email protected]" to="[email protected]" subject=("Queue Limit Exceed") body=("Queue Limit Exceed, Limit is: " . $checkrate)

About razorblade

Internet and Networking Expert, work a lot with Virtualization on Debian server and Mikrotik Devices. Php software developer.

7 thoughts on “Mikrotik Script: Alert on queue tree limit exceeded

  1. hi mr razol,

    could you give me how script for this case:
    – ping host name then result auto send to email

  2. Hi razorblade, how can this script be configured to be sent automatically upon the queue tree limit being exceeded? Following the article verbatim, the script can only be run manually. Thank you in advance!

  3. Hi guys,
    @Isaac this script can be scheduled by Mikrotik Scheduler (System -> Scheduler) so you can check whenever you want.
    @ferdy i’ll get you the script asap!!

  4. hi
    i need you help with this script

    :local dumplist [/queue simple find]
    :foreach i in=$dumplist do={
    :local targ
    :set targ [/queue simple get $i target];
    :if ($targ = “”) do={
    /queue simple set $i max-limit=400k/512k

    i want to check if the target address is equal to then i limit its speed
    this script run with no errors but gives no result in fact
    thank you

  5. Hi Ibrahim,

    It’s because the IP addresses in the queue are recognised with a trailing subnet mask (IE: the actual address is

    Would this simplified version work?

    /queue simple set [find target=""] max-limit=400k/512k

    – Andrew

  6. thank you Omega-00
    it works fine after i follow your instructions 😀
    but i complete my work with that code

    :local dumplist [/queue simple find]
    :foreach i in=$dumplist do={
    :local targ
    :local traff
    :set traff [/queue simple get $i byte];
    :set targ [/queue simple get $i target];
    :if ($targ = “”) do={
    :if ($traff>300) do={
    /queue simple set $i max-limit=128k/128k

    but it give me this messege (Script Error: cannot compare if string is more than time interval

    what can i do???

    thanks again

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.