Not showing (caused by 404 on Endpoint /api/metrics/v1?)
lysogeny opened this issue · 8 comments
I have the installed this package via pip
, yet no memory usage is shown in the jupyter GUI.
I have the following:
jupyter-client 6.1.7
jupyter-console 6.2.0
jupyter-core 4.6.3
jupyter-packaging 0.7.12
jupyter-resource-usage 0.5.1
jupyter-server 1.4.1
jupyterlab 3.0.10
jupyterlab-execute-time 2.0.2
jupyterlab-git 0.23.3
jupyterlab-latex 2.0.0
jupyterlab-pygments 0.1.2
jupyterlab-server 2.3.0
jupyterlab-system-monitor 0.8.0
jupyterlab-topbar 0.6.1
jupyterlab-vim 0.13.4
JupyterLab v3.0.10
/home/jooa/.local/share/jupyter/labextensions
jupyterlab-execute-time v2.0.2 enabled OK (python, jupyterlab_execute_time)
jupyterlab-topbar-extension v0.6.1 enabled OK (python, jupyterlab-topbar)
jupyterlab-system-monitor v0.8.0 enabled OK (python, jupyterlab-system-monitor)
@axlair/jupyterlab_vim v0.13.4 enabled OK (python, jupyterlab_vim)
@jupyter-server/resource-usage v0.5.0 enabled OK (python, jupyter-resource-usage)
Other labextensions (built into JupyterLab)
app dir: /home/jooa/.local/share/jupyter/lab
@jupyterlab/debugger v3.0.7 enabled OK
@jupyterlab/git v0.23.3 enabled X
@jupyterlab/toc v5.0.6 enabled OK
jupyterlab-theme-toggle v0.6.1 enabled OK
nbdime-jupyterlab v2.0.1 enabled X
The following extension are outdated:
@jupyterlab/git
nbdime-jupyterlab
Yet,
Mar 23 18:59:00 vm-129-69 jupyter[1806765]: [W 2021-03-23 18:59:00.435 ServerApp] 404 GET /jupyter/api/metrics/v1?1616522340417 (193.174.53.84) 1.03ms referer=[snip]
appears in the logs.
Why is the endpoint returning a 404? What am I missing?
I found that this happens when you run as user instead of root, Dockerfile to reproduce:
FROM python:3
RUN groupadd -g 1000 python
RUN useradd -m -d /opt/python -u 1000 -g python python
USER python
ENV PATH /opt/python/.local/bin:$PATH
RUN pip install --user --no-cache-dir jupyterlab jupyter-resource-usage
EXPOSE 8888
CMD [ "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--ServerApp.token=''", "--ServerApp.password=''" ]
docker build -t jupyter-resource-usage-91 .
docker run -it --rm -p8888:8888 jupyter-resource-usage-91
The same as root works:
FROM python:3
RUN pip install --no-cache-dir jupyterlab jupyter-resource-usage
EXPOSE 8888
CMD [ "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--ServerApp.token=''", "--ServerApp.password=''", "--allow-root" ]
docker build -t jupyter-resource-usage-91-root .
docker run -it --rm -p8888:8888 jupyter-resource-usage-91-root
I'm not sure what's causing this problem :(.
I was able to fix it, if you start Lab with --log-level DEBUG
flag you can see that the configuration path ~/.local/etc/jupyter
is not searched.
I don't know how to adjust the search paths but symlinking it to ~/.jupyter
works.
FROM python:3
RUN groupadd -g 1000 python
RUN useradd -m -d /opt/python -u 1000 -g python python
USER python
ENV PATH /opt/python/.local/bin:$PATH
RUN pip install --user --no-cache-dir jupyterlab jupyter-resource-usage
RUN ln -snf /opt/python/.local/etc/jupyter /opt/python/.jupyter
EXPOSE 8888
CMD [ "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--ServerApp.token=''", "--ServerApp.password=''" ]
docker build -t jupyter-resource-usage-91-ln .
docker run -it --rm -p8888:8888 jupyter-resource-usage-91-ln
Thank you very much!
I symlinked the contents of ~/.local/etc/jupyter
into ~/.jupyter
and that has resolved my issues with this. I don't know what the proper fix would be though.
Thanks all for reporting.
0.6.0
was just released so you might want to check whether this is still an issue: https://pypi.org/project/jupyter-resource-usage/
Otherwise it's possible that the server is failing to activate the extension, which would then not add the endpoint and give this 404 error. Does anything show up in the server logs, that would look like the following?
[W 2021-04-29 16:09:49.496 ServerApp] jupyter_resource_usage | extension failed loading with message:
No difference in 0.6.0.
The problem is that the configuration which loads the extension is not found because it is not in the correct location.
I'm not sure if this problem is caused by a problem in Jupyterlab not having the correct search path in the default installation or by the installation of this extension.
I also encountered this problem. After I installed jupyterhub, no memory usage is shown on the top right side.
I uninstall the extension and then reinstall it in my own directory. After this action, the resource info successfully come out.
I had the same problem, but it was not resolved by the symlinking solution suggested above. I traced it down to what is probably a version conflict between the version of jupyter
(or probably more specifically: of notebook
) I'm using, and the jupyter-resource-usage
package. My versions are:
$ jupyter --version
jupyter core : 4.7.1
jupyter-notebook : 6.4.0
qtconsole : not installed
ipython : 7.25.0
ipykernel : 6.0.0
jupyter client : 6.1.12
jupyter lab : not installed
nbconvert : 6.4.0
ipywidgets : 7.6.3
nbformat : 5.1.3
traitlets : 5.0.5
My original issue was as reported here: memory usage wasn't showing, and the debugging console of my browser showed a 404 on /api/metrics/v1.
I ran a jupyter serverextension list
, but that showed up empty. While my notebook version should be new enough to find and enable extensions by default, I tried to run
jupyter nbextension enable --py jupyter_resource_usage
jupyter serverextension enable --py jupyter_resource_usage
just to be sure. The second command gave me an error:
File "/sw/arch/Debian10/EB_production/2021/software/IPython/7.25.0-GCCcore-10.3.0/lib/python3.9/site-packages/notebook/serverextensions.py", line 327, in _get_server_extension_metadata
raise KeyError(u'The Python module {} does not include any valid server extensions'.format(module))
KeyError: 'The Python module jupyter_resource_usage does not include any valid server extensions
Inspecting the code snippet that threw the error (serverextensions.py
, around line 327):
def _get_server_extension_metadata(module):
"""Load server extension metadata from a module.
Returns a tuple of (
the package as loaded
a list of server extension specs: [
{
"module": "mockextension"
}
]
)
Parameters
----------
module : str
Importable Python module exposing the
magic-named `_jupyter_server_extension_paths` function
"""
m = import_item(module)
if not hasattr(m, '_jupyter_server_extension_paths'):
raise KeyError(u'The Python module {} does not include any valid server extensions'.format(module))
return m, m._jupyter_server_extension_paths()
I had another notebook server extension around that was working, and it had the following code snippet in its __init__.py
:
# For backward compatibility
load_jupyter_server_extension = _load_jupyter_server_extension
_jupyter_server_extension_paths = _jupyter_server_extension_points
Aha, that comment seems to suggest that it used to be called _jupyter_server_extension_paths
(and clearly that was the case in my serverextension.py
, and is now called _jupyter_server_extension_points
. However, jupyter-resource-usage
only sets the latter, and thus is (I think) not backwards compatible with my version of notebook
.
The dead simple solution was to add _jupyter_server_extension_paths = _jupyter_server_extension_points
to the end of the __init__.py
file of jupyter-resource-usage
. After that, my issue was fixed. I'll make a PR for this.