Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Connection Diagnostics

naia exposes connection health metrics via ConnectionStats. These are computed on demand from internal ring buffers and cover the full picture of link quality.


Available metrics

FieldDescription
rtt_msRound-trip time EWMA in milliseconds
rtt_p50_msRTT 50th-percentile from the last 32 samples
rtt_p99_msRTT 99th-percentile from the last 32 samples
jitter_msEWMA of half the absolute RTT deviation
packet_loss_pctFraction of sent packets unacknowledged in the last 64-packet window (0.01.0)
kbps_sentRolling-average outgoing bandwidth in kilobits per second
kbps_recvRolling-average incoming bandwidth in kilobits per second

Sampling

#![allow(unused)]
fn main() {
// Server side — sample once per second (not every frame):
if let Some(stats) = server.connection_stats(&user_key) {
    // log or push to your metrics backend
}

// Client side:
let stats = client.connection_stats();
}

Warning: connection_stats performs a small sort for the percentile computation. Call it at most once per frame per connection — not inside a hot inner loop.


metrics and tracing integration

For production observability, naia ships optional feature-gated integration with the metrics and tracing ecosystems. Enable via the metrics feature flag:

# server/Cargo.toml
naia-bevy-server = { version = "0.25", features = ["metrics"] }

When metrics is enabled, naia emits counters and gauges compatible with any metrics-crate backend (Prometheus, StatsD, etc.). See the naia-metrics and naia-bevy-metrics crates for the full list of emitted metric names.


Interpreting the numbers

  • rtt_p99 > 300 ms — players on this connection will feel prediction corrections. Consider widening TickBufferSettings and deepening CommandHistory.
  • packet_loss_pct > 0.02 (2%) — entity updates may be delayed or arrive out of order. Test your rollback handler with LinkConditionerConfig::poor_condition().
  • kbps_sent near target_bytes_per_sec — the entity list is bandwidth-limited. Use priority gain to prioritize the most important entities; consider enabling zstd compression.