Page 1 of 1

Interface Data Quota

Posted: Sat Aug 03, 2019 12:59 pm
by famverschoor
Hello everyone.
I'm new here, so excuse me if I post this in the wrong section.
So what I want to do is set a quota on an interface. I have created a wireless interface called "Joel" and I have connected all devices to the interface that must have a quota of 1 GB per day.
I have already created a script that automatically turns off the interface at 11:00 in the evening and created a script that automatically turns on the interface at 7:00 in the morning.
I now want to have a script that disables the interface after 1 GB of traffic, and since I already have a script that turns the interface on again the next morning, the 1 GB will become available again the next day. so the only thing the script needs to do is check if the wireless interface has already used 1gb, and if so, switch off the interface. is that possible, and who can / wants to help me?
Thank you very much in advance!
Fam Verschoor

Re: Interface Data Quota

Posted: Sun Aug 04, 2019 7:25 pm
by Jotne
I do have some problem/bug with my script to help you out.

This should get the rx-byte on interface ether1, but gives nothing.
:put [/interface print as-value stats where name="ether1" rx-byte]
This works:
:put [/interface print as-value stats where name="ether1"]
.id=*1;comment=;name=ether1;rx-byte=2494462011;rx-drop=0;rx-error=0;rx-packet=4402118;tx-byte=492032450;tx-drop=0;tx-error=0;tx-packet=341711;tx-queue-drop=0
This does not work:
{
:local interface "ether1"
:local arr [/interface print as-value stats where name=$interface]
:put ($arr->"rx-byte")
}
This work:
{
:local interface "ether1"
:local arr [/interface print as-value stats where name=$interface]
:set ($arr->"test") "demo"
:put ($arr->"test")
}
demo
If I do test the arr with this, it show array, so what is wrong???
:put [:typeof $arr]
array

Re: Interface Data Quota

Posted: Mon Aug 05, 2019 11:43 am
by Jotne
I was some off in previous post.

This should get you started
{
:global grx
:local rx [/interface get ether1 rx-byte]
:local mbrx ($rx/1048576)
:local diff ($mbrx-$grx)
:put "diff=$diff local=$mbrx global=$grx"
:if ($diff>1024) do={
	:put "larger"
	:global grx $mbrx
	:put "turn off interface"}
}
Since I do not se any way to clear the counter, I store the current MB data used in a global variable.
Then it compare with current data, and if current data is more than 1000MB large, set global variable to current and you can turn off interface.

Re: Interface Data Quota

Posted: Wed Aug 07, 2019 4:07 pm
by famverschoor
Thank you!
And how to i set tje interface name? i don't know much about this, i only know how scheduler works. does this script needs to schedue every minute?
and for sure: does that script turn off the interface called "joel" ?
the next morning the interface automaticly goed on by a self made script.
Thank you for your time!
fam Verschoor

edit: i need a script that automaticlly turns off after 1gb of data traffic, and the next day the interface turns back on and there have to be another 1gb, and so on each day.

Re: Interface Data Quota

Posted: Wed Aug 07, 2019 10:56 pm
by Jotne
To list all interface type
/interface print
They will be named some like ehter1, ether2 etc.
# interface to control
:local if ether1

:global grx
:local rx [/interface get $if rx-byte]
:local mbrx ($rx/1048576)
:local diff ($mbrx-$grx)
:put "diff=$diff local=$mbrx global=$grx"
:if ($diff>1024) do={
	:log info "1GB limit passed"
	/interface ethernet disable $if
	:global grx $mbrx}
Script above will shutdown interface when 1GB of data has been transferred.
Schedule it to run every 5 min.

Then have a script to enable interface the next day, at ex 07:00
# interface to control
:local if ether1

/interface ethernet disable $if

Re: Interface Data Quota

Posted: Wed Aug 07, 2019 11:16 pm
by famverschoor
Thank you!
tomorrow i am gonna try that script.
Hope it works...
thank you for your time!
fam verschoor

Re: Interface Data Quota

