Repository navigation
fix(metrics): CPU usage shown inverted on Linux (~99% when idle) - #45
Open
flavioduque wants to merge 1 commit into
Open
flavioduque wants to merge 1 commit into
flavioduque wants to merge 1 commit into
Conversation
…age, code subtracted from 100 again) and no longer invents a random value when measurement fails Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Linux the dashboard reports ~99% CPU while the host is idle.
getCpuUsage()runs:top -lis macOS-only, so on Linux thempstatbranch runs. Thatawkalready prints usage (100 - %idle), but the code treats the number as idle and computes100 - valueagain. The result is inverted: an idle server shows ~99%, a busy one shows a low value.Also, when measurement throws, the route returned
Math.floor(Math.random() * 30) + 10, which is a made-up number shown as real data.Fix
mpstatbranch now prints%idle(awk '{print $NF}'), which is what the parsing code expects. The macOS path is unchanged.os.cpus()calculation instead of a random value.Verification
Ran inside the running panel container (Alpine, BusyBox
top, sysstatmpstat) with the command string read straight fromroute.tsand the same parsing:1.599.37Not covered by an automated test: the function shells out to
mpstat/top. I can extract the parsing into a pure helper with atests/*.test.tscase if you prefer.🤖 Generated with Claude Code