jupyter-resource-usage icon indicating copy to clipboard operation
jupyter-resource-usage copied to clipboard

Get memory limits from psutil?

Open shreddd opened this issue 5 years ago • 1 comments

We'd like to automatically extract the total memory on the system via psutil rather than set the memory limit through a config option. It would also be useful to have another metric for total memory in use on the system (along with the memory used by Jupyter). Before submitting a PR, I wanted to check if this is desirable.

shreddd avatar Aug 04 '18 20:08 shreddd

@shreddd Is this referring to the "dynamic memory limit"? (As opposed to a "static memory limit" set via configuration?) I'm not sure since the dynamic memory limit also requires being set via the configuration file.

Also NBResuse right now doesn't currently track all of those metrics by default, but using the latest version of the GitHub master, it should be possible to do add something like:

c.ResourceUseDisplay.system_memory_metrics = [
    {"name": "virtual_memory", "attribute": "total"},
    {"name": "virtual_memory", "attribute": "available"},
    {"name": 'virtual_memory", "attribute": "free"},
    {"name": "virtual_memory", "attribute":"used"}
    {"name": "swap_memory", "attribute": "percent"}
])

cf. the psutil documentation. Although half of that is set up, the other half, consisting of automatically creating a Prometheus gauge to track and publish each system-wide memory metric specified in the configuration, still needs to be finished. (And then there's the issue of creating a GUI which can utilize all of this information, regardless of the configuration settings, which hopefully will be solved/addressed by another project, e.g. like jupyterlab-system-monitor).

The above example corresponds to the outputs of the psutil.virtual_memory (total, available, free, and used attributes of the output named tuple) and psutil.swap_memory (percent attribute of the output named tuple) functions. It just occurred to me that a more user-friendly standard would be to support configuration like:

c.ResourceUseDisplay.system_memory_metrics = [
    {"name": "virtual_memory", "attribute": ["total", "available", "free", "used"]},
    {"name": "swap_memory", "attribute": "percent"}
])

That would also require modifying several of the currently embedded assumptions in the code.

Anyway the long-term plan would be to have it such that with the above configuration Prometheus would be automatically publishing metrics to the endpoints metrics/virtual_memory_total, metrics/virtual_memory_available, metrics/virtual_memory_free, metrics/virtual_memory_used, and metrics/swap_memory_percent, without adding any more lines of code or manual user intervention to create those endpoints. I haven't fully implemented that yet, but it does seem to be within reach (cf. https://github.com/yuvipanda/nbresuse/pull/35 ).

krinsman avatar Apr 18 '20 04:04 krinsman