Bandwidth-test in a script

Hello

I am trying to write a script that does a bandwidth-test and keep the 10 second average values.
So in the script there are the following lines :

:global i 5 ;
/tool bandwidth-test 10.140.14.11 duration=5s direction=transmit user=admin password=***** do (:set i $tx-10-second-average; :log info “$i”; }

When you run the script, it logs only one value which is 0. When you run the above two lines from the command prompt it logs every value. I realized that when you run the script it seems that it doesn’t run the bandwidth command for the specific duration. So it gives you back always 0 because is the first value when bandwidth-test tries to connect.

Also if you run the following on the command prompt

/tool bandwidth-test 10.140.14.11 duration=5s direction=transmit user=admin password=***** file=bw

it creates the file bw with only one entry :

status: connecting
duration: 0s
tx-current: 0bps
tx-10-second-average: 0bps
tx-total-average: 0bps
random-data: no
direction: transmit
tx-size: 1500
Any idea? Am I doing something wrong? Any other solution ?

Thank you

Have the same problem…

Have the same problem…

I know this is an old tread, but since it was never answered and it is the first hit when you look for one, I’ll post my own findings:

/tool {
    :local txAvg 0
    :local rxAvg 0
    bandwidth-test 1.2.3.4 duration=20s direction=both user=BTestClient password=******** do={
        :if ($txAvg < $"tx-10-second-average") do={
            :set txAvg $"tx-10-second-average"
        }
        :if ($rxAvg < $"rx-10-second-average") do={
            :set rxAvg $"rx-10-second-average"
        }
    }
    :put ("tx: " . ($txAvg / 1024) . " rx: " .  ($rxAvg / 1024))
}

Observe all running properties that contain a dash in their name needs to be in quotes (e.g. $“tx-10-second-average”). $status goes through the values “connecting”, “running”, and “done testing” (assuming it can connect).

Looks like minimum policies for btest client is ‘winbox’ and ‘test’.

Anyone tried it out?
How send result by mail?
No Gmail

Hi,

I have tried your script and it works fine. The only thing is that your calculation is wrong. We are dealing with transmission speeds and not data capacities. Transmission speeds use bits per second and data capacities use bytes. So the following is incorrect:

:put ("tx: " . ($txAvg / 1024) . " rx: " . ($rxAvg / 1024))

Should be:

:put ("tx: " . ($txAvg / 1000) . " rx: " . ($rxAvg / 1000))

Qiet72

After experimenting with your script, I find the output results are actually quite inconsistent compared to what the “bandwidtht-test” tool reports. After some testing, I finally got consistency.
Here is the resulting script:
/tool {
:local rxAvg 0
:local txAvg 0
bandwidth-test 1.2.3.4 duration=20s direction=both protocol=tcp user=btuser password=xxxxxxx do={
:set rxAvg ($“rx-10-second-average”/1000)
:set txAvg ($“tx-10-second-average”/1000)
}
:put “Rx/Tx: $rxAvg/$txAvg Kbps”
}
Qiet72

In what way? I was personaly going for the max 10 second avg over a 20 second periode, and picking the ‘true’ 10 second avg should at most be a matter of taste? (and so is 1000 and 1024 as long you are consistant in what you comape with)

I see the difference now. In your script, you are setting the ?xAvg variables to the highest bitrate ever during the test. Since there can be a burst especially in the beginning of the test then it does not make sense to record that. It is instead better to record “over time” the 10 second average - that is why I record constantly the 10 second average bitrate until the test is finished.

Qiet72