ExTorch.Metrics (extorch v0.4.0)

Copy Markdown

ETS-backed metrics collection for ExTorch model serving.

Automatically attaches to telemetry events emitted by ExTorch.JIT.Server and maintains per-model inference statistics.

Setup

Call ExTorch.Metrics.setup/0 in your application start to begin collecting:

def start(_type, _args) do
  ExTorch.Metrics.setup()
  # ...
end

Querying Metrics

ExTorch.Metrics.get("model.pt")
# => %{inference_count: 150, error_count: 2, total_duration_ms: 4523.1,
#      min_duration_ms: 12.3, max_duration_ms: 89.2, last_inference_at: ~U[...]}

ExTorch.Metrics.all()
# => [{"model.pt", %{...}}, {"other.pt", %{...}}]

Summary

Functions

Get metrics for all tracked models.

Get metrics for a specific model path.

Reset metrics for a specific model path.

Reset all metrics.

Initialize the metrics ETS table and attach telemetry handlers.

Detach telemetry handlers. Metrics table remains intact.

Functions

all()

@spec all() :: [{String.t(), map()}]

Get metrics for all tracked models.

Returns a list of {path, metrics} tuples.

get(path)

@spec get(String.t()) :: map() | nil

Get metrics for a specific model path.

Returns a map of metrics or nil if no data exists.

reset(path)

@spec reset(String.t()) :: :ok

Reset metrics for a specific model path.

reset_all()

@spec reset_all() :: :ok

Reset all metrics.

setup()

@spec setup() :: :ok

Initialize the metrics ETS table and attach telemetry handlers.

Safe to call multiple times -- will not reset existing data.

teardown()

@spec teardown() :: :ok | {:error, :not_found}

Detach telemetry handlers. Metrics table remains intact.