Posted: Thu Aug 08, 2019 10:50 am
by famverschoor
Hi,
i have set the script in my microtik and schedule it every 5 minutes.
also, i have changed the ''ether1'' on the top and the ''ether'' at the buttom of the script to my interface name ''joel''
But the script doesn't work. i have tried download a 1gb file, from https://www.thinkbroadband.com/download, but after the download completed i wait 5 minuteds and tried running the script manually, but the interface is still on and usable. so i tried download a SECOND 1gb file from https://www.thinkbroadband.com/download, and it succed, and the interface is still not switched to ''disable''.
Is this a bug, or do i need some more or some less?

I already have a script that turn the interface automaticlly on in the morning the next day.

thanks for your time!
fam verschoor

Re: Interface Data Quota

Posted: Thu Aug 08, 2019 3:42 pm
by Jotne
Strange interface name.
ether may hit both ether1, ether2++++
Also you need to enable same interface you disable. Can not be two different name.

Can you post output of
/interface print

Re: Interface Data Quota

Posted: Sun Aug 18, 2019 1:41 pm
by famverschoor
hi, i was on vacation, sorry for my late answer.
the output of the /interface print command:

# NAME TYPE ACTUAL-MTU L2MTU MAX-L2MTU MAC-ADDRESS
0 R ether1 ether 1500 1598 4074 CC:2D:E0:C5:17:D-
1 RS ether2-master ether 1500 1598 4074 CC:2D:E0:C5:17:D-
2 S ether3 ether 1500 1598 4074 CC:2D:E0:C5:17:D-
3 S ether4 ether 1500 1598 4074 CC:2D:E0:C5:17:D-
4 S ether5 ether 1500 1598 4074 CC:2D:E0:C5:17:E-
5 S sfp1 ether 1500 1600 4076 CC:2D:E0:C5:17:E-
6 S Joel wlan 1500 1600 2290 CC:2D:E0:C5:17:E2
7 S Wifitweekommaviergigaherts wlan 1500 1600 2290 CC:2D:E0:C5:17:E-
8 R ;;; defconf
bridge bridge 1500 1598 CC:2D:E0:C5:17:D-
I removed 1 character from the mac addresses of all inerfaces for my privacy, but not from the "joel" interface
for sure: only the "joel" interface needs a quota. the other have to be on.
Verschoor

Re: Interface Data Quota

Posted: Sun Aug 18, 2019 8:27 pm
by Jotne
If I am correct, you have renamed wan1 interface to joel?

Do you get any data from this?
:put [/interface print as-value stats where name="Joel" rx-byte]
What version do you run? This seems to be old naming: ether2-master

Re: Interface Data Quota

Posted: Mon Aug 19, 2019 1:03 pm
by famverschoor
hi,
yes, you are correct. i have one wlan interface called "Wifitweekommaviergigaherts"and one called "joel"and the limit neds to be in the "joel" interface.
the result of the ":put [/interface print as-value stats where name="Joel" rx-byte]" command is basiccly empty:
[admin@Verschoor - MikroTik] > :put [/interface print as-value stats where name="Joel" rx-byte]

[admin@Verschoor - MikroTik] >

is this a problem, or di i need to set things up?
Verschoor

Re: Interface Data Quota

Posted: Mon Aug 19, 2019 6:07 pm
by Jotne
Then try this and post answer here.
:put [/interface print as-value stats]
Should give data for all interface. Do you se "joel" as a name there.

Re: Interface Data Quota

Posted: Wed Aug 21, 2019 12:33 pm
by famverschoor
Hi, the result of the ":put [/interface print as-value stats]" command:

