# `DalaDev.NetworkDiag`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/dala_dev/network_diag.ex#L1)

Network diagnostics for dala Elixir clusters.

Provides tools to diagnose connectivity issues, measure latency,
and verify EPMD health across cluster nodes.

## Examples

    # Ping a node
    {:ok, latency_ms} = DalaDev.NetworkDiag.ping_node(:"dala_qa@192.168.1.5")

    # Measure latency with multiple samples
    {:ok, stats} = DalaDev.NetworkDiag.measure_latency(node, samples: 100)

    # Check EPMD health
    :ok = DalaDev.NetworkDiag.check_epmd_health(node)

    # Trace distribution path
    {:ok, path} = DalaDev.NetworkDiag.trace_distribution(node)

# `latency_stats`

```elixir
@type latency_stats() :: %{
  min: integer(),
  max: integer(),
  avg: float(),
  median: float(),
  samples: integer()
}
```

# `node_ref`

```elixir
@type node_ref() :: node() | DalaDev.Device.t() | String.t()
```

# `check_epmd_health`

```elixir
@spec check_epmd_health(
  node_ref(),
  keyword()
) :: :ok | {:error, term()}
```

Check EPMD health on a node.

Verifies:
- EPMD is running
- Port 4369 is reachable
- Node can register/deregister

Returns `:ok` or `{:error, reason}`.

# `get_network_interfaces`

```elixir
@spec get_network_interfaces(
  node_ref(),
  keyword()
) :: {:ok, map()} | {:error, term()}
```

Get detailed network interface information for a node.

Returns IP addresses, interface names, and reachability.

# `measure_latency`

```elixir
@spec measure_latency(
  node_ref(),
  keyword()
) :: {:ok, latency_stats()} | {:error, term()}
```

Measure latency to a node with multiple samples.

Options:
- `:samples` - Number of ping samples (default: 10)
- `:timeout` - Timeout per sample in ms (default: 5_000)

Returns latency statistics.

# `ping_node`

```elixir
@spec ping_node(
  node_ref(),
  keyword()
) :: {:ok, integer()} | {:error, term()}
```

Ping a node to check connectivity.

Returns `{:ok, latency_ms}` on success, `{:error, reason}` on failure.

Options:
- `:timeout` - Timeout in ms (default: 5_000)

# `trace_distribution`

```elixir
@spec trace_distribution(
  node_ref(),
  keyword()
) :: {:ok, [String.t()]} | {:error, term()}
```

Trace the distribution path to a node.

Shows the network path Elixir distribution takes to reach the node.

Returns a list of hops or error.

---

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