# `ExTorch.Metrics`

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", %{...}}]

# `all`

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

Get metrics for all tracked models.

Returns a list of `{path, metrics}` tuples.

# `get`

```elixir
@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`

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

Reset metrics for a specific model path.

# `reset_all`

```elixir
@spec reset_all() :: :ok
```

Reset all metrics.

# `setup`

```elixir
@spec setup() :: :ok
```

Initialize the metrics ETS table and attach telemetry handlers.

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

# `teardown`

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

Detach telemetry handlers. Metrics table remains intact.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
