MikroTik Simple Queue SNMP Monitoring from Ubuntu Linux

This guide shows how to read MikroTik Simple Queue statistics over SNMP from an Ubuntu Linux server. We will install the required SNMP tools, load the official MikroTik MIB, identify Simple Queue indexes and read traffic, packet and drop counters.

At the end, a Bash script automatically correlates every Simple Queue name with its SNMP counters and prints the results in a readable format.

Install SNMP Tools on Ubuntu

Install the Net-SNMP client utilities and the package used to download additional MIB files:

sudo apt update
sudo apt install -y snmp snmp-mibs-downloader curl
download-mibs

The snmpwalk command is used to retrieve complete SNMP tables, while snmpget is useful when querying specific OIDs or queue indexes.

Download the MikroTik MIB

Download the official MikroTik MIB so that symbolic names such as mtxrQueueSimpleBytesIn can be used instead of numeric OIDs:

mkdir -p ~/mikrotik-mib
cd ~/mikrotik-mib
curl -fL --retry 3 --retry-delay 2 -o mikrotik.mib https://download.mikrotik.com/routeros/7.21.1/mikrotik.mib
sudo cp mikrotik.mib /usr/share/snmp/mibs/MIKROTIK-MIB
sudo chmod 644 /usr/share/snmp/mibs/MIKROTIK-MIB

The MIB file contains the MikroTik-specific SNMP object definitions and allows Net-SNMP to translate symbolic object names into the corresponding numerical OIDs.

Enable the MikroTik MIB

Configure Net-SNMP to load the MikroTik MIB:

root@pc-lab:/usr/share/snmp/mibs# cat /etc/snmp/snmp.conf
#mibs :
mibs +MIKROTIK-MIB

Remove the local SNMP cache after changing the MIB configuration:

rm -rf ~/.snmp

After this step, commands can use MikroTik object names directly instead of long numerical SNMP OIDs.

List MikroTik Simple Queues

The first useful query is mtxrQueueSimpleName. It returns all configured Simple Queues together with their SNMP indexes:

snmpwalk -v2c -c lab_snmp 192.168.12.1 mtxrQueueSimpleName
MIKROTIK-MIB::mtxrQueueSimpleName.1 = STRING: HOST1
MIKROTIK-MIB::mtxrQueueSimpleName.2 = STRING: HOST2

The number at the end of each OID is the queue index. In this example, index 1 belongs to HOST1 and index 2 belongs to HOST2.

This index is important because all traffic counters for the same queue use the same number.

Read Download and Upload Counters

Once the queue index is known, individual counters can be queried directly with snmpget:

snmpget -v2c -c lab_snmp 192.168.12.1 mtxrQueueSimpleBytesIn.1 mtxrQueueSimpleBytesOut.1
MIKROTIK-MIB::mtxrQueueSimpleBytesIn.1 = Counter64: 222195019
MIKROTIK-MIB::mtxrQueueSimpleBytesOut.1 = Counter64: 64384659

The counters are cumulative 64-bit values and increase while traffic passes through the Simple Queue.

Useful Simple Queue SNMP Counters

mtxrQueueSimpleBytesIn.X # DL bytes
mtxrQueueSimpleBytesOut.X # UL bytes
mtxrQueueSimplePacketsIn.X # DL packets
mtxrQueueSimplePacketsOut.X # UL packets
mtxrQueueSimpleDroppedIn.X # DL drops
mtxrQueueSimpleDroppedOut.X # UL drops

Replace X with the SNMP index of the Simple Queue.

Collect Download Counters for All Queues

Instead of querying queues individually, snmpwalk can retrieve the complete counter table in one operation:

root@pc-lab:/usr/share/snmp/mibs# snmpwalk -v2c -c lab_snmp 192.168.12.1 mtxrQueueSimpleBytesIn
MIKROTIK-MIB::mtxrQueueSimpleBytesIn.1 = Counter64: 222247547
MIKROTIK-MIB::mtxrQueueSimpleBytesIn.2 = Counter64: 576

Collect Upload Counters for All Queues

snmpwalk -v2c -c lab_snmp 192.168.12.1 mtxrQueueSimpleBytesOut
MIKROTIK-MIB::mtxrQueueSimpleBytesOut.1 = Counter64: 64437682
MIKROTIK-MIB::mtxrQueueSimpleBytesOut.2 = Counter64: 640

This bulk method is much more useful when monitoring many customers because an entire counter type can be collected with a single SNMP walk.

Correlate Queue Names with Counters

The SNMP index connects the queue name to all of its counters. For example:

mtxrQueueSimpleName.3 = "CUST_10422_192.168.12.8_30"
mtxrQueueSimpleBytesIn.3 = 812345678
mtxrQueueSimpleBytesOut.3 = 234567890

All objects ending in .3 belong to the same Simple Queue. This makes it possible to collect the tables independently and correlate them later by SNMP index.

Automatic Simple Queue SNMP Collection Script

The following Bash script collects all queue names and six important counters. It stores the values in associative arrays and correlates them using the SNMP queue index.

root@pc-lab:~# cat get_SNMP_data_mikrotik.sh
#!/bin/bash
ROUTER="192.168.12.1"
COMM="lab_snmp"
MIBS="-M /usr/share/snmp/mibs:/usr/share/snmp/mibs/ietf:/usr/share/snmp/mibs/iana -m MIKROTIK-MIB"

walk() {
snmpwalk -v2c -c "$COMM" $MIBS "$ROUTER" "$1" 2>/dev/null
}

# index -> name
declare -A NAME

# counters per index
declare -A BIN BOUT PIN POUT DIN DOUT

# 1) Names
while read -r line; do
idx=$(echo "$line" | sed -E 's/.*mtxrQueueSimpleName\.([0-9]+).*/\1/')
name=$(echo "$line" | sed -E 's/.*STRING: ?//')
NAME["$idx"]="$name"
done < <(walk mtxrQueueSimpleName)

# helper to fill associative arrays with raw values
fill_counter() {
local oid="$1"
local -n arr="$2" # nameref to associative array
while read -r line; do
# Example: MIKROTIK-MIB::mtxrQueueSimpleBytesIn.1 = Counter64: 222188971
idx=$(echo "$line" | sed -E "s/.*${oid}\.([0-9]+).*/\1/")
val=$(echo "$line" | sed -E 's/.*: //')
arr["$idx"]="$val"
done
}

# 2) Fill counters (raw)
fill_counter "mtxrQueueSimpleBytesIn" BIN < <(walk mtxrQueueSimpleBytesIn)
fill_counter "mtxrQueueSimpleBytesOut" BOUT < <(walk mtxrQueueSimpleBytesOut)
fill_counter "mtxrQueueSimplePacketsIn" PIN < <(walk mtxrQueueSimplePacketsIn)
fill_counter "mtxrQueueSimplePacketsOut" POUT < <(walk mtxrQueueSimplePacketsOut)
fill_counter "mtxrQueueSimpleDroppedIn" DIN < <(walk mtxrQueueSimpleDroppedIn)
fill_counter "mtxrQueueSimpleDroppedOut" DOUT < <(walk mtxrQueueSimpleDroppedOut)

# 3) Print one line per customer (sorted by index)
for idx in "${!NAME[@]}"; do
echo "${NAME[$idx]} DL_BW: ${BIN[$idx]:-0} bytes | UL_BW: ${BOUT[$idx]:-0} bytes | DL_pkts: ${PIN[$idx]:-0} | UL_pkts: ${POUT[$idx]:-0} | DL_drop: ${DIN[$idx]:-0} | UL_drop: ${DOUT[$idx]:-0}"
done | sort -V

The script performs seven SNMP walks: one for the Simple Queue names and one for each traffic counter. The SNMP index is then used as the common key between all returned tables.

Run the Script

Make the script executable:

chmod +x get_SNMP_data_mikrotik.sh

Run it:

root@pc-lab:~# ./get_SNMP_data_mikrotik.sh
HOST1 DL_BW: 222300477 bytes | UL_BW: 64487908 bytes | DL_pkts: 187132 | UL_pkts: 126175 | DL_drop: 0 | UL_drop: 0
HOST2 DL_BW: 5367 bytes | UL_BW: 4323 bytes | DL_pkts: 118 | UL_pkts: 105 | DL_drop: 0 | UL_drop: 0
root@pc-lab:~#

The result provides one line per MikroTik Simple Queue with cumulative download bytes, upload bytes, packet counters and dropped packets.

How the Counter Collection Works

The important part is the SNMP queue index. The Simple Queue name and all counters use the same index:

Queue Name -> mtxrQueueSimpleName.X
Download Bytes -> mtxrQueueSimpleBytesIn.X
Upload Bytes -> mtxrQueueSimpleBytesOut.X
Download Packets -> mtxrQueueSimplePacketsIn.X
Upload Packets -> mtxrQueueSimplePacketsOut.X
Download Drops -> mtxrQueueSimpleDroppedIn.X
Upload Drops -> mtxrQueueSimpleDroppedOut.X

This makes the MikroTik Simple Queue SNMP table suitable for automated monitoring systems, traffic accounting and historical graph generation.

Important SNMP Note

SNMPv2c uses a community string for authentication and does not encrypt the SNMP traffic. The read-only community should therefore be restricted on the MikroTik router so that SNMP requests are accepted only from the monitoring server or trusted management network.