MQTT + Mikrotik

Arquitetura de Publicação/Assinatura do MQTT
Pacotes necessários: iot 

MQTT Server:

MQTT = 192.168.0.243

/iot mqtt brokers add address=192.168.0.243 name=MK

Script:

*Salve com o nome de rb_inf

################################ Conf ################################
# Nome de um broker MQTT existente.
:local broker "MK"

# Tópico MQTT onde a mensagem deve ser publicada.
:local topic "rb_inf"

################################ Systema ##############################
:put ("[*] Gathering system info...")

:local model [/system routerboard get value-name=model]
:local serialNumber [/system routerboard get value-name=serial-number]
:local rosVersion [/system package get value-name=version \
 	[/system package find where name ~ "^routeros"]]
:local cpuLoad [/system resource get cpu-load]
:local freeMemory [/system resource get free-memory]
:local usedMemory ([/system resource get total-memory] - $freeMemory)
#:local txbyte (([/interface get ether2]->"rx-byte")/?)
#/interface monitor-traffic LAN once do={:put $"rx-bits-per-second" /?}
:local txbyte [/interface ethernet get ether2 value-name=driver-tx-byte]
:local rxbyte [/interface ethernet get ether2 value-name=driver-rx-byte]
:local ip [/ip address get [/ip address find interface=ether2] address]
:local name [/system identity get name]
:local date [/system clock get date]
:local time [/system clock get time]

:local upTime [/system resource get uptime]
#################################### MQTT #####################################
:local message \

	"{\"Modelo\":\"$model\",\
	\"Serial\":\"$serialNumber\",\
	\"Versao\":\"$rosVersion\",\
	\"CPU\":\"$cpuLoad\",\
	\"fmem\":\"$freeMemory\",\
	\"umem\":\"$usedMemory\",\
	\"TX\":\"$txbyte\",\
	\"RX\":\"$rxbyte\",\
	\"Nome\":\"$name\",\
	\"Data\":\"$date\",\
	\"Hora\":\"$time\",\
	\"IP\":\"$ip\",\
	\"Uptime\":\"$upTime\"}"

# Log (terminal)
:log info "$message";
:put ("[*] Total message size: $[:len $message] bytes")
:put ("[*] Sending message to MQTT broker...")
/iot mqtt publish broker=$broker topic=$topic message=$message
:put ("[*] Done")

Programar o script para rodar de 1 em 1s.

/system scheduler
add comment="Envia os dados para o MQTT via script de 3 em 3s." interval=3s name=send_rb_inf on-event=\
    "/system script run rb_inf" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup

TX | RX

# Nome do broker MQTT.
:local broker "MK"
# Tópico MQTT onde a mensagem deve ser publicada.
:local topic "mk_tx_rx"
# Interface de rede. 
:local interface "ether2"

/interface monitor-traffic "$interface" once do={
	:local txb $("tx-bits-per-second");
	:local rxb $("rx-bits-per-second");
	:local Json \
	"{\"TX\":\"$txb\",\
	\"RX\":\"$rxb\"}"
	# Log
	:log info "$Json"
	# MQTT 
	/iot mqtt publish broker=$broker topic=$topic message=$Json
}

Se você deseja imprimir os dados de TX e RX em linhas separadas em vez de usar um formato JSON

# Nome do broker MQTT.
:local broker "MK"
# Interface de rede.
:local interface "ether2"

/interface monitor-traffic "$interface" once do={
	:local txb $("tx-bits-per-second");
	:local rxb $("rx-bits-per-second");
	
	# Log TX
	:log info "TX: $txb"
	# MQTT TX
	/iot mqtt publish broker=$broker topic=TX message="TX: $txb"
	
	# Log RX
	:log info "RX: $rxb"
	# MQTT RX
	/iot mqtt publish broker=$broker topic=RX message="RX: $rxb"
}

Dicas:

# Megabytes → Bytes
:if ($"rx-bits-per-second" > 5242880 ) do={:log info "Teste"}
/interface monitor-traffic ether2 once do={[/iot mqtt publish broker=MK topic=teste message=$"tx-bits-per-second"]}