mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 13:33:00 +00:00

This patch introduces Prometheus for exposing metrics about JupyterHub's operation. We expose a standard /metrics endpoint that can be queried without authentication. We take on prometheus_client as an unconditional dependency to both simplify code & because it is a pure python package with no dependencies itself. The first pass adds 'RED' style metrics for all HTTP requests. http://rancher.com/red-method-for-prometheus-3-key-metrics-for-monitoring/ has some info on the RED method, but to summarize: For each request type, record at least 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. This instantly gives us a lot of useful metrics in a very compact form.
18 lines
428 B
Python
18 lines
428 B
Python
from prometheus_client import REGISTRY, CONTENT_TYPE_LATEST, generate_latest
|
|
from tornado import gen
|
|
|
|
from .base import BaseHandler
|
|
|
|
class MetricsHandler(BaseHandler):
|
|
"""
|
|
Handler to serve Prometheus metrics
|
|
"""
|
|
@gen.coroutine
|
|
def get(self):
|
|
self.set_header('Content-Type', CONTENT_TYPE_LATEST)
|
|
self.write(generate_latest(REGISTRY))
|
|
|
|
default_handlers = [
|
|
(r'/metrics$', MetricsHandler)
|
|
]
|