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