script to run manual bandwidth test and save to file

thank you for posting this! I already had a script that ran a BW test every 5 minutes, but i was then just using SNMP to “grab” the results (ie snmp traffic with short interval, and looking for the spike).

I can add this- for some of my mt scripts, one way to retrieve the value of a variable (or result from a script), if its a number (maybe integer only? not sure), is to have the script assign the value of the variableto a Simple Queue’s name. And then with snmp you can pull the value of the simple queues name (and thus you can graph that script variable). I use this for graphing the number of active VPN sessions on a mt vpn server i have (or in another case, for snmp graphing the current number of “NAT connections open/tracked”, via /ip fire connections print count) .
EDIT- i also have one of these setup to snmp graph the value of /ip neighbor count

below is script i wrote for that task. (i am going to modify your script to try to snmp graph the results of scheduled BW tests, i will post that if im successful in a few hours).

(i just have a single scheduler entry that runs every 5 minutes for this below):

code:
/queue simple set [find comment="SNMPget_vpnACTIVEconnections_Count_Holder"] name=[/ppp active print count-only]

or export:

/system scheduler
add interval=4m name=queueIPneighbor on-event=\
    "/queue simple set [find comment=\"SNMPget_vpnACTIVEconnections_Count_Holder\"] name=[/ppp active print count-only]" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup

you need to create a dumb simple queue to hold this value, you can set it to disabled=yes (then use /queue simple print OID to get its snmp oid to query)


EDIT 2- well that was quick and easy! Credit ofcourse to OP - vader7071 . i just deleted some lines and added a few, he did the heavy work!
You do need to create 2x disabled simple queues named:
bwTX
and
bwRX
(and then can use /queue simple print oid and grab the “name=” oid from each of the 2x queues, and plug that into your SNMP graphing tool, i use PRTG).
and ofcourse set the IP of your BW test server (IP , not dns). Im using his txcB / rxcB varables as the sites im using this on, are are many megabits in speed. so if you need kb or a lower measurement scale, you can modify the varables accordingly (or use the direct output from the bw-test run, ie the $txc but remove the “/1000” part)

{
:local txc
:local txcA
:local txcB
:local txcC

:local rxc
:local rxcA
:local rxcB
:local rxcC

:local rxta
:local rxtaA
:local rxtaB
:local rxtaC

:local txta
:local txtaA
:local txtaB
:local txtaC

/tool bandwidth-test x.x.x.x protocol=tcp direction=both duration=5s do={

:set txcA ($"tx-current" / 1000)
:set txcB ($txcA / 1000 * 1000)
:set txcC ($txcA - $txcB)
:set txcB ($txcB / 1000)
:set txc "$txcB.$txcC"

:set rxcA ($"rx-current" / 1000)
:set rxcB ($rxcA / 1000 * 1000)
:set rxcC ($rxcA - $rxcB)
:set rxcB ($rxcB / 1000)
:set rxc "$rxcB.$rxcC"

:set rxtaA ($"rx-total-average" / 1000)
:set rxtaB ($rxtaA / 1000 * 1000)
:set rxtaC ($rxtaA - $rxtaB)
:set rxtaB ($rxtaB / 1000)
:set rxta "$rxtaB.$rxtaC"

:set txtaA ($"tx-total-average" / 1000)
:set txtaB ($txtaA / 1000 * 1000)
:set txtaC ($txtaA - $txtaB)
:set txtaB ($txtaB / 1000)
:set txta "$txtaB.$txtaC"

}

#:log warning "rxta:"
#:log warning ($rxtaB)
#:log warning "txcB:"
#:log warning ($txcB)

/queue simple set [find comment="bwRX"] name=($rxtaB)
/queue simple set [find comment="bwTX"] name=($txcB)

}