Skip to content

Instantly share code, notes, and snippets.

@kyob
Created January 23, 2025 08:08
Show Gist options
  • Save kyob/09d6c637d9831cf33728578cb1f58ece to your computer and use it in GitHub Desktop.
Save kyob/09d6c637d9831cf33728578cb1f58ece to your computer and use it in GitHub Desktop.

Revisions

  1. kyob created this gist Jan 23, 2025.
    21 changes: 21 additions & 0 deletions monitor-queue-avg-rate.rsc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # MikroTik RouterOS Script: Monitor Queue Average Rate
    # Author: Łukasz Kopiszka
    # Description: Monitors queue usage in /queue tree and logs warning if average rate exceeds a specified threshold.
    # Units converted to Mb/s for readability.
    # Usage: Add the script to RouterOS, and optionally schedule it for periodic execution.
    # Example:
    # /system scheduler add name=monitor-queue-avg-rate interval=1m on-event=monitor-queue-avg-rate
    :local threshold 60
    :foreach qId in=[/queue tree find] do={
    :local qName [/queue tree get $qId name]
    :local qMaxLimit [/queue tree get $qId max-limit]
    :local qAvgRate [/queue tree get $qId rate]
    :if ($qMaxLimit > 0) do={
    :local usagePercent (($qAvgRate * 100) / $qMaxLimit)
    :local avgRateMbps ($qAvgRate / 1000000)
    :local maxLimitMbps ($qMaxLimit / 1000000)
    :if ($usagePercent >= $threshold) do={
    :log warning ("Queue '" . $qName . "' usage " . $usagePercent . "%, avgRate: " . $avgRateMbps . " Mb/s, limit: " . $maxLimitMbps . " Mb/s")
    }
    }
    }