|
5 | 5 | conventions for metrics & labels.
|
6 | 6 | """
|
7 | 7 |
|
| 8 | +try: |
| 9 | + # Jupyter Notebook also defines these metrics. Re-defining them results in a ValueError. |
| 10 | + # Try to de-duplicate by using the ones in Notebook if available. |
| 11 | + # See https://github.com/jupyter/jupyter_server/issues/209 |
| 12 | + from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS, TERMINAL_CURRENTLY_RUNNING_TOTAL, KERNEL_CURRENTLY_RUNNING_TOTAL |
8 | 13 |
|
9 |
| -from prometheus_client import Histogram, Gauge |
| 14 | +except ImportError: |
10 | 15 |
|
| 16 | + from prometheus_client import Histogram, Gauge |
11 | 17 |
|
12 |
| -HTTP_REQUEST_DURATION_SECONDS = Histogram( |
13 |
| - 'http_request_duration_seconds', |
14 |
| - 'duration in seconds for all HTTP requests', |
15 |
| - ['method', 'handler', 'status_code'], |
16 |
| -) |
| 18 | + HTTP_REQUEST_DURATION_SECONDS = Histogram( |
| 19 | + 'http_request_duration_seconds', |
| 20 | + 'duration in seconds for all HTTP requests', |
| 21 | + ['method', 'handler', 'status_code'], |
| 22 | + ) |
17 | 23 |
|
18 |
| -TERMINAL_CURRENTLY_RUNNING_TOTAL = Gauge( |
19 |
| - 'terminal_currently_running_total', |
20 |
| - 'counter for how many terminals are running', |
21 |
| -) |
| 24 | + TERMINAL_CURRENTLY_RUNNING_TOTAL = Gauge( |
| 25 | + 'terminal_currently_running_total', |
| 26 | + 'counter for how many terminals are running', |
| 27 | + ) |
22 | 28 |
|
23 |
| -KERNEL_CURRENTLY_RUNNING_TOTAL = Gauge( |
24 |
| - 'kernel_currently_running_total', |
25 |
| - 'counter for how many kernels are running labeled by type', |
26 |
| - ['type'] |
27 |
| -) |
| 29 | + KERNEL_CURRENTLY_RUNNING_TOTAL = Gauge( |
| 30 | + 'kernel_currently_running_total', |
| 31 | + 'counter for how many kernels are running labeled by type', |
| 32 | + ['type'] |
| 33 | + ) |
0 commit comments