Community discussions

MikroTik App
 
galaxyaord
just joined
Topic Author
Posts: 10
Joined: Fri Nov 01, 2019 11:11 pm

Sum values obtained with foreach

Sat Feb 13, 2021 9:49 am

Greetings. I want to obtain the limit-at variable of all the queues that correspond to a parent and add all its values in the same variable, how can I do this? I run the following commands:
 :foreach b in=[/queue simple find parent=example-parent] d={
	:global test [/queue simple get $b limit-at]; :put $test
	} 
but instead of giving me the total value they are printed individually line by line, for example:

1M / 5M
1M / 2M
2M / 1M

How can I do so that when consulting the variable for example $ result it gives me the total sum? In this case: put $result = 3M/8M
 
Emil66
just joined
Posts: 23
Joined: Tue Aug 28, 2018 2:09 am

Re: Sum values obtained with foreach

Sat Feb 13, 2021 11:44 am

Sums are obtained by adding stuff up. Computers only do what they're told. Try telling the computer to add something.
Hex S
 
galaxyaord
just joined
Topic Author
Posts: 10
Joined: Fri Nov 01, 2019 11:11 pm

Re: Sum values obtained with foreach

Sat Feb 13, 2021 2:58 pm

Sums are obtained by adding stuff up. Computers only do what they're told. Try telling the computer to add something.
I publish precisely because I cannot find how to combine all the results in a single variable
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1915
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Sum values obtained with foreach

Sat Feb 13, 2021 8:05 pm

Split the data inn to two variables (do not need to use global her so use local variable)
Then sum up
https://wiki.mikrotik.com/wiki/Manual:S ... _Operators
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 

Who is online

Users browsing this forum: No registered users and 14 guests