Community discussions

MikroTik App
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

flakey script execution

Thu Sep 03, 2009 2:40 am

This puzzles me... I have tested each of the lines of script on our office Mikrotik before deploying it to the current Mikrotik with the same version.
The second :if ($monitors>7000000)... line was entered because after monitors was greater than 14 nothing else happened.
Now I have noticed that the log shows the value of monitors every time the scripts run but sometimes skips logging the value of traffic.
I have even forced traffic to be greater then 14 but the rest of the script never runs.
The value of traffic will continue to increment until the value of monitors drops below 700000. Then it goes back to 0. :?

:global traffic
:global monitors
:local counter
:local numberofqueues
:local in
/interface monitor-traffic Lookout once do={:set monitors $"tx-bits-per-second"}
:if ($monitors>7000000) do={:set traffic ($traffic+1)} else={:set traffic 0}
:if ($monitors>7000000) do={:log info $monitors;:log info $traffic;}
:if ($traffic>14) do={:set counter 1;:set numberofqueues [/queue simple print count];:set numberofqueues {$numberofqueues-1};:while ($counter < $numberofqueues) do={:set in {"*".[:tostr $counter]}; /queue simple set $in burst-limit=3M/3M; :set counter ($counter + 1);};}
:if ($traffic>14) do={:set traffic 1; /system script run wait5;}

Just to clarify the numberofqueues part is required because the last two queues are defaults that we do not change.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 3:51 am

What is this script supposed to be doing? As in, what goal are you trying to achieve?

Your numberofqueues part is off. You can't rely on queues starting with id *1 - here a quick example from a test system:
:foreach queue in=[/queue simple find] do={:put $queue}
*12
*13
*14
*15
The test system has 4 simple queues, and as you can see there's no id *1 because earlier queues have been deleted. Additionally, I'm not sure you can create ids by combining strings, the type might not be cast right.

To change the rate limit on all but the two default queues, you could for example assign a comment to those two queues (such as "Default queues"), and filter them out:
:if ($traffic>14) do={
	:foreach queue in=[/queue simple find comment!="Default queue"] do={
		/queue simple set $queue burst-limit=3M/3M;
	}
}
I'm not sure why you're increasing the traffic variable, either. Is this script run every now and then by a scheduler and you only want to change queue bursts if a utilization persists over time?

Felix
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 7:02 pm

Yes that is it. I runs every twenty seconds.
I was not aware of the of the problem with queue numbers.
I assumed they would always start with *1.

I did not consider the option you have shown.

Thanks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 7:21 pm

You may want to investigate "/tool traffic-monitor". You can use that to put a monitor on an interface that fires a script when bandwidth for certain traffic goes above or falls below a threshold.
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 9:22 pm

Yes but we only run the script when it has been above the threshold for 5 minutes.
My understanding of "/tool traffic-monitor" does not have that ability.
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 9:26 pm

The other problem is you can not call two queues by the same name.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 9:34 pm

You can still use it to make your script much simpler.

Use the traffic-monitor to fire a script when traffic utilization is above a threshold, that script sets a global variable of "threshold-reached" to "([/system clock get time] + 5m)". The script that fires when utilization drops under the threshold again sets the global variable to 23:59:59 and adjusts the queues to their normal value (blindly, because changing to the same value doesn't hurt and it makes the logic simple).

Then you schedule a script to run every minute or so that checks whether or not "[/system clock get time]" is larger than the "threshold-reached" global variable. If yes, utilization has been above the threshold for over 5 minutes and you adjust your queues. If not, do nothing.

I'm not sure I understand the issue with not being able to give two queues the same name - what exact problem does that cause?
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 9:56 pm

error queue by that name already exists
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 10:05 pm

Yes. You can't create two queues with the same name. That's true for pretty much all objects in a Mikrotik router. You also cannot create two interfaces with the same name. Why do you need to name two queues the same?
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 10:20 pm

:if ($traffic>14) do={
   :foreach queue in=[/queue simple find comment!="Default queue"] do={
      /queue simple set $queue burst-limit=3M/3M;
   }
}
This would only skip one Default queue when I have two default queues to skip
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 10:23 pm

No. That would skip all queues that have a _COMMENT_ of "Default queue". Multiple queues can carry the same comment.
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 10:49 pm

Ok I feel stupid - duh... :oops:

I noticed that the queue named Default queue changed with all the other ones.

duh :oops:
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Thu Sep 03, 2009 11:25 pm

:global threshold

:set threshold 23:59:59

:foreach queue in=[/queue simple find comment!="Default queue"] do={
      /queue simple set $queue burst-limit=10M/10M;
   }
when this ran it all my dynamic queues created by DHCP were removed. :(
Only the static ones were left.
Now I have to wait for every ones routers to reup their leases so they get their queues back. :(

Version 3.28 on x86
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: flakey script execution

Thu Sep 03, 2009 11:37 pm

Maybe adjust it by putting a comment on all queues you want to change, and filtering by that instead of excluding by comment.
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Fri Sep 04, 2009 12:57 am

OK a little more info...

The disappearing dynamic queues occurs when I make a change to the Traffic Monitor Threshold setting while Traffic Monitor was running.

Did I find a bug?

Fortunately rebooting the router brings the queues back. :D

The comment in all the queues would not work since they are created by DHCP.
 
PteraWireless
newbie
Topic Author
Posts: 34
Joined: Tue Apr 07, 2009 6:37 pm

Re: flakey script execution

Fri Sep 04, 2009 3:49 am

:if ([/system clock get time]  > $threshold) do={
:foreach queue in=[/queue simple find comment!="Default queue"] do={
      /queue simple set $queue burst-limit=3M/3M;
   }
}
Well what is wrong with this?
The proper conditions were met but nothing happened.

I also ran the same script on another Mikrotik here at the office and it worked. :?