on my Mikrotik I'm trying to write a script that pushs rx/tx bytes of my WAN interface via MQTT to my Node-Red installation that should forward it to Influx to get some Grafana diagrams in the end.
The following code has two issues:
1. The rx-bytes/tx-bytes should contain the values since the script ran the last time. So I'm trying to reset the counter at the end. But the values are not reset for some reason.
2. The variables totalTX and totalRX are each separated into 3 digit blocks. This avoids creating a valid json message. I need the digits without spaces. E.g. instead of 133 519 996 it needs to be 133519996.
Any help is welcome!
Code: Select all
# Required packages: iot
:local broker "node_red_system"
:local topic "mikrotik/wanVolume"
:local totalTX [/interface ethernet get ether1 tx-bytes]
:local totalRX [/interface ethernet get ether1 rx-bytes]
:local message \
"{ \"rx\":$"totalRX",\
\"tx\":$"totalTX"}"
:log info "$message"
/iot mqtt publish broker=$broker topic=$topic message=$message
/interface reset-counters ether1