Automatic bandwidth test

I search script run bandwidth test on a regular basis.
And the results forward per email.
Anyone have experience with it?

Here is a script that does what you want. It may be a bit overkill, but should point you in the right direction. I think it was used in 5.x. Edit the details at the top, and the “/tool email” line at the bottom. Use the scheduler to run it at the desired interval.

:local desc "Bandwidth test"
:local targetIP 192.168.88.1
:local user "admin"
:local pass "password"

:local output
:local cpu
/tool bandwidth-test address=$targetIP direction=both duration=30s user=$user password=$pass protocol=udp do={
	:if ($status="running") do={
# each second, add cpu load to an array
		:set cpu ($cpu , [/system resource get cpu-load])
	}
	:if ($status="done testing") do={
# add all cpu-load values together
		:local cpuTotal 0
		:foreach i in=$cpu do={
			:set cpuTotal ($cpuTotal + $i)
		}
# get total average cpu-load		
		:set cpuTotal ($cpuTotal / [:len $cpu])

# get last array item number		
		:local j1 ([:len $cpu]-1)
# subtract nine to get the last 10 array items, *note below		
		:local j2 ($j1 - 9)
# if subtracted number is negative, set to 0 for first value of the array
		:if ($j2 < 0) do={
			:set j2 0
		}
# calculate cpu average for last 10 seconds
		:local cpu10s 0
# *note referenced from above. Because "for from=x to=y" includes BOTH starting and ending numbers, these need to be 9 apart to equal 10 iterations. If x=15 and y=5, this will equal 11 total iterations. x=15 and y=6 will equal 10 iterations.
		:for j from=$j1 to=$j2 do={
# add last 10 (or less) array items together
			:set cpu10s ($cpu10s + [:pick $cpu $j])
		}
# get average of last 10 (or less). Because our numbers factor to 9 for the "for" statement above, re-add 1 for a correct count
		:set cpu10s ($cpu10s / ($j1 - $j2 + 1))
	
		:set output ($output . "Direction: " . direction . "\r")
		:set output ($output . "Duration: " . duration . "\r")
		:set output ($output . "---------------------------------------\r")
		:set output ($output . "CPU current: " . [:pick $cpu ([:len $cpu]-1)] . "%\r")
		:set output ($output . "CPU 10 second average: " . $cpu10s . "%\r")
		:set output ($output . "CPU total average: " . $cpuTotal . "%\r")
		:set output ($output . "---------------------------------------\r")
		:set output ($output . "Tx current: " . (tx-current / 1000000) . " Mbps\r")
		:set output ($output . "Tx 10 second average: " . (tx-10-second-average / 1000000) . " Mbps\r")
		:set output ($output . "Tx total average: " . (tx-total-average / 1000000) . " Mbps\r")
		:set output ($output . "---------------------------------------\r")
		:set output ($output . "Rx current: " . (rx-current / 1000000) . " Mbps\r")
		:set output ($output . "Rx 10 second average: " . (rx-10-second-average / 1000000) . " Mbps\r")
		:set output ($output . "Rx total average: " . (rx-total-average / 1000000) . " Mbps\r")
		
		/tool e-mail send subject="$desc" body="$output" ......
	}
}

Thanks Skot, i try this out and let you know if it works.

Don’t work i think email settings are not correct ore cli is changed.
Use RouterOS 6.25

Hello,

Anyone has this script working with v 6 and higher ?

I have tested and changed a few settings and options but can´t get it work.

Whta’s going wrong? it’s don’t work here also