Adding file descriptor metrics to topbeat and gosigar

I really like the metrics topbeat grabs per process but I feel it is missing a two key metric which is the file descriptor limit for the process and the amount currently used by it. Along with CPU and Memory resource I feel the most common thing to exhaust is the process's fd limit. I am willing to add it and submit a pull request, but I wanted to start a discussion first and make sure that this feature is something the community would like and that it would have a chance of being merged. It will also take a pull request to the elastic/gosigar fork also. Although I believe this would be a primarily Linux feature, I believe it would be VERY useful. From what I was able to gather, it would be possible to implement for OpenBSD and Darwin also (though that uses C in gosigar which I'm not that great with).

I think it would be useful to report the number of file descriptors in use, the soft limit, and the hard limit on a per process basis. It would be handy for detecting leaks or alerting when a process starts approaching its FD limit.

You could start with the Linux implementation in elastic/gosigar. And possibly we can get others to contribute on the Darwin and OpenBSD implementations. Please open en enhancement issue in the elastic/beats repo for this.

If the FD metrics are not implemented then we should ensure that they are not reported by the Beat (versus reporting zero values for each metric). Be aware that we are using elastic/gosigar in both Topbeat and Metricbeat. I think Metricbeat will eventually supersede Topbeat, it already reports all of the same data as Topbeat and more.

And apparently I had opened an issue in elastic/topbeat for this before we merged everything into elastic/beats. https://github.com/elastic/topbeat/issues/120

That issue reminds me that on Windows we could report the number of handles held by a process.

I had looked at metricbeat but didn't notice the system module. I think it makes more sense for me to focus on adding it to metricbeat first then shouldn't I?

I think the FD logic should be added to elastic/gosigar first. Then once that is in place, update Metricbeat to publish the data and ignore Topbeat for now.

So it appears that metricbeat is just using topbeat for most of the stuff under the hood. I'm not sure how I would add it to metricbeat without adding it to topbeat?

True, so you are going to have to plumb the data through Topbeat for the reporting the process file descriptors. For the overall system file descriptors you could possibly invoke gosigar directly from a new MetricSet in Metricbeat (similar to how the diskio MetricSet directly calls gopsutil).

@lukejolly @andrewkroh Just saw this thread now. Both options work :wink: https://github.com/elastic/beats/issues/1789