I have not until now that you recommended it, looks much simpler indeed, thanks.

Although, so far I can't seem to hit a pipe limit. If I watch pl.stats, no matter what timer_interval I set, the counter increases to 1 upon a call then back to 0 the next second.

root@proxy:/# watch -n 1 -d kamcmd pl.stats
PIPE: id=65.39.XX.XX load=0 counter=0

Say I wanted 1 call per minute pipe, what would be the 'timer_interval' and pl_check limit?

On Mon, Jul 9, 2018 at 2:47 PM Alex Balashov <abalashov@evaristesys.com> wrote:
Have you considered using pipelimit for this? It's as simple as:

   if(!pl_check("$avp(customer_id)", "TAILDROP", "$avp(cps_limit)")) {
       pl_drop();
       exit;
   }

There was a time when that wasn't possible because pipes couldn't easily
be created dynamically for a given customer ID or whatever, and htable
was the preferred vehicle for that. That has changed, and nowadays it's
a lot simpler. :-)

-- Alex

On Mon, Jul 09, 2018 at 02:41:44PM -0400, Sergiu Pojoga wrote:

> Hi folks,
>
> Trying to implement CPS throttling based on this
> <https://lists.kamailio.org/pipermail/sr-users/2013-September/079713.html>article,
> having some trouble.
>
> modparam("htable", "htable", "rhs=>size=32;initval=0;autoexpire=300;"
> modparam("htable", "htable", "rhm=>size=32;initval=0;autoexpire=1800;")
>
> route[CPS] {
> $var(rateHashSec) = $si+":sec:"+$timef(%Y/%m/%d_%H_%M_%S);
> $var(rateHashMin) = $si+":min:"+$timef(%Y/%m/%d_%H_%M_00);
> xlog("L_INFO", "var(rateHashSec)=$var(rateHashSec);
> var(rateHashMin)=$var(rateHashMin)\n");
> $var(ratePerSec) = $shtinc(rhs=>$var(rateHashSec));
> $var(ratePerMin) = $shtinc(rhm=>$var(rateHashMin));
> xlog("L_INFO", "var(ratePerSec)=$var(ratePerSec);
> var(ratePerMin)=$var(ratePerMin)\n");
> $var(limitPerSec) = 1;
> $var(limitPerMin) = 1;
>
> if ($var(ratePerSec) > $var(limitPerSec) || $var(ratePerMin) >
> $var(limitPerMin)) {
>                         xlog("L_INFO", "CPS Limit on IP $si\n");
>                         send_reply("503", "CPS Limit on IP $si");
>                         exit;
> }
>
> }
>
> Logs show hashes are created but *$var(ratePerSec/Min)* won't increment no
> matter how many calls I place per second or minute:
>
> Jul  9 14:35:52 proxy /usr/local/sbin/kamailio[1484]: INFO: <script>:
> var(rateHashSec)=65.39.XX.XX:sec:2018/07/09_14_35_52;
> var(rateHashMin)=65.39.XX.XX:min:2018/07/09_14_35_00
> Jul  9 14:35:52 proxy /usr/local/sbin/kamailio[1484]: INFO: <script>:
> var(ratePerSec)=0; var(ratePerMin)=0
>
> Much obliged.
> --Sergiu

> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users@lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


--
Alex Balashov | Principal | Evariste Systems LLC

Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
Web: http://www.evaristesys.com/, http://www.csrpswitch.com/

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users