mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2204] [CLOSED] Monitor: token usage and cost per day, priced, with the folder's models merged or shown one by one #3921
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3921
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2204
Author: @pipti
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:token-usage📝 Commits (3)
810df50Token usage and cost: per-day counts kept across starts, own prices42f258bToken usage and cost: bill the electricity the card's own power means36f47e5Token usage and cost: the card adds up the folder's models, or shows them one by one📊 Changes
8 files changed (+1001 additions, -4 deletions)
View changed files
📝
docs/DETAILS.md(+6 -0)📝
serve/server.py(+94 -3)📝
serve/telemetry.py(+13 -0)➕
serve/test_usage.py(+368 -0)➕
serve/usage.py(+294 -0)📝
serve/web/app.css(+11 -0)📝
serve/web/app.js(+146 -1)📝
serve/web/index.html(+69 -0)📄 Description
Issue: Resolves #900
Summary
The Monitor gains a Token usage and cost card. It keeps, per day, what each request used (prompt, reused, written tokens) and what the machine actually drew for it (watt-hours, folded in from the Power card's own sampler), so the figures survive a restart and describe real days rather than one sitting. Everything is priced at your own rates, set in About > Token pricing.
A run folder normally holds the usage file of every model one has run. The card adds them all up by default; the one choice Merged / By model — on the card's own title bar and in About > Settings — shows them one by one instead, both as a line per model and as one row per model and day in the per-day list.
Three commits, one feature. Nothing in the engine, the request path or any default changes.
What changed
UsageStorekeeps the per-day counts instrata-<model>.usage.jsonbeside the run config (tokens, watt-hours, seconds sampled) and prices them:DEFAULT_PRICINGis CNY 2 / 0.4 / 8 per million tokens (input / cached input / output), 0.55 per kWh, 100 W for the rest of the box — all settable, kept instrata-<model>.pricing.json.read_days()is the one reader of a usage file,days_view()the one builder of the card's rows (today, the last 14 days newest first, the all-time sum, each priced), andsummed()adds several models' days up.ModelsUsagenames each model after themodel_nameof the run config beside its file (the file's stem when there is none; two configs of one model are one model), and reads the other files at most once per poll, keyed by mtime and size. A file that is missing or half written reads as the days it holds.Service.usage_view()is what GET /usage, POST /pricing and the usage block of GET /metrics answer: the folder merged, plusmodelsfor the per-model view, every model priced with this server's prices. The running model's counts come from the live store rather than its file, so the seconds the sampler holds in memory are not lost; the other models come from disk, which their own server saves everySAVE_EVERY_S.start_telemetry()points the sampler's newon_sample(sample, dt)atService._sample_power, which foldsgpu_powerinto the store and splits the busy share atGPU_BUSY_PCT(the same linegpu_busy()draws). A server started without a run config keeps the numbers in memory only, as before.on_sample(sample, dt), called with the time the reading actually covers; a hook that raises can never end the sampler thread.app.cssgrew.seg--2(two choices) and.seg--sm(the card's small one). A server that sends no per-model view keeps the merged card, as before.Extra Notes
other_wattsover the seconds sampled. Happy to drop that commit or fold it into theirs if you would rather keep the two apart; the token card stands on its own without it.a0116b27(python -m unittest discover -s serve -t . -p "test_*.py") runs 743 tests, 12 skipped, and reports one error —serve.test_server.HipEnvGuard.test_only_for_hip, which doesPath(r"Z:\definitely\not\here").exists()inhip_env_guardand hits a disconnected network drive here (OSError: [WinError 1331]). A cleana0116b27checkout on this same machine fails the same test the same way (Ran 4 tests ... FAILED (errors=1)), so it is this PC'sZ:drive, not the change;serve.test_usageis 18 tests, all passing. On the machine here (RTX 5090 32 GB, Ultra 9 285K, 95 GB) a folder of three models came out as 1,937 requests / 157,142,730 prompt / 10.53 kWh / ¥142.25 merged, and 857 + 469 + 611 requests with ¥68.83 + ¥40.53 + ¥32.89 split per model, which is what the per-day files hold. Both views and both switches were clicked through in a headless browser against a mock engine, with no console errors.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.