fix: use idle-based CPU formula in dashboard charts and alert evaluator#54
Merged
TerrifiedBug merged 2 commits intomainfrom Mar 7, 2026
Merged
fix: use idle-based CPU formula in dashboard charts and alert evaluator#54TerrifiedBug merged 2 commits intomainfrom
TerrifiedBug merged 2 commits intomainfrom
Conversation
GET /api/v1/pipelines/:id and /api/v1/nodes/:id return 500 because NodePipelineStatus contains BigInt fields (eventsIn, eventsOut, etc.) that JSON.stringify cannot serialize. Adds a jsonResponse() helper using a custom replacer to convert BigInts to numbers.
The fleet detail page correctly uses (total - idle) / total for CPU%, but the dashboard charts and alert evaluator still used the old cpuDelta / wallClockSeconds formula which gives per-core percentages (e.g. 787% on an 8-core machine). This aligns all CPU calculations to the same idle-based formula clamped to 0-100%. Affected code paths: - dashboard.chartMetrics: chart CPU time-series - dashboard.nodeCards: sparkline CPU values - alert-evaluator getCpuUsage: alert threshold checks
Contributor
Greptile SummaryThis PR aligns CPU usage calculations across three previously-inconsistent code paths — Changes:
No correctness bugs were identified. The formulas are mathematically correct, counter-reset edge cases are properly guarded, and the Prisma schema confirms Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Agent Heartbeat] --> B[metrics-ingest: Store NodeMetric with cpuSecondsTotal and cpuSecondsIdle]
B --> C[alert-evaluator getCpuUsage]
B --> D[dashboard nodeCards sparkline]
B --> E[dashboard chartMetrics CPU series]
C --> F["totalDelta = newer.total - older.total\nif totalDelta le 0 return null\ncpu% = clamp totalDelta - idleDelta / totalDelta x 100"]
D --> G["per-row delta between arr i and arr i-1\nif totalDelta > 0 compute cpu%\nelse cpu = 0"]
E --> H["per-row delta between curr and prev\nif cpuTotalDelta > 0 compute cpu%\nelse cpu = 0"]
F --> I[AlertEvent fire or resolve]
G --> J[Node card sparkline chart]
H --> K[Dashboard CPU time-series chart]
L[Public REST routes nodes and pipelines] --> M[jsonResponse: BigInt to Number replacer]
Last reviewed commit: e18b43d |
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.
Summary
(total - idle) / totalfor CPU%, but three other code paths still used the oldcpuDelta / wallClockSecondsformula — producing values like 787% on multi-core machinesAffected code paths
alert-evaluator.tsgetCpuUsage()— alert threshold checks (the 787.80% firing alert)dashboard.tschartMetrics— dashboard CPU chart time-seriesdashboard.tsnodeCardssparkline — was passing raw cumulativecpuSecondsTotal, now computes percentageTest plan
topoutput), not pinned at 100%