Community discussions

MikroTik App
 
User avatar
BrianHiggins
Forum Veteran
Forum Veteran
Topic Author
Posts: 720
Joined: Mon Jan 16, 2006 6:07 am
Location: Norwalk, CT
Contact:

Get current TX / RX speed via script

Fri Jan 24, 2020 12:18 am

this is a really simplified script of what I'm trying to do, but the first two lines don't work, and I can't figure out how to do a get on this figure... I don't care if I need to use a few extra lines to pull the tx/rx speeds, I simply can't figure out how to get just the rx/tx values into variables. Is there another way besides /interface monitor-traffic? the only thing I can think of is /interface ethernet print stats from=ether1 but that doesn't give current bits per second rate info...

:set ULSP [/interface monitor-traffic ether1 once get rx-bits-per-second]
:set DLSP [/interface monitor-traffic ether1 once get Tx-bits-per-second]
:log info "Current DL speed is $ULSP"
:log info "Current UL speed is $DLSP"
 
User avatar
macsrwe
Forum Guru
Forum Guru
Posts: 1011
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Re: Get current TX / RX speed via script

Fri Jan 24, 2020 7:39 am

monitor-traffic isn't an object with items in it, it's more a script. Try entering the following:

:put ("foo" . [/interface/monitor-traffic 1-WAN] . "bar")

You will see there is no real item there, just an interactive action.

Unlike total number of bytes, rates are not stored as items inside an object, they are computed on the fly by apps/processes/jobs such as Winbox, the Dude, and monitor-traffic. I don't even think there's an SNMP OID for them.
 
User avatar
bpwl
Forum Guru
Forum Guru
Posts: 3124
Joined: Mon Apr 08, 2019 1:16 am

Re: Get current TX / RX speed via script

Fri Jan 24, 2020 2:47 pm

In DUDE, if there is no automatic label on the SNMP monitored link for the TP-link R480T...

RX: [bitrate(round(diff32(oid_raw("1.3.6.1.2.1.2.2.1.10.5", 0, 0, "192.168.x.y", "v1-public"))))]
TX: [bitrate(round(diff32(oid_raw("1.3.6.1.2.1.2.2.1.16.5", 0, 0, "192.168.x.y", "v1-public"))))]

With x.y the IP address

So indeed, you take the counters and calculate the difference over an interval.
Used SNMPwalk in DUDE to find the OID.

For a Mikrotik, DUDE sets it automatically (even for an ethernet interface) to:

[snmp_wireless_link_info()]Rx: [Interface.InBitRate][snmp_wireless_link_rx_rate()]
Tx: [Interface.OutBitRate][snmp_wireless_link_tx_rate()]
 
User avatar
BrianHiggins
Forum Veteran
Forum Veteran
Topic Author
Posts: 720
Joined: Mon Jan 16, 2006 6:07 am
Location: Norwalk, CT
Contact:

Re: Get current TX / RX speed via script

Fri Jan 24, 2020 5:18 pm

there is no DUDE installation here, and unless there's a way to pull the OID via the MT script that won't work. the actual goal here is to set a traffic monitor script to perform a web call when traffic throughput exceeds a certain threshold, and if possible include the current mbps ul/dl in the data passed via the fetch command.

I can pull the tx/rx data via the API and that works fine, but I need something that is an outbound push from the router at the time of occurrence, not a inbound pull that looks on a schedule
 
User avatar
bpwl
Forum Guru
Forum Guru
Posts: 3124
Joined: Mon Apr 08, 2019 1:16 am

Re: Get current TX / RX speed via script

Fri Jan 24, 2020 6:26 pm

Sorry only use DUDE existing stuff ... not my own scripts.

But still , this might be close:

"Code to check wireless transmit speed:

ros_command(":put ((([/interface monitor-traffic wlan1 once as-value]->\"tx-bits-per-second\")/1000)/100);") "

from: https://wiki.mikrotik.com/wiki/Manual:T ... ta_sources
You do not have the required permissions to view the files attached to this post.
 
creatin
Member Candidate
Member Candidate
Posts: 108
Joined: Sat Nov 23, 2019 2:59 am

Re: Get current TX / RX speed via script

Sun Jan 26, 2020 3:32 pm

This this:

:local tx ([/interface get [find name=ether1] tx-byte)

I'm using this for converting to GBs:
:local tx (([/interface get [find name=ether1] tx-byte])/1073741824);

same applies for rx-byte on ether1

or:
:local txp ([/interface ethernet get ether1 driver-tx-byte]);
:local rxp ([/interface ethernet get ether1 driver-rx-byte]);

Who is online

Users browsing this forum: No registered users and 11 guests