-
-
Notifications
You must be signed in to change notification settings - Fork 388
Description
While implementing a jupyterlab extension to monitor the kernel usage (https://github.com/Quansight/jupyterlab-kernel-usage), a few PRs have been merged to use psutil to return Memory, CPU usage of the machine and the kernel processes.
- Add usage_request and usage_reply based on psutil #805
- Add hostname to the usage reply #865
- Add the PID to the resource usage reply #908
This has worked great for most of the metrics, but we hit now an issue for the kernel CPU reported on Quansight/jupyterlab-kernel-usage#11. psutil returns the CPU based on the last call, so it looks like everytime we ask the CPU via the kernel websocket, it return zero as psutil considers it is the first time the request is made, see info on:
- https://psutil.readthedocs.io/en/latest/#psutil.cpu_percent
- https://stackoverflow.com/questions/24367424/cpu-percentinterval-none-always-returns-0-regardless-of-interval-value-python/27229967#27229967
Please note that similar issue is reported on the jupyter-resource-usage extension (which monitors the server usage, not the kernel usage) jupyter-server/jupyter-resource-usage#107
A solution would be to maintain a separated thread that would be responsible to return that CPU in a correct way based on psutil.
What would be the impact to create such as separated thread? What are the already existing threads? Does it sound like a reasonable approach? Any other idea?