Passive per-allocation QoS and metering exporter for TURN relay frames.
What problem this solves
Operators need usage and quality signals (bytes, packets, loss, jitter) per TURN allocation without rewriting media. This plugin counts every frame, tracks RTP SSRCs when payloads look like RTP, and emits Telemetry samples on a timer plus a final snapshot at allocation close.
Implements Xirsys.XTurn.Plugin in :passive mode (dedicated process;
safe for Process.send_after/3).
Telemetry events:
[:xturn, :metrics, :allocation, :sample]- periodic flush[:xturn, :metrics, :allocation, :stop]- final snapshot fromhandle_close/2
Options
:flush_ms- sample interval in milliseconds (default5000):clock_rates- payload type to clock rate map (default%{0 => 8000, 8 => 8000}):usage_log- optional path; one JSON line appended per allocation on stop:match- allocation filter passed toattach?/2
RFCs
Examples
iex> Xirsys.XTurn.Plugin.Metrics.mode()
:passive
iex> Xirsys.XTurn.Plugin.Metrics.hooks()
[:egress, :ingress]
iex> alloc = %Xirsys.XTurn.Plugin.Allocation{username: "alice"}
iex> Xirsys.XTurn.Plugin.Metrics.attach?(alloc, match: [username: "alice"])
true
Summary
Functions
Attach when :match filters are empty or all listed allocation fields match.
Emit the final Telemetry stop event and optional usage-log line.
Update byte/packet/SSRC stats for this frame; return new state.
Handle the periodic sample timer (:xturn_metrics_sample).
Meters both directions.
Start counters and schedule the first sample flush.
Always :passive (per-allocation instance process).
Functions
Attach when :match filters are empty or all listed allocation fields match.
Emit the final Telemetry stop event and optional usage-log line.
Update byte/packet/SSRC stats for this frame; return new state.
Handle the periodic sample timer (:xturn_metrics_sample).
Emits [:xturn, :metrics, :allocation, :sample] Telemetry and reschedules
the next flush after flush_ms.
Meters both directions.
Start counters and schedule the first sample flush.
Always :passive (per-allocation instance process).