shirou / gopsutil

psutil for golang
Other
10.56k stars 1.58k forks source link

Expose Swap/Paging usage per device #1115

Closed tbarker25 closed 2 years ago

tbarker25 commented 3 years ago

Is your feature request related to a problem? Please describe. As part of OpenTelemetry collection, we would like to expose the swap usage per device. for more specifics on our use-case see: https://github.com/open-telemetry/opentelemetry-collector/issues/3447

Describe the solution you'd like mem.VirtualMemory() (or another method) to expose swap usage on a per device basis.

Describe alternatives you've considered Implementing this in the otel-collector instead. This is certainly possible, but we would prefer the logic be in gopsutil.

Additional context Here is an example of collecting this in Linux: https://github.com/tbarker25/opentelemetry-collector/blob/swap-devices/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/pagefile_linux.go

tbarker25 commented 3 years ago

if this is a change you are amenable to then we're willing to write a PR (at least for the OSs we care about)

shirou commented 3 years ago

gopsutil is a port from psutil. psutil does not have such a device level swap usage. so, basically "No". However, from my personal interest, I think that this feature can be added.

To add, we should discuss about those.

  1. Implements or survey how to implements at least Linux, Windows, Darwin, FreeBSD.
  2. Define the function as completely independent of the psutil function

For example, from my quick survey, FreeBSD can get device level swap usage by using swapctl like this

[freebsdhost]%swapctl -l
Device:       1024-blocks     Used:
/dev/vtbd0p2    1048576    531276

We need more information on Darwin to proceed discussion.

For 2, create for example, mem.SwapDevices() (needs more good name!) function and implements those. then, this does not affects current API.

tbarker25 commented 3 years ago

I had a look around for a way to do this on Darwin and couldn't find one. It might not be possible.

Are we able to proceed leaving Darwin as unimplemented, or this a showstopper?

tbarker25 commented 3 years ago

I've put together a PR for this. I did not manage to find a way to implement this for Darwin, but did find a way for Linux, FreeBSD, OpenBSD, Windows and Solaris.