<div dir="ltr">I have not until now that you recommended it, looks much simpler indeed, thanks.<div><br></div><div>Although, so far I can't seem to hit a pipe limit. If I watch pl.stats, no matter what <i>timer_interval</i> I set, the counter increases to 1 upon a call then back to 0 the next second.</div><div><div><br></div><div>root@proxy:/# watch -n 1 -d kamcmd pl.stats</div><div>PIPE: id=65.39.XX.XX load=0 counter=0</div></div><div><br></div><div>Say I wanted 1 call per minute pipe, what would be the 'timer_interval' and pl_check limit?</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 9, 2018 at 2:47 PM Alex Balashov <<a href="mailto:abalashov@evaristesys.com">abalashov@evaristesys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Have you considered using pipelimit for this? It's as simple as:<br>
<br>
   if(!pl_check("$avp(customer_id)", "TAILDROP", "$avp(cps_limit)")) {<br>
       pl_drop();<br>
       exit;<br>
   }<br>
<br>
There was a time when that wasn't possible because pipes couldn't easily<br>
be created dynamically for a given customer ID or whatever, and htable<br>
was the preferred vehicle for that. That has changed, and nowadays it's<br>
a lot simpler. :-)<br>
<br>
-- Alex<br>
<br>
On Mon, Jul 09, 2018 at 02:41:44PM -0400, Sergiu Pojoga wrote:<br>
<br>
> Hi folks,<br>
> <br>
> Trying to implement CPS throttling based on this<br>
> <<a href="https://lists.kamailio.org/pipermail/sr-users/2013-September/079713.html" rel="noreferrer" target="_blank">https://lists.kamailio.org/pipermail/sr-users/2013-September/079713.html</a>>article,<br>
> having some trouble.<br>
> <br>
> modparam("htable", "htable", "rhs=>size=32;initval=0;autoexpire=300;"<br>
> modparam("htable", "htable", "rhm=>size=32;initval=0;autoexpire=1800;")<br>
> <br>
> route[CPS] {<br>
> $var(rateHashSec) = $si+":sec:"+$timef(%Y/%m/%d_%H_%M_%S);<br>
> $var(rateHashMin) = $si+":min:"+$timef(%Y/%m/%d_%H_%M_00);<br>
> xlog("L_INFO", "var(rateHashSec)=$var(rateHashSec);<br>
> var(rateHashMin)=$var(rateHashMin)\n");<br>
> $var(ratePerSec) = $shtinc(rhs=>$var(rateHashSec));<br>
> $var(ratePerMin) = $shtinc(rhm=>$var(rateHashMin));<br>
> xlog("L_INFO", "var(ratePerSec)=$var(ratePerSec);<br>
> var(ratePerMin)=$var(ratePerMin)\n");<br>
> $var(limitPerSec) = 1;<br>
> $var(limitPerMin) = 1;<br>
> <br>
> if ($var(ratePerSec) > $var(limitPerSec) || $var(ratePerMin) ><br>
> $var(limitPerMin)) {<br>
>                         xlog("L_INFO", "CPS Limit on IP $si\n");<br>
>                         send_reply("503", "CPS Limit on IP $si");<br>
>                         exit;<br>
> }<br>
> <br>
> }<br>
> <br>
> Logs show hashes are created but *$var(ratePerSec/Min)* won't increment no<br>
> matter how many calls I place per second or minute:<br>
> <br>
> Jul  9 14:35:52 proxy /usr/local/sbin/kamailio[1484]: INFO: <script>:<br>
> var(rateHashSec)=65.39.XX.XX:sec:2018/07/09_14_35_52;<br>
> var(rateHashMin)=65.39.XX.XX:min:2018/07/09_14_35_00<br>
> Jul  9 14:35:52 proxy /usr/local/sbin/kamailio[1484]: INFO: <script>:<br>
> var(ratePerSec)=0; var(ratePerMin)=0<br>
> <br>
> Much obliged.<br>
> --Sergiu<br>
<br>
> _______________________________________________<br>
> Kamailio (SER) - Users Mailing List<br>
> <a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
> <a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
<br>
<br>
-- <br>
Alex Balashov | Principal | Evariste Systems LLC<br>
<br>
Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free) <br>
Web: <a href="http://www.evaristesys.com/" rel="noreferrer" target="_blank">http://www.evaristesys.com/</a>, <a href="http://www.csrpswitch.com/" rel="noreferrer" target="_blank">http://www.csrpswitch.com/</a><br>
<br>
_______________________________________________<br>
Kamailio (SER) - Users Mailing List<br>
<a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote></div>