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.
MikroTik RouterOS script to monitor queue usage and log warnings when average rate exceeds a specified threshold.
# 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")
}
}
}
@kyob
Copy link
Author

kyob commented Jan 25, 2025

Zrzut ekranu z 2025-01-25 07-39-53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment