Xirsys.Sockets.Telemetry (xturn_sockets v2.2.0)

View Source

Optional :telemetry events under [:xturn_sockets, event].

emit/3 no-ops when config :xturn_sockets, telemetry_enabled: false, and swallows errors if :telemetry is not started. attach_handlers/0 installs library log/counter handlers; callers may attach their own instead.

Summary

Functions

Attaches library log and counter handlers for [:xturn_sockets, ...] events.

Detaches every handler whose id starts with "xturn_sockets_".

Executes [:xturn_sockets, event_name] when telemetry is enabled.

Snapshot of process-local counters kept in :persistent_term.

Coarse health atom from current counters.

Erases this module's :persistent_term counters.

Functions

attach_handlers()

Attaches library log and counter handlers for [:xturn_sockets, ...] events.

Idempotent per handler id. Safe to call from a host application's start.

detach_handlers()

Detaches every handler whose id starts with "xturn_sockets_".

emit(event_name, measurements, metadata)

@spec emit(atom(), map(), map()) :: :ok

Executes [:xturn_sockets, event_name] when telemetry is enabled.

Parameters

  • event_name - last segment of the event name (atom)

  • measurements - numeric map (%{bytes: n}, ...)

  • metadata - context map (%{ip: tuple, port: n}, ...)

    iex> Xirsys.Sockets.Telemetry.emit(:doctest_event, %{count: 1}, %{}) :ok

get_metrics()

Snapshot of process-local counters kept in :persistent_term.

Keys include connection counts, bytes sent/received, rate-limit hits, and SSL handshake totals. last_updated is System.system_time(:second).

Takes no parameters; counters are global to the VM via :persistent_term.

health_status()

Coarse health atom from current counters.

Returns :healthy, :degraded (SSL error rate), :unhealthy (send error rate), or :under_attack (rate-limit hits).

Takes no parameters; reads counters via get_metrics/0.

reset_counters()

Erases this module's :persistent_term counters.

iex> Xirsys.Sockets.Telemetry.reset_counters()
:ok