cpu: add workaround for counter resets related to % Processor Utility
metric
#1637
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.
Fixes #1299
Problem
The
% Processor Utility
performance counter hold 2 values: Amount of busy time (V), amount of CPU tick (D).To calculate the CPU percentage, the follow formula is needed:
(V1 - V0) / (D1 - D0)
. In prometheus, it can calculates viarate(V[1m]) / rate(D[1m])
.The CPU tick counter is an unsigned int32, with overflows approx. each 2 hours and the rollover happens on 4294967295 (2^32).
Program, that fetching the raw values, can handle the counter reset, because interger substractor works on overflows, too. (go ref: go.dev/play/p/57GXzfT-m5G)
For example:
C0 = ((2^32)-10)
C1 = 10
C1 - C0 = 20
The problem here is that all Prometheus values are float64. By converting the values, the bit based mechanic is lost.
This image explain how Prometheus handle the overflow which results into gaps using the rate function
Solution
The solution will introduce a dedicated counter which do some interger calcuation on each scrape. and add the value to a float64 counter