mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
Moved the 'metrics' file to a new package named 'promethues'.
Then split the file into two files, one containing the metrics themselves, the other containing any function that have something to do with prometheus. Finally, Added new metrics into the prometheus.metrics file that represent the number of running terminals and added the functionality for that metric to be recorded in the terminal.api_handlers file.
This commit is contained in:
parent
d772277c0b
commit
03e5dc00e1
@ -7,7 +7,8 @@
|
||||
|
||||
import json
|
||||
from tornado.log import access_log
|
||||
from .metrics import prometheus_log_method
|
||||
from .prometheus.log_functions import prometheus_log_method
|
||||
|
||||
|
||||
def log_request(handler):
|
||||
"""log a bit more information about each request than tornado's default
|
||||
|
0
notebook/prometheus/__init__.py
Normal file
0
notebook/prometheus/__init__.py
Normal file
@ -1,18 +1,5 @@
|
||||
"""
|
||||
Prometheus metrics exported by Jupyter Notebook Server
|
||||
from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS
|
||||
|
||||
Read https://prometheus.io/docs/practices/naming/ for naming
|
||||
conventions for metrics & labels.
|
||||
"""
|
||||
|
||||
from prometheus_client import Histogram
|
||||
|
||||
# This is a fairly standard name for HTTP duration latency reporting
|
||||
HTTP_REQUEST_DURATION_SECONDS = Histogram(
|
||||
'http_request_duration_seconds',
|
||||
'duration in seconds for all HTTP requests',
|
||||
['method', 'handler', 'status_code'],
|
||||
)
|
||||
|
||||
def prometheus_log_method(handler):
|
||||
"""
|
21
notebook/prometheus/metrics.py
Normal file
21
notebook/prometheus/metrics.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""
|
||||
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',
|
||||
)
|
@ -1,7 +1,8 @@
|
||||
import json
|
||||
from tornado import web, gen
|
||||
from ..base.handlers import APIHandler
|
||||
from ..utils import url_path_join
|
||||
from notebook.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL
|
||||
|
||||
|
||||
class TerminalRootHandler(APIHandler):
|
||||
@web.authenticated
|
||||
@ -9,12 +10,16 @@ class TerminalRootHandler(APIHandler):
|
||||
tm = self.terminal_manager
|
||||
terms = [{'name': name} for name in tm.terminals]
|
||||
self.finish(json.dumps(terms))
|
||||
TERMINAL_CURRENTLY_RUNNING_TOTAL.set(
|
||||
len(terms)
|
||||
)
|
||||
|
||||
@web.authenticated
|
||||
def post(self):
|
||||
"""POST /terminals creates a new terminal and redirects to it"""
|
||||
name, _ = self.terminal_manager.new_named_terminal()
|
||||
self.finish(json.dumps({'name': name}))
|
||||
TERMINAL_CURRENTLY_RUNNING_TOTAL.inc()
|
||||
|
||||
|
||||
class TerminalHandler(APIHandler):
|
||||
@ -36,5 +41,6 @@ class TerminalHandler(APIHandler):
|
||||
yield tm.terminate(name, force=True)
|
||||
self.set_status(204)
|
||||
self.finish()
|
||||
TERMINAL_CURRENTLY_RUNNING_TOTAL.dec(1)
|
||||
else:
|
||||
raise web.HTTPError(404, "Terminal not found: %r" % name)
|
||||
|
Loading…
Reference in New Issue
Block a user