Page 1 of 1

Bandwidth test daily

Posted: Wed Mar 21, 2018 5:14 pm
by afbonillac
Hi friends,

I need create a script that satures the channel "Bandwith test" daily for 1 minute and this result save in a plane file during 1 mounth, and this file send to mail the last day of month,

I create a schelude with this script "/tool bandwidth-test address=207.32.195.2 user=btest password=btest duration=60 file=resultado" but generate this file with this information
"# mar/21/2018 10: 7: 7 by RouterOS 6.40.4
# software id = 9DKZ-R6YT
#
status: connecting
duration: 0s
rx-current: 0bps
rx-10-second-average: 0bps
rx-total-average: 0bps
lost-packets: 0
random-data: no
direction: receive
rx-size: 1500
"

Thanks.

Re: Bandwidth test daily

Posted: Thu Sep 06, 2018 4:21 pm
by punkaker
Hi! I am interested exactly in the same, to make some kind of script to schedule a Bandwith Test at night and save results in a text file to compare the available speed of a connection. Did you have any progress with this issue?

Re: Bandwidth test daily

Posted: Thu Sep 06, 2018 8:12 pm
by ADahi
first temp script
modify it as you need
:do {/tool

:local avrTX 0;
:local avrRX 0;
:local luser "";
:local lpass "";
:local Addr  "";

 bandwidth-test duration=60s user=$luser password=$lpass protocol=tcp address=$Addr direction=both do={
 :if ($status="done testing") do={
 :set $avrTX ("tx-total-average: " . ($"tx-total-average" / 1048576) . "." . ($"tx-total-average" % (1048576) / 1024) . " Mbps" );
 :set $avrRX ("rx-total-average: " . ($"rx-total-average" / 1048576) . "." . ($"rx-total-average" % (1048576) / 1024) . " Mbps" );
 }
}
:log info message=$avrTX;
:log info message=$avrRX;
} on-error={:log error message="script failed"}

Re: Bandwidth test daily

Posted: Fri Sep 21, 2018 11:03 am
by punkaker
Hi Adahi! Thanks for your reply.

I have tested your script, and apparently the bandwith test is running correctly (I see the traffic in the interface) but in the log, the displayed values are "0" and "0". Do you know what can be wrong?

Thanks in advance!

Re: Bandwidth test daily

Posted: Fri Sep 21, 2018 11:25 am
by ADahi
it was working on bugfix versions
modify script required for stable versions

Re: Bandwidth test daily

Posted: Fri Sep 21, 2018 11:40 am
by punkaker
Dear Adahe,

Thanks, it seems that it did not work the first time but the next ones is working properly! :)

I think that I will modify it to divide into 2 parts so the test is performed separately in TX and RX (donĀ“t like the "both" results), and so the results are recorded into a text file and stored in the Mikrotik.

Thanks for your help!!

Re: Bandwidth test daily

Posted: Fri Sep 21, 2018 11:50 am
by ADahi
you welcome :D

Re: Bandwidth test daily

Posted: Fri Sep 21, 2018 3:27 pm
by punkaker
I have modified the script from Adahi so it stores the results in a text file, so the script can be scheduled daily to analyze the BW-test result on different days. I have added comments too. I share with the community, just in case! :)
:log info "------------ BW-TEST Starts--------------";

:local luser "BW Test Server USER";
:local lpass "BW TEST Server PASSWORD";
:local Addr  "BW TEST Server IP ADDRESS";

:local avrRX 0;
:local avrTX 0;


# DOWNLOAD TEST
:log info "----> Measuring RX (30 seg)........";
:do {/tool
   bandwidth-test duration=30s user=$luser password=$lpass protocol=tcp address=$Addr direction=receive do={
     :set $avrRX ("rx-total-average: " . ($"rx-total-average" / 1048576) . "." . ($"rx-total-average" % (1048576) / 1024) . " Mbps" );
   }
} on-error={:log error message="RX script failed"}

:delay 2s;

# UPLOAD TEST
:log info "----> Measuring TX (30 seg) ........";
:do {/tool
  bandwidth-test duration=30s user=$luser password=$lpass protocol=tcp address=$Addr direction=transmit do={
     :set $avrTX ("tx-total-average: " . ($"tx-total-average" / 1048576) . "." . ($"tx-total-average" % (1048576) / 1024) . " Mbps" );
  }
} on-error={:log error message="TX script failed"}

:log info message=$avrRX;
:log info message=$avrTX;
:log info "-------- End of  BW-TEST------------";


################# SAVING RESULTS WITH DATE ######################
:local filename2 "LOG_BW_TEST.txt"
:local ds [/system clock get date];
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local month [ :pick $ds 0 3 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set mm ("0" . $mm); };
:set ds ([:pick $ds 7 11] . $mm . [:pick $ds 4 6]);

:if  ( [:len [/file find name=$filename2]] = 0) do={
:log info "Log file does not exist. Creating a new one.....";
/file print file=$filename2 where name="";
}

:log info "Adding result to the end of the lof file......";
/file set $filename2 contents=([get $filename2 contents]  ."\n".$ds."-->" . $avrRX);
/file set $filename2 contents=([get $filename2 contents] ."    ". $avrTX);
}



Re: Bandwidth test daily

Posted: Mon Nov 26, 2018 12:52 am
by jo2jo
cool, see this thread too, at the bottom i made a tiny modification to make it so repeated/scheduled BW test results can be pulled via SNMP (ie so they can be graphed over time).
viewtopic.php?f=9&t=129513&p=699739

Re: Bandwidth test daily

Posted: Mon Nov 26, 2018 8:23 am
by Jotne
I did send it over syslog to graph it. This way I do not need to tell the management tool (Splunk) to collect it and what mib to use.
Same script added to all routers, no need to tell one and one that I should collect anything.
Se graphs here: viewtopic.php?t=137338