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

Support for using procstat without pgrep #3558

Closed
vrecan opened this issue Dec 8, 2017 · 9 comments · Fixed by #3559
Closed

Support for using procstat without pgrep #3558

vrecan opened this issue Dec 8, 2017 · 9 comments · Fixed by #3559
Labels
feature request Requests for new plugin and for new features to existing plugins

Comments

@vrecan
Copy link
Contributor

vrecan commented Dec 8, 2017

Proposal:

I would like to submit a PR to change proc stats to use go-ps instead of pgrep. This would allow pattern matching to work in a cross platform way. I am willing to do the work for this but I wanted to make sure that the change would be accepted.

Current behavior:

proc stats can not do pattern matching on windows

Desired behavior:

proc stats can do pattern matching on windows

Use case: [Why is this important (helps with prioritizing requests)]

This will allow me to leverage telegraf instead of rolling my own solutions to monitor java processes in windows.

@danielnelson
Copy link
Contributor

The go-ps API is very limited, so I don't think it would be suitable. Also, gopsutil can do all of this and is already a dependency so I would be more likely to try to create a pgrep replacement using it, but we need to pay close attention to performance.

Currently in Windows you should use the win_perf_counters input for this functionality.

@danielnelson danielnelson changed the title Change procstats to use go-ps instead of pgrep Support for using procstat without pgrep Dec 8, 2017
@danielnelson danielnelson added the feature request Requests for new plugin and for new features to existing plugins label Dec 8, 2017
@vrecan
Copy link
Contributor Author

vrecan commented Dec 8, 2017

How would I get memory and cpu stats for a process on windows?

@vrecan
Copy link
Contributor Author

vrecan commented Dec 8, 2017

I can go through gopsutil for this as well if you think that would be cleaner

@vrecan
Copy link
Contributor Author

vrecan commented Dec 8, 2017

Previously when using gopsutil for this I have found it to be a little on the slow side. This was over a year ago so things may have changed. I have contributed code to gopsutil in the past. I can implement this however you would like but I have a working version using go-ps

@danielnelson
Copy link
Contributor

Another issue with go-ps is that it is using cgo, but we currently cross-compile for Darwin and Windows. I wouldn't be very surprised if gopsutil's method is slower in Windows though.

You can get memory and cpu stats in Windows with win_perf_counters, check this example: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_perf_counters#process

@vrecan
Copy link
Contributor Author

vrecan commented Dec 8, 2017

Whats the problem with CGO? It's relatively easy to still cross compile with CGO. I do it on a bunch of projects. Gopsutil works with or without cgo. They have a common pattern of _no_cgo files and _cgo files.

Would you be happy with it if I just leverage gopsutil and benchmark it?

Thanks for working with me on this!

@danielnelson
Copy link
Contributor

Whats the problem with CGO?

The main issue is we need to setup the builds to do this, also at this time we want to make sure not to introduce any build requirements that will make compilation more difficult for Telegraf users, so no shared objects or such.

I'll also mention that we are somewhat sensitive to increasing the binary size unless there is a clear benefit.

Would you be happy with it if I just leverage gopsutil and benchmark it?

Yes, lets take a look. Even if it's slower maybe we could use it on Windows only, which might be required anyway since I suspect many users rely on quirks of pgrep and we don't want to break backwards compatibility.

@vrecan
Copy link
Contributor Author

vrecan commented Dec 10, 2017

I am working my way through an implementation. So far I have it working but for things like pattern matches it's really slow. gs-go version returns in 0.01 seconds and the gopsutil version takes 6 seconds to...

@vrecan
Copy link
Contributor Author

vrecan commented Dec 10, 2017

I have a PR to gopsutil that adds support for querying by cmdline and Name of a process. This allows us to get this to work on windows in a way that performs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants