im use mikrotik v 3.13 on pc hotspot lan network
i need scrept to like that
:if ([:len [//queue simple %nmber-of-red-colour%]] >=5) do={/ip proxy access enable [/ip proxy access find comment=1]}
and i use user profile to limet the speed
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:put $local;
While you can't directly retrieve the number of queues shown red in the GUI, here a quick snippet that should work for counting up the number of Hotspot queues that are over 90% utilization at that point in time:
Though I'm not sure why you wouldn't want the proxy to be enabled at all times. Also, I'm not sure at all how well that code would scale for lots of Hotspot users. It does quite a bit of work to get to the count. There may be much better solutions to what you actually want to achieve, I was mostly curious how you could script out calculating queue utilization.Code: Select all:local count 0; # cycle through all Hotspot queues :foreach queue in=[/queue simple find name~"^<hotspot"] do={ # retrieve max-limit for queue :local limit [/queue simple get $queue max-limit]; # take out the upload limit, since we only care about downstream traffic :set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]]; # convert k and m abbreviations into numerical values :if ([:pick $limit ([:len $limit] - 1)] = "k") do={ :set limit [:pick $limit 0 ([:len $limit] - 1)]; :set limit ($limit * 1000) }; :if ([:pick $limit ([:len $limit] - 1)] = "m") do={ :set limit [:pick $limit 0 ([:len $limit] - 1)]; :set limit ($limit * 1000000) }; # get the current rate in the queue :local rate [/queue simple get $queue rate]; # again parse out the downstream portion :set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]]; # calculate the delta between the two :local delta ($limit - $rate); # increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization) :if ($delta < ($limit / 4)) do={ :set count ($count + 1) } }; :put $local;
thanks mr Chupaka i think u remember me !!!!p.s. red is >= 75%
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:if ($count >=5) do={
:foreach proxyElement in=[/ip proxy access find comment=1] do={
/ip proxy access enable $proxyElement;
}
}
[admin@MikroTik] > /system script print
Flags: I - invalid
0 name="stuff" owner="admin" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive last-started=oct/07/2009 15:47:54 run-count=1 source=
/ip proxy access print terse
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:if ($count >=1) do={
:put "enabling proxy access rules"
:foreach proxyElement in=[/ip proxy access find comment=1] do={
/ip proxy access enable $proxyElement;
}
} else={
:put "not enabling proxy access rules, condition not met"
}
/ip proxy access print terse
[admin@MikroTik] > /queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0 D name="<hotspot-test>" target-addresses=10.2.1.254/32 dst-address=0.0.0.0/0 interface=all parent=none direction=both priority=8 queue=default-small/default-small limit-at=128k/128k max-limit=128k/128k burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
1 D name="hs-<Wired>" dst-address=0.0.0.0/0 interface=Wired parent=none direction=both priority=8 queue=hotspot-default/hotspot-default limit-at=1M/1M max-limit=1M/1M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
2 D name="hs-<Wireless>" dst-address=0.0.0.0/0 interface=Wireless parent=none direction=both priority=8 queue=hotspot-default/hotspot-default limit-at=1M/1M max-limit=1M/1M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
[admin@MikroTik] > :put [/queue simple get 0 rate]
0/0
[admin@MikroTik] > /system script run 0
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
not enabling proxy access rules, condition not met
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
[admin@MikroTik] > :put [/queue simple get 0 rate]
4584/129000
[admin@MikroTik] > /system script run 0
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
enabling proxy access rules
0 comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}
/ip proxy access print detail where disabled=yes
:local count 0;:foreach queue in=[/queue simple find name~"^<hotspot"] do={:local limit [/queue simple get $queue max-limit];:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];:if ([:pick $limit ([:len $limit] - 1)] = "k") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:if ([:pick $limit ([:len $limit] - 1)] = "M") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:local rate [/queue simple get $queue rate];:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];:local delta ($limit - $rate);:if ($delta < ($limit / 4)) do={:set count ($count + 1); :put "rate: $rate, limit: $limit, increasing count"} else={:put "rate: $rate, limit: $limit, not increasing count"}};:put "total count: $count";:if ($count >=1) do={:put "enabling proxy access rules";:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}} else={:put "not enabling proxy access rules, condition not met"}
:local count 0;:foreach queue in=[/queue simple find name~"^<hotspot"] do={:local limit [/queue simple get $queue max-limit];:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];:if ([:pick $limit ([:len $limit] - 1)] = "k") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:if ([:pick $limit ([:len $limit] - 1)] = "M") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:local rate [/queue simple get $queue rate];:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];:local delta ($limit - $rate);:if ($delta < ($limit / 4)) do={:set count ($count + 1); :put "rate: $rate, limit: $limit, increasing count"} else={:put "rate: $rate, limit: $limit, not increasing count"}};:put "total count: $count";:if ($count >=1) do={:put "enabling proxy access rules";:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}} else={:put "not enabling proxy access rules, condition not met"}
foreach queue in=[/queue simple find name~"^<hotspot"] do={:put /queue simple get $queue name}
Unless I'm mistaken, that screenshot does not show you running the script you quote in the same post. The script you're quoting in the same post outputs one line per Hotspot queue found.
If you are sure you're running that script, post the output of
If that doesn't output anything, version 3.13 doesn't support find by regular expression and the script cannot work on 3.13, and you'd have to upgrade to 3.30 (as stated earlier, the script works for me running 3.30). Maybe try upgrading anyway and see if it works.Code: Select allforeach queue in=[/queue simple find name~"^<hotspot"] do={:put /queue simple get $queue name}
Try that instead. My apologies.:foreach queue in=[/queue simple find name~"^<hotspot"] do={:put [/queue simple get $queue name]}
I'm sorry I was quickly posting that before leaving work and that code won't run:
Try that instead. My apologies.:foreach queue in=[/queue simple find name~"^<hotspot"] do={:put [/queue simple get $queue name]}