-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proc.Percent() #318
Comments
if interval > 0: Below is the change I made Also, |
@adityacs do you have proof that the CPU usage of your process is not 0? |
I have verified this on many processes. It will show 0 value. However, if I do sleep for 3 to 5 secs then I can get the value. |
I think this issue can be closed, @adityacs in this comment you are only collecting the process information once: #318 (comment) CPU usage requires TWO data points in order to be calculated (and there needs to be measurable time between the two collections). So your first collection will always be 0. Try sleeping for a few hundred milliseconds between two collections and you should see a usage reading. |
@sparrc sleeping is handled by this part of the code right?. line
what will be the use of the else part?
|
Where is that code from exactly? I was referring to your Would help if you could try formatting your code a bit better, use "```" to surround either side of a single block of code. |
in https://github.com/shirou/gopsutil/blob/master/process/process.go
|
Any update on this? |
@adityacs so what are you saying is the bug? proc.Percent already provides a way to call it with a sleep. Are you asking that the default behavior be changed? |
@sparrc If we don't change the implementation here, then in telegraf procstat plugin we will have to add some sleep instead of time.Duration(0). |
no it won't, proc.Percent() caches the previous call and uses that if time.Duration == 0 |
@sparrc In telegraf my interval is 10s. However, I always receive "0"% for cpu_usage. |
@sparrc "no it won't, proc.Percent() caches the previous call and uses that if time.Duration == 0". Caching is working for me absolutely fine when I try from a sample code. I am not sure why from telegraf I am getting "0" value. |
@adityacs I think you are confusing a telegraf issue with a gopsutil issue. The problem is a recently merged PR on the master branch of Telegraf. I am reverting that commit here: influxdata/telegraf#2479 @shirou I think you can close this issue. |
@sparrc Sorry for the confusion. In my first comment of this issue itself I mentioned I am using procstat telegraf pluign. |
@shirou Sure Thanks |
I am trying to get cpu usage for a process. However, I am getting 0 as the value always.
Below is my sample code. I am using telegraf procstat plugin. Even there it's returning 0 value
`
func main() {
}`
Thanks
The text was updated successfully, but these errors were encountered: