Skip to content

Kamailio metrics ​

When a SIP proxy such as Kamailio sits in front of FreeSWITCH, some of what happens to calls is invisible to FreeSWITCH: requests the proxy rejected itself, connections it holds, transactions waiting for an answer. With the Kamailio source switched on in the profile (one JSON-RPC URL per Kamailio — set up in Kamailio), every run — load tests and PBX watches — records Kamailio's own counters and shows them in a Kamailio card on the run page. The source is optional and read-only.

First step: switch the Kamailio source on in the profile (setup); every following run gets the Kamailio card.

Kamailio card of a run
The Kamailio card: requests, own rejections, connections, shared memory, restarts and coverage, summed over all Kamailios.

What is polled ​

Each Kamailio's JSON-RPC endpoint (HTTP, xhttp + jsonrpcs modules) is asked for:

MethodUsed for
core.uptimeuptime and start time — restart detection
stats.fetch allevery statistic Kamailio has (core, tm/tmx, sl, tcp, shmem, websocket, any module)
tls.infoopen and maximum TLS connections (optional; if it fails, retried after 20 polls)
core.versionthe version shown per Kamailio (on connect and after a restart)
SettingDefault
kamailio.poll_interval (while a run is active)5 s
kamailio.idle_poll_interval (otherwise, for the Dashboard)30 s
kamailio.timeout (per request)3 s

When a run starts, every Kamailio is polled at once. All Kamailios are polled in parallel and summed (shared memory: the highest of them). A poll older than twice the poll interval plus 2 s counts as no data for that second.

Counters, deltas and rates ​

Kamailio's statistics are of two kinds:

  • Cumulative counters (requests received, replies sent…) count up since Kamailio started. PBXsight turns them into deltas between two polls, and rates = delta ÷ seconds between the polls.
  • Levels (shared memory, open connections, active transactions, TLS write queue…) are current values, used as they are. A statistic is treated as a level when its name says so (shmem.*, pkmem.*, tls.*, or containing current, active_, inuse_, registered_users, early_dialogs, opened_connections, max_connections, queued, queue_size; of the websocket.* statistics only the *current_connections and *max_concurrent_connections ones). A counter that went down isn't treated as a counter for that interval (no delta).

The run's totals are the sums of the deltas of every poll interval that lies inside the run. The per-second chart values are the rates of the latest poll interval, so a spike shorter than the poll interval is averaged over it.

The tester's own polls are subtracted ​

Kamailio counts every JSON-RPC request like a SIP request: a received request, on a new TCP connection, answered by Kamailio itself with a 200 (or a 403/4xx if refused). Left in, PBXsight's own polling would show up as SIP traffic. The collector counts its own requests and removes them from core.rcv_requests, sl.sent_replies, tcp.established, tcp.passive_open, and from sl.200_replies/sl.2xx_replies (answered) or sl.403_replies/sl.4xx_replies/sl.sent_err_replies (refused). The summary keeps the number as own polls.

Restarts ​

A restart is detected when Kamailio's start time changed or its uptime went back. The interval across the restart gives no delta (its counts are lost — at most one poll interval); totals continue from the next poll. Each restart is counted with its time in the run.

The card, number by number ​

TileMeaningSource statistic
RequestsSIP requests Kamailio received, all methods (own polls excluded), the average per second, and transactions: requests handled statefully (t_relay)core.rcv_requests, tmx.UAS_transactions
Rejected by Kamailioreplies Kamailio sent itself with 4xx, 5xx or 6xx instead of forwarding — a routing rule's 403, 404, 483 too many hops, 503 overload / no destination — and their share of the requestssl.4xx_replies, sl.5xx_replies, sl.6xx_replies (or the sum of sl.<code>_replies)
Drops · errorsmessages dropped (a drop in the routing script, or invalid) · errors incl. malformed messagescore.drop_requests + core.drop_replies · core.err_requests + core.err_replies + core.bad_msg_hdr + core.bad_URIs_rcvd
Connections peakmost open TCP connections in any second (TLS and WebSocket are part of TCP), with the TLS and WS peaks; a TLS write queue warning when data waited to be writtentcp.current_opened_connections, tls.info, websocket.ws_current_connections, tls.clear_text_write_queued_bytes
WebSocketonly with Kamailio's websocket module: connections opened (successful handshakes) · failed (failed handshakes + failed connections) and their % of the attempts, closed by Kamailio and by the clients, and the peak open at oncesee WebSocket
Shared memoryhighest use of any Kamailio, % of its total, and first → last value of the runshmem.real_used_size (else used_size) ÷ shmem.total_size
Restartsrestarts during the run and whenuptime / start time
Data coverageseconds with data from at least one Kamailio, % of the run—

Below: charts of Traffic (received/s, transactions/s, own 4xx/s, own 5xx/s, drops/s), Connections & memory and — with the websocket module — WebSocket (connections open, opened/s, closed/s, failed/s); a table per Kamailio (version, data coverage, restarts, last error); Kamailio's own replies by code — a 200 there is Kamailio answering something itself, e.g. keepalive OPTIONS, not a rejection; requests by method; replies received (from FreeSWITCH and phones, by class — FreeSWITCH's 401 challenges are normal 4xx here); and All counters that changed during the run (the 30 that changed most, any module) — to see what else your Kamailio reports.

Connections are not devices. Every device on TCP, TLS or WSS holds one connection; devices on UDP (many desk phones and DECT bases) hold none, and a DECT base registers all its handsets over one address. A sudden drop in connections means TCP/TLS/WSS devices were disconnected.

WebSocket ​

Web clients (browser apps on SIP over WSS) connect to Kamailio's websocket module, which reports its own statistics through stats.fetch (group websocket). PBXsight uses:

StatisticKindUsed as
ws_current_connectionslevelconnections open (chart, peak, Dashboard)
ws_max_concurrent_connectionslevel— (Kamailio's own high-water mark; in All counters only)
ws_successful_handshakescounteropened
ws_failed_handshakescounterfailed
ws_failed_connectionscounterfailed
ws_local_closed_connectionscounterclosed by Kamailio
ws_remote_closed_connectionscounterclosed by the clients
ws_received_frames, ws_transmitted_framescounter— (All counters only)

The ws_sip_* / ws_msrp_* copies per subprotocol appear only in All counters; the tile counts all subprotocols together. Failed % = failed ÷ (opened + failed) × 100. ws_failed_connections can count connections that failed after their handshake, so it is a failure share of the connection attempts rather than strictly a handshake rejection rate. The Dashboard shows failed/s per Kamailio, and the hints say Kamailio refused WebSocket connections at 3 or more failures and 1 % or more: look at the TLS certificate / SNI on the WSS listener, the WebSocket upgrade route (ws_handle_handshake, Origin / path checks) and connection limits (tcp_max_connections, the tls module's max_connections, tcp_children); for a web registration storm, compare with the Web clients card's storm failures. Without the module (no websocket.* statistics) there is no tile, no chart and no criterion value — the card looks as before.

Read the WebSocket chart ​

The Kamailio card's WebSocket chart has the connections open as a line (Kamailio's ws_current_connections, the highest value per chart bucket) and opened/s, closed/s and failed/s as rates. Four things to know before you compare it with the tester's Web clients chart of a web registration run:

  • Opened/s is a rate, not a count. A storm of 500 reconnects shows as a spike of opened/s spread over the poll interval (5 s by default, so the lines move in steps), not as 500 on the axis. The totals are in the WebSocket tile.
  • Right after a storm Kamailio can count old and new connections together for one poll: the closed connections are not cleaned up yet while the new ones are already open. Open can then briefly exceed the number of clients (e.g. 883 for 500 clients) and settles at the next poll. That is Kamailio's bookkeeping, not extra clients.
  • Connections opened before the run's measured part are not in the run. In a call load, find the limit or busy hour with web clients, the phones register (and open their WebSockets) while the run is still starting; those handshakes happen before the run's counters start, so opened covers only reconnects during the run. In a web registration run the ramp is part of the run.
  • The tester's Web clients chart shows open as the lowest value in each second (so a fast storm's dip stays visible), Kamailio's chart its polled level: the dip looks shallower or is missed between two polls.

Both views together tell you who closed the connections (Kamailio's closed by Kamailio vs by the clients) and whether Kamailio refused any (failed) while the clients came back.

Kamailio card of a web-client registration run with the WebSocket tile
The Kamailio card of a web-client run: the WebSocket tile (opened, failed, closed, peak open) and its chart.

Open transactions ​

tmx.active_transactions (the per-step Kamailio open tx column of the Steps card) is the most useful level during a load test: transactions stay open while Kamailio waits for the next hop. Rising open transactions with a flat request rate mean Kamailio is waiting — on FreeSWITCH, or on rtpengine's offer. The hints use it to tell "Kamailio is waiting for FreeSWITCH" from "Kamailio itself is slow".

Per window / step PBXsight keeps: requests, own 4xx, own 5xx, drops, peak TCP connections, peak open transactions, highest shared memory and restarts — and, with the websocket module, WebSocket failures and peak WebSocket connections.

Criteria ​

All optional, off by default, for any run type:

CheckKeyForm suggestsValue
Kamailio restartsmax_kamailio_restarts0restarts of any Kamailio seen during the run
Kamailio shared memorymax_kamailio_shm_pct80 %the highest shared-memory use of any Kamailio at any second (note: start → end)
Kamailio WebSocket failuresmax_kamailio_ws_failed_pct1 %failed WebSocket handshakes + failed connections, % of the attempts (note: the counts)

Skipped when the source is off or had no data; the WebSocket check also when Kamailio reported no WebSocket stats (websocket module not loaded) or there were fewer than 10 connection attempts. The always-on watch doesn't apply these Kamailio criteria (its counters include load tests). See Pass / fail verdict.

Worked example: reading the card

A registration test with 1 000 extensions over TLS: Requests 2 060, 2 050 transactions; Rejected by Kamailio 12 (12 × 403, 0.58 % of requests); Connections peak 1 004 TCP · TLS 1 004; shared memory 11.2 % → 11.9 %. The 403s were sent by Kamailio itself — FreeSWITCH never saw those REGISTERs, so they are missing from FreeSWITCH's numbers; look at the routing script's rules (e.g. an IP allow-list) and the Kamailio log for who sent them.

Limits of counters ​

  • Counters say how many, not who: a burst of 403s shows, but not which user or address was rejected. Use the Kamailio log for that.
  • Rates are per poll interval (5 s by default during runs): short spikes are averaged.
  • Meaning depends on your routing script — e.g. whether Kamailio or FreeSWITCH answers OPTIONS or challenges REGISTERs, and whether requests are relayed statefully (t_relay, counted as transactions) or statelessly (forward(), counted as forwarded).
  • Counts of a poll interval that straddles a restart are lost.

PBXsight — load testing and monitoring for FreeSWITCH PBXes. Only test systems you own or may test.