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

Prevent re-definition of prometheus metrics #210

Merged
merged 3 commits into from
Apr 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']
)