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

Provide live values corresponding to Process.Rlimit() #344

Closed
phemmer opened this issue Apr 4, 2017 · 1 comment · Fixed by #346
Closed

Provide live values corresponding to Process.Rlimit() #344

phemmer opened this issue Apr 4, 2017 · 1 comment · Fixed by #346

Comments

@phemmer
Copy link

phemmer commented Apr 4, 2017

Currently gopsutil provides (*Process).Rlimit(), but several of the resources who's limits are made available there, are not available for retrieval of their current values. For example locked memory, or stack size.

(This request was originally part of #343, but I'm breaking them apart as they really are separate, just related)
(Ref: influxdata/telegraf#2617)

@phemmer
Copy link
Author

phemmer commented Apr 4, 2017

Started looking into this as we need this functionality. Implementing this could be rather messy.
Lets look at a few examples:

  • Max open files (RlimitStat.Resource == RLIMIT_NOFILE)
    The active value is exposed as Process.NumFDs().
  • Max cpu time (RlimitStat.Resource == RLIMIT_CPU)
    The active value is exposed as a summation of Process.Times().User and Process.Times().System.
  • Max resident set (RlimitStat.Resource == RLIMIT_RSS)
    The active value is exposed as Process.MemoryInfo().RSS.
  • Max locked memory (RlimitStat.Resource == RLIMIT_MEMLOCK)
    The active value is not exposed anywhere.

As you can see, getting the active values is kinda scattered all over the place. It's also entirely possible that different OSs might implement them differently (such as cpu time limit might be user time only, and not system time). I think the cleanest implementation might be to instead expand RlimitStat to include the active value. We could make the behavior togglable, such as passing a boolean to Process.Rlimit() so that it doesn't gather the active values unless requested.
The main issue I see with this idea is that not all of the resource limits have an active value. For example the max core file size. That's only used when the process core dumps. When gathering the data, we could just skip it, in which it'll be presented as zero-value.
The alternative is we could have a method such as Process.RlimitCurrent(), which returns a list of structs using the same key as RlimitStat.Resource, and the user can then relate the 2 together.

P.S. Why does Process.Rlimit() return a slice, instead of a map with the RlimitStat.Resource as the map's key? It'd make finding a specific value much easier rather than having to iterate and compare equality.

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 a pull request may close this issue.

1 participant