Disable Mikrotik Interface based on volume of data

This is a simple and crude method to disable an interface based on the volume of data that has gone through it. In the below example we will be using the rx bytes on ether4

# interface to control
:local if ether4

:local rx [/interface get $if rx-byte]

:if ($rx>512000000) do={
	:log info "512mb limit passed"
	/interface ethernet disable $if

In the example above the above script is scheduled to run every 5 mins, if the rx bytes on ether4 are greater than 512000000 bytes (512mb) then “512mb limit passed” will be written into the log and then ether4 will be disabled.

If you wanted 30Gb of volume to be the limit then the number of bytes you would change the 512000000 to would be 30720000000. don’t forget to also change the log entry for the volume of data you have decided on.

To get the interface running again, reset the traffic counters on that interface and then enable it again. Once it hits the volume threshold it will disable the interface once more. I did say it was crude and dirty!!!!!