Appearance
Kamailio
Many FreeSWITCH installations sit behind a SIP proxy — often Kamailio, with rtpengine relaying the media. PBXsight treats the proxy as the SIP entry point: it sends every REGISTER and INVITE there, and FreeSWITCH sees the tests through it. Kamailio is optional, and any proxy or SBC works as the entry point; FreeSWITCH can also be tested directly.
This page has two parts: what to check on the proxy so a load test isn't blocked or distorted (applies to any proxy, with Kamailio examples), and the optional read-only JSON-RPC access that gives PBXsight Kamailio's own counters.
First step: check the proxy's flood protection lets the tester through (below); the metrics part can wait.
Let the tester past flood protection
A load test looks like a flood from one IP address: hundreds of REGISTERs or INVITEs per second from the tester. If Kamailio uses pike, an htable-based IP ban, or fail2ban on its host, it will start dropping or banning the tester mid-run. Whitelist the tester's address (as the proxy sees it — the public address if there's NAT) before the check:
# kamailio.cfg, request_route
if (!($si == "203.0.113.10")) { # the tester (or an address group via the permissions module)
if (!pike_check_req()) { xlog("L_ALERT", "pike blocking $rm from $si\n"); exit; }
}Symptoms of a block: responses stop in the middle of a run, timeouts grow with the rate, and the next run gets no answers at all for a while (until the ban expires). The run's SIP responses show timeout instead of codes.
Pass the test headers through
FreeSWITCH recognises test traffic by:
X-PBXsight-Run: <run id>on every REGISTER and INVITE (andX-PBXsight-Call: <Call-ID>on INVITEs, used for the per-call setup breakdown and to pair both legs' audio),User-Agent: pbxsight/<run id>,- the extension + domain of the uploaded extension set.
Kamailio passes all of them through unless the routing script removes X- headers or rewrites the User-Agent. If yours strips X- headers (some configs do towards the PBX), exempt the two X-PBXsight-* headers. Without them, PBX-side counts still match by User-Agent and extension + domain, but the per-call "before FreeSWITCH" join falls back to the SIP Call-ID, which a B2BUA-style proxy may change.
Raise TLS and connection limits
If the proxy only listens on TLS (common for internet-facing setups), set the profile's Transport to TLS and Port to 5061. The tester does not verify the proxy's certificate and sends no client certificate.
Over TCP and TLS every test extension holds its own connection for the whole run, like a phone: a test with 1000 extensions means 1000 TLS connections on the proxy, on top of the real phones. Kamailio's defaults (tcp_max_connections and tls_max_connections, 2048 each) can be reached by a big test; raise them, and the open-files limit of the Kamailio process, if you plan more extensions than that. Also check tcp_connection_lifetime: the tester sends a CRLF keepalive every 25 s on each connection, and re-registers well before the expiry.
Match rtpengine's SRTP setting
Many setups make rtpengine offer RTP/SAVP (SRTP) to TLS clients and drop plain RTP from them. A call test with media RTP then gets answered, but FreeSWITCH receives no audio and the calls may end with MEDIA_TIMEOUT. Use media mode SRTP in the profile: the tester's media engine speaks SDES-SRTP (a=crypto, AES_CM_128_HMAC_SHA1_80). The run's Media path card warns when the answer's media profile differs from the offer.
Alternatively, skip the forced SRTP for the tester in Kamailio, e.g. when $ua =~ "^pbxsight/".
Test several proxies behind one host name (HA)
The profile's Host may be a host name with several A records, e.g. two stateless Kamailios. A run always talks to one address:
- when a test starts, PBXsight resolves the name (IPv4);
- it picks one address at random — or the one you chose in the New test form;
- every request of the run goes there, and phones stay on the node they registered through;
- the run records it (e.g.
sip.example.com:5061 → 10.0.0.2), so you can tell which node a result belongs to.
The Dashboard's Target card shows what the name currently resolves to. To compare nodes, run the same test pinned to each address. GET /api/pbx/targets returns the resolution; POST /api/tests accepts target_ip.
Give PBXsight read-only metrics over JSON-RPC
Optional. With it, every run gets a Kamailio card (requests by method, replies Kamailio sent itself, drops, connections, shared memory, restarts) and the Dashboard shows one row per Kamailio. PBXsight polls each Kamailio with four read-only JSON-RPC methods — stats.fetch all, core.uptime, core.version, tls.info — over HTTP, and sums the nodes.
JSON-RPC is full admin access to Kamailio (core.kill, changing state, …), so expose it only to the tester's network and only for read-only methods. Kamailio configs differ a lot; adapt these steps to yours and apply them on every Kamailio you want to see.
1. Load the modules
xhttp (HTTP on Kamailio's TCP listeners) and jsonrpcs (the RPC commands). Load xhttp beforejsonrpcs and enable the HTTP transport explicitly; otherwise jsonrpc_dispatch() may log jsonrpc over http not initialized - check transport param and never reply:
loadmodule "xhttp.so"
loadmodule "jsonrpcs.so"
modparam("jsonrpcs", "transport", 7) # HTTP + FIFO + datagram: keeps kamcmd / kamcli workingipops is needed for is_in_subnet() below (often loaded already).
2. Add a TCP listener the tester can reach
xhttp answers HTTP on Kamailio's TCP listeners (listen=tcp:…). Use one on a private IP or the VPN; don't expose RPC on a public interface.
3. Add a guarded route
An xhttp event route hands /RPC to a route that checks the source network and the method:
# if your config already has event_route[xhttp:request] (e.g. for WebSockets),
# add the route() call as its FIRST line; otherwise create it with these lines
event_route[xhttp:request] {
route(PBXSIGHT_RPC);
# … your existing xhttp handling (WebSocket upgrade etc.) …
xhttp_reply("404", "Not Found", "", "");
}
# top level (not inside another route)
route[PBXSIGHT_RPC] {
if (!($hu =~ "^/RPC")) { return; }
set_reply_close(); # close the HTTP connection after the reply
set_reply_no_connect();
if (!is_in_subnet("$si", "10.8.0.0/24")) { # the tester's network
xlog("L_WARN", "pbxsight: RPC refused from $si\n");
xhttp_reply("403", "Forbidden", "", "");
exit;
}
if ($rm != "POST" || !($rb =~ "method[^,}]*(core[.]version|core[.]uptime|stats[.]fetch|stats[.]get_statistics|tls[.]info)")) {
xlog("L_WARN", "pbxsight: RPC method not allowed from $si\n");
xhttp_reply("403", "Forbidden", "", "");
exit;
}
jsonrpc_dispatch();
exit;
}Calling the route first keeps the polls out of any per-request logging (a poll every few seconds would otherwise add thousands of log lines a day). To test from the Kamailio host itself, add its own address to the allowed sources.
4. Check, then restart
sh
kamailio -c -f /etc/kamailio/kamailio.cfg # prints file, line and column of errorsA restart drops that Kamailio's TCP/TLS connections; phones re-register.
5. Test from the tester's machine
sh
curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"stats.fetch","params":["all"],"id":1}' \
http://10.0.0.5:5060/RPC | headExpected: a JSON object of counters ("core.rcv_requests": "…", …). An unlisted method (e.g. core.ps) and a request from outside the allowed network must get 403. wget works where there's no curl.
6. Add Kamailio to the PBX profile
In the profile's Kamailio section tick optional source and add one JSON-RPC URL per Kamailio (http://10.0.0.5:5060/RPC; https:// works too). Polls run every 5 s during runs and every 30 s otherwise (Poll (runs) / Poll (idle)), with a 3 s Timeout. See PBX profiles.
Avoid common pitfalls
- Kamailio has no
!~operator: write!($x =~ "…"). - Avoid
\.and\"escapes in regex strings; use[.]. - A
route[...]block can't be defined inside another route. - Counters are cumulative since Kamailio started and reset on restart; PBXsight uses the difference between polls and detects restarts from the uptime.
- Kamailio counts PBXsight's own JSON-RPC polls as received requests; PBXsight subtracts them, so the numbers on the card are SIP traffic only.
- Counters say how many, not who: a burst of rejected REGISTERs is visible, the user or IP isn't.