Community discussions

MikroTik App
 
afbonillac
just joined
Topic Author
Posts: 1
Joined: Wed Mar 21, 2018 3:48 pm

Bandwidth test daily

Wed Mar 21, 2018 5:14 pm

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.
 
punkaker
just joined
Posts: 13
Joined: Thu Apr 12, 2018 7:26 pm

Re: Bandwidth test daily

Thu Sep 06, 2018 4:21 pm

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?
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Bandwidth test daily

Thu Sep 06, 2018 8:12 pm

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"}
 
punkaker
just joined
Posts: 13
Joined: Thu Apr 12, 2018 7:26 pm

Re: Bandwidth test daily

Fri Sep 21, 2018 11:03 am

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!
You do not have the required permissions to view the files attached to this post.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Bandwidth test daily

Fri Sep 21, 2018 11:25 am

it was working on bugfix versions
modify script required for stable versions
You do not have the required permissions to view the files attached to this post.
 
punkaker
just joined
Posts: 13
Joined: Thu Apr 12, 2018 7:26 pm

Re: Bandwidth test daily

Fri Sep 21, 2018 11:40 am

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!!
You do not have the required permissions to view the files attached to this post.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Bandwidth test daily

Fri Sep 21, 2018 11:50 am

you welcome :D
 
punkaker
just joined
Posts: 13
Joined: Thu Apr 12, 2018 7:26 pm

Re: Bandwidth test daily

Fri Sep 21, 2018 3:27 pm

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);
}


 
jo2jo
Forum Guru
Forum Guru
Posts: 1003
Joined: Fri May 26, 2006 1:25 am

Re: Bandwidth test daily

Mon Nov 26, 2018 12:52 am

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Bandwidth test daily

Mon Nov 26, 2018 8:23 am

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
 
VincentL
newbie
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: Bandwidth test daily

Fri Mar 04, 2022 5:24 pm

Hello,

I need to collect datas from speedtest, or ping and bandwithtest.
While googlize it, I found this thread.
My skills in routeros scripting are low but the Punkaker script with comment is clear to but understable.

Now I' d like to understand this line : :set $avrRX ("rx-total-average: " . ($"rx-total-average" / 1048576) . "." . ($"rx-total-average" % (1048576) / 1024) . " Mbps" );
Specifically, why we need to divide by 1048576 or 1024.

Thank you for your reply

Vincent
 
VincentL
newbie
Posts: 34
Joined: Fri Feb 03, 2017 3:27 pm

Re: Bandwidth test daily

Thu Mar 10, 2022 3:39 pm

Hello,

Reply to myself : 1048576 == 1024*1024, so Byte to MegaBytes conversion.

Regards,

Vincent
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Bandwidth test daily

Thu Mar 10, 2022 8:21 pm

Improve your knowledge, it is since 1998 that

1 Megabit (Mb / Mbit) = 1000 KiloBit (kb / kbit) = 1000000 bit

1 Mebibit (Mib / Mibit) = 1024 Kibibit (Kib / Kibit) = 1048576 bit

8 bit = 1 Byte

1 MegaByte (MB) = 1000 KiloByte (kB) = 1000000 Byte

1 MebiByte (MiB) = 1024 KibiByte (KiB) = 1048576 Byte

1 Byte = 8 bit

1MB = 8000000 bit

1MiB = 8388608 bit

The results are on bps, bit-per-second, if Mega-bit-per-second is wanted, must be something like this (ignoring if is coded right and is the other parts are correct):
:set $avrRX ("rx-total-average: " . ($"rx-total-average" / 1000000) . "." . ($"rx-total-average" % (1000000) / 1000) . " Mbps" );
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1053
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: Bandwidth test daily

Thu Mar 10, 2022 8:39 pm

Well, no/yes - or it's actually both depending on the use of SI or IT (de facto standard) for eg storage etc. Yeah, it's a mess: Megabyte (Wikipedia)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Bandwidth test daily

Thu Mar 10, 2022 8:42 pm

For speed point of view, everityme bit is used.
As ISP I everytime talk about bit-per-second when I sell 100M (100Mbit/s) = 100.000.000

From storage point of view, MiB are used, 1TB SSD give different space if TiB or TB are really intended....
1.099.511.627.776 or 1.000.000.000.000 is near "100GB" less

Usually when bit is involved 1000x are used, and 1024x if bytes is used
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1053
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: Bandwidth test daily

Fri Mar 11, 2022 10:40 am

For speed point of view, everityme bit is used. As ISP I everytime talk about bit-per-second when I sell 100M (100Mbit/s) = 100.000.000
Concur.

From storage point of view, MiB are used, 1TB SSD give different space if TiB or TB are really intended....1.099.511.627.776 or 1.000.000.000.000 is near "100GB" less Usually when bit is involved 1000x are used, and 1024x if bytes is used
Yeah, and according to IEC (1984) we should also use Kibibit, Mebibyte and Gibibyte to be more precise but I've never managed to get used to that concept so I still mix up the notations.

Who is online

Users browsing this forum: No registered users and 14 guests