Pull requests / #3628
#3628 [GUI] Add opt-in GPU energy and electricity cost monitoring to the Power card
open · @hash13 · 0 comentários · No GitHub
Server & APIMulti-GPUAMD / HIPNVIDIA / CUDA
Descrição
# [GUI] Add opt-in GPU energy and electricity cost monitoring to the Power card
## Summary
This PR adds optional GPU energy monitoring and electricity cost calculations to Strata's existing Monitor Power card.
The feature reuses Strata's existing GPU telemetry, multi-GPU support, and Monitor refresh infrastructure. No additional services, dependencies, or persistent storage are required.
Energy monitoring is strictly opt-in. Without an `electricity` configuration block, the existing Power card behavior remains unchanged.
The implementation focuses on cumulative GPU energy consumption and total electricity costs. Request-level energy attribution and token cost calculations are intentionally out of scope.
## Screenshot
<img width="353" height="212" alt="GPU energy and electricity cost monitoring" src="https://github.com/user-attachments/assets/efc6d451-e2b2-47f9-ad10-faaec18ab68f" />
## Configuration
Add an `electricity` block to the top level of the active Strata JSON configuration.
**Energy monitoring only:**
```json
"electricity": {}
```
**Energy monitoring with electricity costs:**
```json
"electricity": {
"price_per_kwh": 0.32,
"currency": "EUR"
}
```
- `price_per_kwh`: Optional non-negative electricity price per kWh.
- `currency`: Optional ISO currency code, defaulting to `EUR`.
- Without a valid price, cumulative energy consumption is displayed without costs.
- Without an `electricity` block, the feature is disabled.
Configuration changes take effect after restarting the server.
## Power Card
The existing Power card retains its current GPU power reading, power limit, and power history sparkline.
When electricity costs are enabled, the card uses a compact two-column layout:
| Power | Electricity cost |
|---|---|
| **278 W** | **0.155 €** |
| of 520 W limit | 483.0 Wh |
The layout reuses the existing Speed card styling without additional CSS or increased card height.
When only energy monitoring is enabled, cumulative energy consumption appears alongside the existing power limit.
All values update through the existing Monitor refresh cycle.
### Value Formatting
**Energy consumption:**
| Consumption | Display |
|---|---|
| Below 1 kWh | Wh, one decimal place |
| From 1 kWh | kWh, three decimal places |
**Electricity costs:**
| Cost | Display |
|---|---|
| Positive values below 0.001 | `< 0.001 €` |
| Below 10 | Three decimal places |
| From 10 | Two decimal places |
Currency symbols use the existing smaller unit styling. Number formatting follows the browser's locale.
## Energy Measurement
The implementation prefers NVIDIA's cumulative NVML hardware energy counter (`nvmlDeviceGetTotalEnergyConsumption`) when supported.
This provides accumulated energy directly in millijoules and avoids estimating consumption solely from periodically sampled power values.
If cumulative counter readings are unavailable during initialization, energy is estimated by integrating the existing GPU power samples over time using the trapezoidal rule.
For multi-GPU configurations:
- Supported hardware counters are aggregated across monitored GPUs.
- If cumulative counters are unavailable for one or more GPUs, the fallback uses aggregated GPU power measurements.
Energy accumulation begins when the telemetry sampler starts and resets when the sampler is recreated.
Electricity costs are calculated as:
**Cost = accumulated GPU energy (kWh) × configured price per kWh**
The cost calculation uses the accumulated energy value without requiring additional NVML reads beyond energy monitoring itself.
Measurements cover GPU energy only. CPU, RAM, motherboard, storage, fans, and PSU conversion losses are excluded.
Estimated energy depends on the availability and accuracy of GPU power readings.
## Operating Modes
| Configuration | Power Card Display |
|---|---|
| No `electricity` block | Current GPU power (W) and power limit only |
| `"electricity": {}` | GPU power, power limit, and cumulative energy consumption (Wh/kWh) |
| `electricity` with `price_per_kwh` | Two-column layout: GPU power and power limit on the left; total electricity cost and cumulative energy consumption on the right |
## Scope and Compatibility
- Feature disabled by default
- No changes to inference behavior
- No request-level accounting or token cost estimation
- No additional dependencies or persistent storage
- Existing `/metrics` endpoint extended with `hardware.gpu_energy_kwh` when enabled
- Optional electricity price and currency exposed through `hardware_static`
- Existing Power card retained when disabled
Request-level energy attribution is deferred to a later PR, initially limited to serial requests to avoid double counting energy during overlapping requests.
## Changed Files
The complete implementation affects three files:
| File | Changes |
|---|---|
| `serve/telemetry.py` | NVML cumulative energy readings, sampled-power fallback, multi-GPU aggregation, and electricity price metadata |
| `serve/server.py` | Pass optional electricity configuration to telemetry |
| `serve/web/app.js` | Display cumulative energy consumption and optional electricity costs in the existing Power card |
**Failed:** None observed.
**Not run:** Automated tests, AMD GPUs.
## Validation
**Revision:** Strata v0.2.2 with PR changes
**Environment:** Intel i9-14900K, 2× RTX 5060 Ti, CUDA 13.0, Podman
**Commands / steps:**
- Started Strata with the modified configuration.
- Opened Monitor → Power in the browser.
**Passed:**
- Manual testing on Strata v0.2.2
- GPU energy and electricity cost display
**Failed:** None observed.
**Not run:** Automated tests, AMD GPUs.
No site
Links install, modelos, releases.