feat(us-025): model usage statistics with rolling RPM windows and SQLite persistence

Adds _RollingCounter and _StatsCollector to the tracker: three rolling windows
(hour=60×1min, day=24×1hr, month=30×1day) track request RPMs per model.
GET /v1/stats returns combined local + peer stats. POST /v1/stats/gossip lets
trackers push their local slice for additive merge in hive mode.
SQLite persistence via --stats-db flag; stats survive tracker restarts.
Records a stat for each proxied /v1/chat/completions request.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dobromir Popov
2026-06-30 13:37:33 +03:00
parent fff11c4d8b
commit d9110b623b
3 changed files with 333 additions and 0 deletions

View File

@@ -33,6 +33,12 @@ def main() -> None:
default=None,
help="This tracker's own URL as seen by peers (auto-derived from --host/--port if omitted)",
)
start_cmd.add_argument(
"--stats-db",
default=None,
metavar="PATH",
help="SQLite database path for persistent model usage statistics",
)
args = parser.parse_args()
@@ -44,6 +50,7 @@ def main() -> None:
heartbeat_timeout=args.heartbeat_timeout,
cluster_peers=cluster_peers or None,
cluster_self_url=args.self_url,
stats_db=getattr(args, "stats_db", None),
)
port = server.start()
print(f"meshnet-tracker listening on http://{args.host}:{port}", flush=True)