Web server reports a CPU load that's a spike value and not indicative of actual load
Describe the bug
The CPU tile on the web dashboard shows a steady 20-24% on a nearly idle Pi. The same cpu_percent value fetched on its own (GET /api/device/metrics) is 0-1%, and top on the Pi shows about 2% busy.
/api/device/metrics uses psutil.cpu_percent(interval=0.5), which measures a 0.5 s window. The dashboard requests metrics at the same moment as /api/nodes?enrich=true, /api/packets and the analytics endpoints (frontend/js/app.js, _updateStats()), so that window includes the CPU spent answering the page's own requests. The tile therefore reports the cost of loading the dashboard, not the Pi's real load.
Steps to reproduce
- Log in and note
cpu_percentfromGET /api/device/metricsrequested on its own, repeatedly. It reads about 0-1%. - Fire
/api/nodes?enrich=true,/api/packets?limit=50,/api/analytics/traffic,/api/analytics/signal/summary,/api/nodes/countand/api/device/statusin parallel with a/api/device/metricsrequest, as the dashboard does. cpu_percentjumps to about 21-25%. Opening the dashboard in a browser shows the same 20-24% every 15 s.
Expected behavior
cpu_percent should reflect the Pi's actual load and not depend on what other requests arrive with it. Suggestion (untested): sample psutil.cpu_percent(interval=None) on a background timer and return the latest value or a short moving average.
With the addition of SDR functions running alongside the Meshtastic and Meshcore functions, it is important to know actual CPU load, along with max spikes so that we can know when there isn't anymore overhead to support additional functions.
Hardware
- Pi: Raspberry Pi 4 (4 cores)
- Concentrator: RAK v2 Pi HAT (exact concentrator model: [fill in])
- Node/radio: Meshtastic, US 906.375 MHz, MediumFast
- Region: US
- OS: Debian 13 (trixie); Meshpoint v0.7.7
Logs / screenshots
Metrics alone, repeated: cpu_percent 0.0, 0.0, 1.0, 0.0, 0.0; load average 0.07-0.20.
Metrics fired concurrently with the dashboard's other requests: cpu_percent 0.5, 25.2, 21.6.
Direct measurement on the Pi:
$ top -bn2 -d5 | grep "^%Cpu" | tail -1 %Cpu(s): 1.3 us, 0.8 sy, 0.0 ni, 97.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
RAM (14.1%) and disk (67.3%) on the dashboard match the API, so only CPU differs.
Notes
I found this while comparing the dashboard to a small ESP32 touchscreen viewer I built (https://github.com/parheliatech/MeshPointCYD). It fetches metrics alone every 15 s, so it sees the idle value. Full analysis: https://github.com/parheliatech/MeshPointCYD/blob/main/docs/cpu-percent-analysis.md
Thanks for the detailed report. The fix is now merged into the RC branch (feat/v0.8.0) via #150.
CPU usage is sampled independently every two seconds, and the dashboard and remote metrics read the cached value. This removes the blocking half-second sample from each metrics request. The dashboard shows N/A while the first valid sample is pending.
CI passed. On a test device, metrics-request latency fell from approximately 600–795 ms to 14–26 ms. We also checked the rendered dashboard across several refreshes: the previous roughly 25% readings were replaced by lower, varying readings with the fix. This was a short observation window, not a calibrated CPU-accuracy test.
The fix is available on RC; it is not in Stable/main yet. If you use RC, please update and let us know whether this resolves the behavior on your device. Leaving this issue open for that confirmation.