mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1707] [CLOSED] Add GPU energy monitoring and cache-aware token cost analytics #3621
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#3621
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/1707
Author: @hash13
Created: 10/9/2026
Status: ❌ Closed
Base:
main← Head:telemetry-energy-token-costs📝 Commits (1)
18d1829feat(monitor): add GPU energy tracking and token cost analytics📊 Changes
3 files changed (+427 additions, -7 deletions)
View changed files
📝
serve/server.py(+105 -5)📝
serve/telemetry.py(+72 -1)📝
serve/web/app.js(+250 -1)📄 Description
Summary
This PR extends the existing web Monitor with GPU energy consumption and electricity cost tracking, including separate prefill and decode metrics.
The goal is to make energy efficiency and actual GPU operating costs of local LLM inference visible, rather than relying only on instantaneous GPU power or token throughput.
The existing Strata monitoring architecture provides a good foundation for this extension:
/metricsendpoint.The implementation builds on these components without introducing additional services, API endpoints or persistent storage.
Screenshots
Power card
Energy and token cost details
The screenshot shows GPU electricity costs per million tokens:
€0.0181 for fresh input,
€0.0097 for total input (including cached tokens), and
€0.3363 for output.
After 38 minutes, total GPU electricity costs are €0.0278, including idle consumption.
The effective all-in cost is €0.9957 per million output tokens, demonstrating how idle time affects actual operating costs.
1. GPU Energy Monitoring
The existing Power card now displays:
For NVIDIA GPUs, the implementation prefers NVML's cumulative hardware energy counter (
nvmlDeviceGetTotalEnergyConsumption).Unlike integrating periodically sampled power readings, the hardware counter reports accumulated energy directly. This improves accuracy for short inference operations and allows more reliable separation of prefill and decode energy.
If a hardware energy counter is unavailable, the monitor falls back to integrating sampled GPU power over time. Phase-specific cost metrics require a hardware energy counter.
Multiple GPUs are supported by aggregating their energy consumption.
All measurements are kept in memory and reset when the server restarts.
2. Energy and Token Cost Details
Clicking the Power card opens a live-updating detail dialog with four sections.
Overall
Shows GPU operating costs across the entire monitoring session:
All-in costs include total GPU energy consumed since monitoring started, including idle time and unassigned GPU activity.
This distinction matters when comparing local inference with hosted API pricing.
For example, if the server remains powered on for a long time before processing its first request, the initial all-in cost per million output tokens may appear relatively high.
As more tokens are generated, those accumulated idle costs are distributed across a larger number of output tokens.
This is intentional: GPUs consume electricity even when they are not processing requests. Considering only active inference would underestimate the actual GPU operating costs.
The all-in value therefore reflects the entire monitoring session, not just the most recent request or a theoretical model price.
Energy
Displays:
This distinguishes measured inference energy from the remaining GPU energy consumption.
Input / Prefill
Displays:
Cache reuse is explicitly considered.
Cached prompt tokens generally avoid repeated prefill computation. Treating every logical input token as newly processed would therefore produce misleading efficiency and cost comparisons.
The dialog distinguishes between logical API input and actual native prefill work, including additional prefill during internal generation continuations.
Output / Decode
Displays:
Native token accounting excludes artificially injected tokens from physical decode efficiency calculations.
This allows prefill and decode efficiency to be compared independently of the configured electricity price.
3. Measurement Accuracy
The implementation includes safeguards against misleading measurements:
Total GPU energy tracking continues independently of request-level attribution.
4. Web Monitor Integration
The existing Power card retains its compact layout:
Price formatting:
Formatting rules:
< 0.001The detail dialog uses four sections:
It reuses Strata's existing visual styling, including compact cards and an icon-based close button.
The dialog updates live through the existing Monitor refresh cycle, including while it remains open. No separate polling mechanism is required.
5. Configuration
Electricity pricing is optional and can be configured at the top level of the existing Strata JSON configuration.
Example:
In this example,
0.32represents 32 euro cents per kWh.The
electricityobject should be added alongside the existing top-level configuration fields.price_per_kwh: Electricity price in the currency's main unit per kWh, not centscurrency: ISO 4217 currency code, such asEUR,USDorGBPWithout a configured electricity price, energy consumption and efficiency remain available while monetary cost values are omitted.
6. Scope and Limitations
The implementation intentionally measures GPU energy consumption only, not total system electricity consumption.
The following are excluded:
Whole-system monitoring would require additional platform-specific implementations. Depending on the hardware and operating system, these may involve Linux RAPL, elevated permissions, additional utilities or external power meters.
To maintain portability and avoid introducing unnecessary privileges or security-sensitive dependencies, whole-system measurement is deliberately outside the scope of this PR.
Consequently, reported electricity costs are GPU-only costs, not complete host operating costs.
7. Implementation
Changes are limited to the existing components:
serve/telemetry.pyserve/server.pyserve/web/app.jsThe feature reuses Strata's existing telemetry, metrics and Monitor infrastructure without introducing additional services or persistent storage.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.