-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[receiver/hostmetrics] Use gopsutil total seconds to calculate utilization #8857
[receiver/hostmetrics] Use gopsutil total seconds to calculate utilization #8857
Conversation
I don't think that For example: Let's assume So if we do this change the metrics becomes useless. |
Oh, after looking at the code, seems like |
receiver/hostmetricsreceiver/internal/scraper/cpuscraper/ucal/cpu_utilization_calculator.go
Outdated
Show resolved
Hide resolved
my bad 😅 I have updated the description and the variable name in 0e0c90e |
Hi @dmitryax do you think this can be merged to main? Is there anything else missing from my side? Thanks! |
Description:
system.cpu.utilization delta time is calculated using timestamps read in each scrape. These timestamp reads are not directly related to the cpu times reads so the used delta time to calculate utilization is not aligned with the delta time from times values. This makes system.cpu.utilization inacurate.
As cpu utilization relies on cpu times, the delta time should be calculated from the cpu times value (gopsutil already provides a Total() function that returns the total number of seconds). This way we can avoid timestamp read and persistence between scrapes simplifying it.
Now:
utilization.user = cpu.user / (time diff from system time)
utilization.idle = cpu.idle / (time diff from system time)
...
Proposal:
utilization.user = cpu.user / (elapsed seconds from times)
utilization.idle = cpu.idle / (elapsed seconds from times)
...
Link to tracking Issue:
#8856
Testing:
Tests have been refactored.
Documentation:
No additional documentation has been added.