-
Notifications
You must be signed in to change notification settings - Fork 318
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
[Batch 2] Notebook PR Ports. #97
Changes from all commits
5013110
c8c853d
674b65c
0abc68c
3d1cb4c
1ec99a4
3bc7091
25b9f80
9eafe12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #98. |
||
|
||
|
||
def prometheus_log_method(handler): | ||
""" | ||
Tornado log handler for recording RED metrics. | ||
|
||
We record the following metrics: | ||
Rate - the number of requests, per second, your services are serving. | ||
Errors - the number of failed requests per second. | ||
Duration - The amount of time each request takes expressed as a time interval. | ||
|
||
We use a fully qualified name of the handler as a label, | ||
rather than every url path to reduce cardinality. | ||
|
||
This function should be either the value of or called from a function | ||
that is the 'log_function' tornado setting. This makes it get called | ||
at the end of every request, allowing us to record the metrics we need. | ||
""" | ||
HTTP_REQUEST_DURATION_SECONDS.labels( | ||
method=handler.request.method, | ||
handler='{}.{}'.format(handler.__class__.__module__, type(handler).__name__), | ||
status_code=handler.get_status() | ||
).observe(handler.request.request_time()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Prometheus metrics exported by Jupyter Notebook Server | ||
|
||
Read https://prometheus.io/docs/practices/naming/ for naming | ||
conventions for metrics & labels. | ||
""" | ||
|
||
|
||
from prometheus_client import Histogram, Gauge | ||
|
||
|
||
HTTP_REQUEST_DURATION_SECONDS = Histogram( | ||
'http_request_duration_seconds', | ||
'duration in seconds for all HTTP requests', | ||
['method', 'handler', 'status_code'], | ||
) | ||
|
||
TERMINAL_CURRENTLY_RUNNING_TOTAL = Gauge( | ||
'terminal_currently_running_total', | ||
'counter for how many terminals are running', | ||
) | ||
|
||
KERNEL_CURRENTLY_RUNNING_TOTAL = Gauge( | ||
'kernel_currently_running_total', | ||
'counter for how many kernels are running labeled by type', | ||
['type'] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
from jupyter_server._tz import utcnow, isoformat | ||
from ipython_genutils.py3compat import getcwd | ||
|
||
from notebook.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notebook? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
||
class MappingKernelManager(MultiKernelManager): | ||
"""A KernelManager that handles | ||
|
@@ -178,6 +180,13 @@ def start_kernel(self, kernel_id=None, path=None, **kwargs): | |
lambda : self._handle_kernel_died(kernel_id), | ||
'dead', | ||
) | ||
|
||
# Increase the metric of number of kernels running | ||
# for the relevant kernel type by 1 | ||
KERNEL_CURRENTLY_RUNNING_TOTAL.labels( | ||
type=self._kernels[kernel_id].kernel_name | ||
).inc() | ||
|
||
else: | ||
self._check_kernel_id(kernel_id) | ||
self.log.info("Using existing kernel: %s" % kernel_id) | ||
|
@@ -282,11 +291,19 @@ def shutdown_kernel(self, kernel_id, now=False): | |
"""Shutdown a kernel by kernel_id""" | ||
self._check_kernel_id(kernel_id) | ||
kernel = self._kernels[kernel_id] | ||
kernel._activity_stream.close() | ||
kernel._activity_stream = None | ||
if kernel._activity_stream: | ||
kernel._activity_stream.close() | ||
kernel._activity_stream = None | ||
self.stop_buffering(kernel_id) | ||
self._kernel_connections.pop(kernel_id, None) | ||
self.last_kernel_activity = utcnow() | ||
|
||
# Decrease the metric of number of kernels | ||
# running for the relevant kernel type by 1 | ||
KERNEL_CURRENTLY_RUNNING_TOTAL.labels( | ||
type=self._kernels[kernel_id].kernel_name | ||
).dec() | ||
|
||
return super(MappingKernelManager, self).shutdown_kernel(kernel_id, now=now) | ||
|
||
def restart_kernel(self, kernel_id): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it really be a
..
here?