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:
Producerdrains a registry on an interval and publishes the counters as JSON tracks on an origin.Consumersubscribes to one published stats broadcast and yields typed frames, for aggregators, dashboards, and billing meters.aggregate::Consumerfolds 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; the node suffix disambiguates relays sharing a
cluster origin and may be multi-segment, e.g. sjc/1). A grouping depth
splits that into one broadcast per leading broadcast-path segments at
<prefix>/<group>/node/<node>, so a consumer can announce-scope to a
single group. Parse announce paths back with parse_node_path.
Traffic is bucketed by Tier (an arbitrary label chosen by business
logic: billing class, region, …). The default tier is unprefixed; a named
tier prefixes its track names with its label. Each broadcast carries, per
tier, a publisher (egress) and a subscriber (ingress) traffic track plus a
sessions track, each in a plain and a compressed flavor:
publisher.json/subscriber.json: each frame is a JSON object mapping broadcast path to a cumulativeTrafficsnapshot (TrafficFrame), one full snapshot per frame.sessions.json: each frame maps auth root to a cumulativePresencegauge (SessionsFrame), counting connected sessions regardless of data flow.<name>.json.z: a compressed sibling of each of the above, encoded withmoq_json::snapshot(group-scoped DEFLATE plus RFC 7396 merge-patch deltas). Since successive stats frames are nearly identical, this is a fraction of the plain track’s bytes; read it withConsumer(ormoq_jsondirectly), not as raw JSON frames.
Named-tier tracks (<tier>/publisher.json, …) are created the first time
traffic records under that label; default-tier tracks always exist and hold
{} while idle. Compute names with traffic_track / sessions_track.
An entry appears in a frame while it is live (an open counter still exceeds
its *_closed counterpart, so traffic could resume at any moment) or on
the tick its snapshot changed, then is dropped once fully closed. Counters
are cumulative and monotonic: a downstream aggregator computes rates from
successive snapshots, and a counter going backwards means the relay
restarted or the entry was garbage collected and re-created, so consumers
should treat a decrease as a fresh segment.
Modules§
- aggregate
- The aggregating half: fold a group’s per-node stats broadcasts into one view.
Structs§
- Consumer
- Reads one published stats broadcast (a
<prefix>/node/<node>announce), yielding typed frames per track. - Consumer
Config - Configuration for a
Consumer. Construct withConsumerConfig::newand chain thewith_*setters. - Handle
- Counter collection, re-exported from
moq_net::statsso stats consumers can depend on this crate alone. Tier-scoped wrapper aroundRegistry. Whatcrate::Client::with_statsandcrate::Server::with_statsaccept. Cheap to clone. - Node
Path - A parsed stats broadcast path:
<prefix>[/<group>]/node[/<node>]. Seeparse_node_path. - Presence
- Counter collection, re-exported from
moq_net::statsso 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 - sessions_closedis the current live session count. - Producer
- Publishes a
Registry’s counters as stats broadcasts. Cheap to clone. - Producer
Config - Settings for a
Producer. Construct withProducerConfig::newand chain thewith_*setters (e.g.ProducerConfig::new().with_origin(origin).with_prefix(".foo")), then hand it toProducer::new. - Registry
- Counter collection, re-exported from
moq_net::statsso stats consumers can depend on this crate alone. Counter collection registry. Cheap to clone (Arcinside for the shared state). One instance per relay; sessions get tier-scoped handles viaRegistry::tier. Themoq-statscrate drains it withRegistry::reportto publish the counters as MoQ broadcasts. - Sessions
Consumer - A typed reader over one sessions track; see
TrafficConsumer. - Tier
- Counter collection, re-exported from
moq_net::statsso stats consumers can depend on this crate alone. Traffic-class label that selects which counter set a session’s bumps record in, so a singleRegistrycan 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::statsso 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). - Traffic
Consumer - A typed reader over one traffic track. Yields the latest
TrafficFrame; intermediate frames a slow reader missed are collapsed, which is safe because the counters are cumulative.
Enums§
- Error
- Errors produced while publishing or consuming stats.
- Role
- Counter collection, re-exported from
moq_net::statsso stats consumers can depend on this crate alone. Publisher (egress) vs subscriber (ingress) side of a broadcast, used as a label on aSnapshottraffic 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
prefixwith the given groupingdepth, splitting it into its group and node parts. - sessions_
track - The sessions track name for a tier:
sessions.jsonon the default tier,<tier>/sessions.jsonon a named one, plusCOMPRESSED_SUFFIXwhencompressed. - traffic_
track - The traffic track name for a tier and role:
<role>.jsonat the prefix root on the default tier (publisher.json/subscriber.json),<tier>/<role>.jsonon a named one, plusCOMPRESSED_SUFFIXwhencompressed.
Type Aliases§
- Result
- A
Resultusing this crate’sError. - Sessions
Frame - One frame off a sessions track: connect/disconnect gauges keyed by auth root.
- Traffic
Frame - One frame off a traffic track: cumulative counters keyed by broadcast path.