Skip to main content

Crate moq_stats

Crate moq_stats 

Source
Expand description

Publish and consume MoQ traffic stats.

moq-net collects per-session traffic counters in a stats::Registry; this crate turns that registry into MoQ broadcasts and back:

  • Producer drains a registry on an interval and publishes the counters as JSON tracks on an origin.
  • Consumer subscribes to one published stats broadcast and yields typed frames, for aggregators, dashboards, and billing meters.
  • aggregate::Consumer folds a whole group’s per-node broadcasts into one merged view, so a downstream sees a project’s total live traffic as if it came from a single node.

§Wire format

A Producer publishes one broadcast per node at <prefix>/node/<node> (default prefix .stats), or one per group of leading broadcast-path segments at <prefix>/<group>/node/<node>; parse announce paths back with parse_node_path. Each Tier carries publisher.json, subscriber.json, and sessions.json tracks of cumulative Traffic and Presence counters, plus .json.z siblings encoded with moq_json::snapshot; compute names with traffic_track / sessions_track. The full contract (paths, tracks, both encodings, and counter semantics) is at https://doc.moq.dev/concept/stats.

Re-exports§

pub use consume::Consumer;
pub use produce::Producer;

Modules§

aggregate
The aggregating half: fold a group’s per-node stats broadcasts into one view.
consume
The consuming half: typed readers over one published stats broadcast.
produce
The publishing half: drain a Registry on an interval into stats tracks.

Structs§

Handle
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. Tier-scoped wrapper around Registry. What crate::Client::with_stats and crate::Server::with_stats accept. Cheap to clone.
NodePath
A parsed stats broadcast path: <prefix>[/<group>]/node[/<node>]. See parse_node_path.
Presence
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. Connected-session presence for one slice (an auth root on a tier, or any sum of such slices): cumulative connects and disconnects. `sessions_started
Registry
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. Counter collection registry. Cheap to clone (Arc inside for the shared state). One instance per relay; sessions get tier-scoped handles via Registry::tier. The moq-stats crate drains it with Registry::report to publish the counters as MoQ broadcasts.
Tier
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. Traffic-class label that selects which counter set a session’s bumps record in, so a single Registry can split customer-facing, cluster-peer, regional, etc. traffic. Each tracked broadcast keeps a per-tier counter set on both its publisher and subscriber sides.
Traffic
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. A cumulative traffic counter readout for one slice (a broadcast on a (tier, role), or any sum of such slices).

Enums§

Error
Errors produced while publishing or consuming stats.
Role
Counter collection, re-exported from moq_net::stats so stats consumers can depend on this crate alone. Publisher (egress) vs subscriber (ingress) side of a broadcast, used as a label on a Snapshot traffic row. The internal bump paths track the side statically, so this only surfaces on the aggregate read side.

Constants§

COMPRESSED_SUFFIX
Suffix appended to a plain track name for its compressed sibling.

Functions§

parse_node_path
Parse a stats broadcast announce path published under prefix with the given grouping depth, splitting it into its group and node parts.
sessions_track
The sessions track name for a tier: sessions.json on the default tier, <tier>/sessions.json on a named one, plus COMPRESSED_SUFFIX when compressed.
traffic_track
The traffic track name for a tier and role: <role>.json at the prefix root on the default tier (publisher.json / subscriber.json), <tier>/<role>.json on a named one, plus COMPRESSED_SUFFIX when compressed.

Type Aliases§

Result
A Result using this crate’s Error.
SessionsFrame
One frame off a sessions track: connect/disconnect gauges keyed by auth root.
TrafficFrame
One frame off a traffic track: cumulative counters keyed by broadcast path.