[admin@Verschoor - MikroTik] > :put [/interface print as-value stats]
.id=*3;comment=;name=ether1;rx-byte=61141908876;rx-drop=0;rx-error=0;rx-packet=55379201;tx-byte=17514463568;tx-drop=0;tx-error=0;tx-packet=37394594;tx-queue-drop=0;.id=*4;co
mment=;name=ether2-master;rx-byte=16664833120;rx-drop=0;rx-error=0;rx-packet=32428061;tx-byte=47185282769;tx-drop=0;tx-error=0;tx-packet=47410555;tx-queue-drop=0;.id=*5;comm
ent=;name=ether3;rx-byte=0;rx-drop=0;rx-error=0;rx-packet=0;tx-byte=0;tx-drop=0;tx-error=0;tx-packet=0;tx-queue-drop=0;.id=*6;comment=;name=ether4;rx-byte=0;rx-drop=0;rx-err
or=0;rx-packet=0;tx-byte=0;tx-drop=0;tx-error=0;tx-packet=0;tx-queue-drop=0;.id=*7;comment=;name=ether5;rx-byte=0;rx-drop=0;rx-error=0;rx-packet=0;tx-byte=0;tx-drop=0;tx-err
or=0;tx-packet=0;tx-queue-drop=0;.id=*8;comment=;name=sfp1;rx-byte=0;rx-drop=0;rx-error=0;rx-packet=0;tx-byte=0;tx-drop=0;tx-error=0;tx-packet=0;tx-queue-drop=0;.id=*2;comme
nt=;name=Joel;rx-byte=2780384118;rx-drop=0;rx-error=0;rx-packet=4765960;tx-byte=9822790120;tx-drop=0;tx-error=0;tx-packet=9641311;tx-queue-drop=37539;.id=*1;comment=;name=Wi
fitweekommaviergigaherts;rx-byte=2477538070;rx-drop=0;rx-error=0;rx-packet=5950811;tx-byte=10990119742;tx-drop=0;tx-error=0;tx-packet=12277336;tx-queue-drop=5661;.id=*9;comm
ent=defconf;name=bridge;rx-byte=17899269034;rx-drop=0;rx-error=0;rx-packet=39255324;tx-byte=61796014792;tx-drop=0;tx-error=0;tx-packet=56893144;tx-queue-drop=0

Re: Interface Data Quota

Posted: Wed Aug 21, 2019 5:39 pm
by Jotne
Then I do not know what is wrong with your system. This is the correct name Joel and it has data.
.id=*2;comment=;name=Joel;rx-byte=2780384118;rx-drop=0;rx-error=0;rx-packet=4765960;tx-byte=9822790120;tx-drop=0;tx-error=0;tx-packet=9641311;tx-queue-drop=37539;
Not sure if I can do any more help

This should give same information.
:put [/interface print as-value stats where name="Joel"]
What Router do you have? What RouterOS version?
How do you run the command? Putty/SSH, Via Winbox/Webgui?

Re: Interface Data Quota

Posted: Wed Aug 28, 2019 4:56 pm
by famverschoor
hi, i have a microtik HAP series, i don't know exactly witch one.How do i see witch version of RouterOS i have?
I command via Winbox terminal on a Windows 10 Pro laptop.

Re: Interface Data Quota

Posted: Wed Aug 28, 2019 9:33 pm
by Jotne
Version
 :put [/system resource get version]
6.44.5 (long-term)
Board name
:put [/system resource get board-name]
hEX
Model
:put [/system routerboard get model]
RouterBOARD 750G r3
See script in my signature (Splunk) for more example

Re: Interface Data Quota

Posted: Sat Aug 31, 2019 10:20 pm
by famverschoor
hi,
my version:
6.45.1 (stable)
my hEX model:
RouterBOARD 962UiGS-5HacT2HnT

Re: Interface Data Quota

Posted: Tue Sep 03, 2019 10:10 pm
by famverschoor
hi, i searched over the internet once again and i got an idea. what i wanted is to limit a group of devices to 1gb per day, i already trief doing it by making an interface for them, and limit that interface, but there is a problem (?)
is there another way to make a group of devices witch have a limitation of 1gb per day, or is the interface method the omly way?

Re: Interface Data Quota

Posted: Wed Sep 18, 2019 9:35 pm
by famverschoor
Hi,
do any of you know a wat to limit users to a certain amount of traffic?

Verschoor