Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CPU load): Fix CPU load showing 0% in Runtime -> Metrics -> System #1057

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

five-iron
Copy link
Contributor

The problem I am seeing in a downstream project is while viewing the Runtime->Metrics tab, CPU load almost always shows 0.00%. What I think is going on after some digging is that Jolokia is returning 0 for SystemCpuLoad due to this problem here: https://medium.com/infobipdev/the-java-cpu-usage-observer-effect-18808b18323f

The hidden cause of this discrepancy is the rename of the metric in JDK 14 from SystemCpuLoad to CpuLoad. The old metric was not removed, only deprecated in the API. JmxCollector pulls and publishes all available metrics, effectively calculating the same CPU usage twice in a row. The value was corrupted by merely measuring it — twice.

In the back end, getSystemCpuLoad() actually just calls getCpuLoad(), resulting in two nearly subsequent calls to that getCpuLoad method when the whole OperatingSystem mbean is called, which the medium article warns about.

From looking at the actual jolokia response object, CpuLoad in actually does have a real value, so this proposed change would just use that instead if available.

Made both fields conditional in the ts class in order to:

  1. Support servers running <JDK14, before CpuLoad was added
  2. Protect against SystemCpuLoad possibly getting removed in a future version of Java

@hawtio-ci
Copy link

hawtio-ci bot commented Aug 7, 2024

Test results

Run attempt: 2109
Detailed summary

NAME TESTS PASSED ✅ SKIPPED 💤 FAILED ❌ ERRORS 🚫 TIME 🕖
results-quarkus-node(18)-java(17)-firefox 67 64 3 0 0 319.644
results-quarkus-node(18)-java(21)-firefox 67 64 3 0 0 312.047
results-quarkus-node(20)-java(17)-firefox 67 64 3 0 0 311.136
results-quarkus-node(20)-java(21)-firefox 67 64 3 0 0 312.277
results-springboot-node(18)-java(17)-firefox 67 63 4 0 0 311.126
results-springboot-node(18)-java(21)-firefox 67 63 4 0 0 313.075
results-springboot-node(20)-java(17)-firefox 67 63 4 0 0 311.965
results-springboot-node(20)-java(21)-firefox 67 63 4 0 0 312.914

Copy link

github-actions bot commented Aug 7, 2024

Test Results

  8 files  ±0    8 suites  ±0   41m 44s ⏱️ +2s
 66 tests ±0   64 ✅ ±0   2 💤 ±0  0 ❌ ±0 
536 runs  ±0  508 ✅ ±0  28 💤 ±0  0 ❌ ±0 

Results for commit 9fcd4bb. ± Comparison against base commit 3a9f4d6.

♻️ This comment has been updated with latest results.

@five-iron five-iron marked this pull request as draft August 8, 2024 03:44
@five-iron five-iron marked this pull request as ready for review August 8, 2024 04:40
@tadayosi tadayosi merged commit ef87d11 into hawtio:main Aug 8, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants