Skip to content

Commit

Permalink
Prevent re-definition of prometheus metrics (jupyter-server#210)
Browse files Browse the repository at this point in the history
* Prevent re-definition of prometheus metrics
  • Loading branch information
blink1073 committed Apr 25, 2020
1 parent 3ff4ad3 commit c0de313
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions jupyter_server/prometheus/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
conventions for metrics & labels.
"""

try:
# Jupyter Notebook also defines these metrics. Re-defining them results in a ValueError.
# Try to de-duplicate by using the ones in Notebook if available.
# See https://github.com/jupyter/jupyter_server/issues/209
from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS, TERMINAL_CURRENTLY_RUNNING_TOTAL, KERNEL_CURRENTLY_RUNNING_TOTAL

from prometheus_client import Histogram, Gauge
except ImportError:

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'],
)
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',
)
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']
)
KERNEL_CURRENTLY_RUNNING_TOTAL = Gauge(
'kernel_currently_running_total',
'counter for how many kernels are running labeled by type',
['type']
)

0 comments on commit c0de313

Please sign in to comment.