Issue files (.scratch/issues/20-29): retrospective specs for all work done in the current sprint — hardening, route-timeout, start-layer protocol, heartbeat stats, availability map, rolling RPM, smart assignment, throughput routing, routing tests, relay outbound client. ADRs (docs/adr/0011-0014): 0011 — Auto-shard from memory budget and tracker network assignment 0012 — X-Meshnet-Start-Layer overlapping shard execution protocol 0013 — Rolling RPM statistics, smart assignment scoring, throughput routing 0014 — Relay outbound client for NAT/internet pipeline hops prd.json: US-020 through US-029 added, all marked done. ralph_progress.py now shows 29/29 complete (100%). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1.3 KiB
1.3 KiB
US-025 — Model usage statistics: rolling RPM windows + SQLite persistence
Status: done Priority: Medium Stage: Implemented
Context
Trackers need per-model request-rate data to drive smart shard assignment (US-026) and to give operators visibility into what the network is actually serving. Stats must survive tracker restarts and should be shareable across a tracker cluster.
Design
_RollingCounter: circular-bucket counter, epoch-indexed, stale buckets auto-reset- Three windows: 60×1-min buckets (last hour), 24×1-hr (last day), 30×1-day (last month)
_StatsCollector:record_request(),get_local_rpms(),merge_peer_rpms(),get_combined_stats()- SQLite persistence via
--stats-db PATH - Gossip: each tracker keeps its own slice; merge is additive (not averaged)
Acceptance criteria
_RollingCounterpasses unit tests (record, rpm, stale bucket reset)_StatsCollectoraccumulates and merges peer slices additively- SQLite round-trip: buckets saved and restored across restart
GET /v1/statsreturns combined stats JSONPOST /v1/stats/gossipaccepts peer slice and merges_handle_proxy_chatcallsstats.record_request()after model is resolved--stats-db PATHCLI flag added to tracker- 6 unit tests pass;
python -m pytestpasses