Community discussions

 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Interface Data Quota

Sat Aug 03, 2019 12:59 pm

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Sun Aug 04, 2019 7:25 pm

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
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Mon Aug 05, 2019 11:43 am

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.
Last edited by Jotne on Wed Aug 07, 2019 10:45 pm, edited 1 time in total.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Wed Aug 07, 2019 4:07 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Wed Aug 07, 2019 10:56 pm

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
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Wed Aug 07, 2019 11:16 pm

Thank you!
tomorrow i am gonna try that script.
Hope it works...
thank you for your time!
fam verschoor
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Thu Aug 08, 2019 10:50 am

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Thu Aug 08, 2019 3:42 pm

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
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Sun Aug 18, 2019 1:41 pm

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Sun Aug 18, 2019 8:27 pm

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
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Mon Aug 19, 2019 1:03 pm

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Mon Aug 19, 2019 6:07 pm

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.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Wed Aug 21, 2019 12:33 pm

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Wed Aug 21, 2019 5:39 pm

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?
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Wed Aug 28, 2019 4:56 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1302
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Interface Data Quota

Wed Aug 28, 2019 9:33 pm

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
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Sat Aug 31, 2019 10:20 pm

hi,
my version:
6.45.1 (stable)
my hEX model:
RouterBOARD 962UiGS-5HacT2HnT
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Tue Sep 03, 2019 10:10 pm

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?
 
famverschoor
just joined
Topic Author
Posts: 11
Joined: Sat Aug 03, 2019 12:39 pm

Re: Interface Data Quota

Wed Sep 18, 2019 9:35 pm

Hi,
do any of you know a wat to limit users to a certain amount of traffic?

Verschoor

Who is online

Users browsing this forum: No registered users and 18 guests