Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding kernel specific metrics to nbresuse #40 #41

Closed
wants to merge 9 commits into from
Closed

Adding kernel specific metrics to nbresuse #40 #41

wants to merge 9 commits into from

Conversation

Gsbreddy
Copy link

This will address the issue #40

@Gsbreddy
Copy link
Author

The sample metrics are attached here for reference. The kernel specific metrics can be found at the end of the file. This has hub metrics as well since I was testing from hub so please ignore them.

hubmetrics.txt

@jtpio
Copy link
Member

jtpio commented May 20, 2020

Thanks @Gsbreddy!

nbresuse/prometheus.py Outdated Show resolved Hide resolved
@Gsbreddy
Copy link
Author

Gsbreddy commented May 20, 2020 via email

nbresuse/prometheus.py Outdated Show resolved Hide resolved
Using kernel_spec_manager now so that we can support more kernels like xpython etc. even if they are installed using conda or pip.
nbresuse/prometheus.py Outdated Show resolved Hide resolved
@jtpio
Copy link
Member

jtpio commented May 26, 2020

Thanks @Gsbreddy for working on this.

I submitted a small fix in https://github.com/Gsbreddy/nbresuse/pull/1.

Fix handling of kernel specs in kernel metrics
@jtpio
Copy link
Member

jtpio commented May 26, 2020

Trying it locally with the xeus-python wheel (installed from PyPI). It looks like it is not picked up because the argv doesn't fully match the command of the process:

home/jtp/miniconda/envs/nbresuse/bin/python -m xpython_launcher -f /home/jtp/.local/share/jupyter/runtime/kernel-3cd39950-b840-44e4-b0e8-23ec9b780f1e.json

While the kernel.json spec in ${CONDA_PREFIX}/share/jupyter/kernels/xpython/kernel.json contains python3.8 only:

{
  "display_name": "xpython",
  "argv": [
      "python3.8",
      "-m",
      "xpython_launcher",
      "-f",
      "{connection_file}"
  ],
  "language": "python"
}

@Gsbreddy
Copy link
Author

Looks like python3.8 in argv is getting expanded in process to that env specific python.

@jtpio
Copy link
Member

jtpio commented May 26, 2020

Yes, with something like os.path.realpath("python3.8")

@jtpio
Copy link
Member

jtpio commented May 26, 2020

It looks like it is coming from jupyter_client: https://github.com/jupyter/jupyter_client/blob/15b3b0566d962bbc042d21b858caeca2e870209a/jupyter_client/manager.py#L180-L189

Since argv[0] matches python3.8, it is then replaced by sys.executable.

@Gsbreddy
Copy link
Author

Gsbreddy commented May 26, 2020

Yeah, we can do the same here as well. Then the match will work.

executable is 'python' or 'python3', use sys.executable. These will typically be the same, but if the current process is in an env and has been launched by abspath without activating the env, python on PATH may not be sys.executable, but it should be.
@Gsbreddy
Copy link
Author

I handled this using sys. Please check now.

nbresuse/prometheus.py Outdated Show resolved Hide resolved
Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
nbresuse/prometheus.py Outdated Show resolved Hide resolved
nbresuse/prometheus.py Outdated Show resolved Hide resolved
@jtpio
Copy link
Member

jtpio commented May 28, 2020

Just tested locally and the kernel_memory_usage shows up in the prometheus metrics after starting a new kernel:

# HELP kernel_memory_usage counter for kernel memory usage
# TYPE kernel_memory_usage gauge
kernel_memory_usage{kernel_id="06a46d91-5161-4e13-8800-9bca3f881a64"} 2.5636864e+07

However it will still be reported even after the kernel has been shut down. I guess we will want to remove it from the list? Otherwise the frontends will need to query the list of running kernels separately and filter the metrics taking into account only the running kernels?

@jtpio
Copy link
Member

jtpio commented May 28, 2020

Although with Prometheus it's usually preferred for the metrics to be persisted (time series data).

@Gsbreddy
Copy link
Author

This would give information on the usage trend of the user.

Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
@jtpio
Copy link
Member

jtpio commented May 28, 2020

Tested with ipykernel, xeus-python and the bash kernel, and they all seem to be listed in the metrics.

In follow-ups PRs, we could:

  • add tests
  • try to think of a way to query snapshots of the metrics. The previous API (with the JSON response) before the switch to Prometheus is still a convenient way for frontends to retrieve the data (see JupyterLab regression #36 for more context)

Thanks again @Gsbreddy for working on this 👍

cc @krinsman who has commit rights and might want to have a look.

@Gsbreddy
Copy link
Author

Gsbreddy commented May 28, 2020

I agree. I think we can go with #19 and have an API with previous JSON response(api/nbresuse/v1) for Jupyterlab to display on UI and leave /metrics for prometheus use. If not #19 then have to think of a way to achieve this.

I am working on making this work with JupyterLab. So I will update once done.

@jtpio
Copy link
Member

jtpio commented May 28, 2020

I am working on making this work with JupyterLab. So I will update once done.

Using a JSON response from /api/nbresuse/v1? Or by parsing the Prometheus metrics with regexes?

@Gsbreddy
Copy link
Author

Gsbreddy commented May 28, 2020 via email

@jtpio
Copy link
Member

jtpio commented May 28, 2020

Sounds good!

@Gsbreddy
Copy link
Author

Gsbreddy commented May 28, 2020

I will raise a PR once I finish that work. Can we close this or should we wait till next PR?

@jtpio
Copy link
Member

jtpio commented May 29, 2020

I am working on making this work with JupyterLab

Where do you plan to do that? In nbresuse? In JupyterLab? In another extension like the jupyterlab-system-monitor?

@Gsbreddy
Copy link
Author

I am planning it in nbresuse and then make a subsequent change in JupyterLab to call new api(/api/nbresuse/v1) in nbresuse(As I mentioned, similar to 0.3.3).

@jtpio
Copy link
Member

jtpio commented May 29, 2020

👍

(I thought it was about using the kernel metrics from this PR)

@Gsbreddy
Copy link
Author

Gsbreddy commented Jun 3, 2020

@krinsman @jtpio
Please review. -> https://github.com/Gsbreddy/nbresuse/pull/2
This solves yuvipanda#36

@jtpio
Copy link
Member

jtpio commented Jun 3, 2020

Thanks @Gsbreddy, it looks promising!

I'll give it a try locally soon.

@Gsbreddy
Copy link
Author

@jtpio

Tested with ipykernel, xeus-python and the bash kernel, and they all seem to be listed in the metrics.

In follow-ups PRs, we could:

  • add tests
  • try to think of a way to query snapshots of the metrics. The previous API (with the JSON response) before the switch to Prometheus is still a convenient way for frontends to retrieve the data (see JupyterLab regression #36 for more context)

Thanks again @Gsbreddy for working on this 👍

cc @krinsman who has commit rights and might want to have a look.

Can you take a look at this ?

@jtpio jtpio deleted the branch jupyter-server:master February 6, 2023 12:49
@jtpio jtpio closed this Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants