Community discussions

MikroTik App
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

How can I sum the limits-at of all child queues?

Sun Feb 14, 2021 6:11 am

How can I sum the limits-at of all child queues?

I'm "trying" to get a script that gets all the limit-at of the rules that match a parent and that in turn adds all the results in kilobits, so if for example I have 2 daughters with limit-at of 2M/2M I can get a final variable that results in $ example = 4000/4000 but I only get to the point where I get the limit-at I don't know what else to do, I've already read the wiki and I can't do anything else.
This is the script I have managed to do, but it only does half:
 :foreach b in=[/queue simple find parent=parent-example] d={
	:global test [/queue simple get $b limit-at];
	} 

My native language is not English, so understanding the wiki is very difficult for me even with translators, however I understand most of the code I see, please, if you know how to do it, put it as an answer.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How can I sum the limits-at of all child queues?

Sun Feb 14, 2021 12:39 pm

What not continue in this thread?
viewtopic.php?f=9&t=172555
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

Re: How can I sum the limits-at of all child queues?

Sun Feb 14, 2021 4:35 pm

What not continue in this thread?
viewtopic.php?f=9&t=172555
Greetings, because I do not think I have explained myself well in the other and in this I also detail that I have not been able to achieve it on my own. It is also written in another way in the hope that google translator does it well
 
sin3vil
newbie
Posts: 34
Joined: Sat May 26, 2018 10:05 pm

Re: How can I sum the limits-at of all child queues?

Mon Feb 15, 2021 6:13 pm

Something like this would work.
#declare function
global parentTotal do={
#initialize total up and down vars
local totalUp 0
local totalDown 0
#loop over all childs
#print as-value generates an array of associative arrays for each entry
foreach item in=[/queue simple print as-value where parent=$1] do={
#get the limit-at value
local limitat ($item->"limit-at")
#split into up and down values
#up is from start up to /
#down is from /+1 char, to end of string
local up [pick $limitat 0 [find $limitat "/"]]
local down [pick $limitat ([find $limitat "/"]+1) [len $limitat]]
#add it up
set totalUp ($totalUp + $up)
set totalDown ($totalUp + $down)
}
#display and return result in up/down format
put ("$totalUp/$totalDown")
return ("$totalUp/$totalDown")
}

#usage
$parentTotal <parent name>
 
Emil66
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Tue Aug 28, 2018 2:09 am

Re: How can I sum the limits-at of all child queues?

Mon Feb 15, 2021 9:51 pm

You still need to deal with "numbers" like 768k, 3M or 1G.
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

Re: How can I sum the limits-at of all child queues?

Tue Feb 16, 2021 12:51 am

Something like this would work.
#declare function
global parentTotal do={
#initialize total up and down vars
local totalUp 0
local totalDown 0
#loop over all childs
#print as-value generates an array of associative arrays for each entry
foreach item in=[/queue simple print as-value where parent=$1] do={
#get the limit-at value
local limitat ($item->"limit-at")
#split into up and down values
#up is from start up to /
#down is from /+1 char, to end of string
local up [pick $limitat 0 [find $limitat "/"]]
local down [pick $limitat ([find $limitat "/"]+1) [len $limitat]]
#add it up
set totalUp ($totalUp + $up)
set totalDown ($totalUp + $down)
}
#display and return result in up/down format
put ("$totalUp/$totalDown")
return ("$totalUp/$totalDown")
}

#usage
$parentTotal <parent name>
You have made me very happy! haha, but, in which part do I declare which is the parent to look for? Assuming your name is "parent_testtt"
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

Re: How can I sum the limits-at of all child queues?

Tue Feb 16, 2021 1:11 am

Something like this would work.
#declare function
global parentTotal do={
#initialize total up and down vars
local totalUp 0
local totalDown 0
#loop over all childs
#print as-value generates an array of associative arrays for each entry
foreach item in=[/queue simple print as-value where parent=$1] do={
#get the limit-at value
local limitat ($item->"limit-at")
#split into up and down values
#up is from start up to /
#down is from /+1 char, to end of string
local up [pick $limitat 0 [find $limitat "/"]]
local down [pick $limitat ([find $limitat "/"]+1) [len $limitat]]
#add it up
set totalUp ($totalUp + $up)
set totalDown ($totalUp + $down)
}
#display and return result in up/down format
put ("$totalUp/$totalDown")
return ("$totalUp/$totalDown")
}

#usage
$parentTotal <parent name>
I am using this:
 #declare function
global parentTotal do={
#initialize total up and down vars
local totalUp 0
local totalDown 0
#loop over all childs
#print as-value generates an array of associative arrays for each entry
foreach item in=[/queue simple print as-value where parent=$1] do={
#get the limit-at value
local limitat ($item->"limit-at")
#split into up and down values
#up is from start up to /
#down is from /+1 char, to end of string
local up [pick $limitat 0 [find $limitat "/"]]
local down [pick $limitat ([find $limitat "/"]+1) [len $limitat]]
#add it up
set totalUp ($totalUp + $up)
set totalDown ($totalUp + $down)
}
#display and return result in up/down format
put ("$totalUp/$totalDown")
return ("$totalUp/$totalDown")
}

#usage
$parentTotal <testparentname> 
but it gives me 0/0 response

Who is online

Users browsing this forum: rogerioqueiroz and 19 guests