Merge pull request #4967 from kireetb/main

Allow configuration of bucket sizes in metrics - #4833
This commit is contained in:
Min RK
2025-03-19 13:29:24 +01:00
committed by GitHub
2 changed files with 33 additions and 1 deletions

View File

@@ -33,6 +33,16 @@ export JUPYTERHUB_METRICS_PREFIX=jupyterhub_prod
would result in the metric `jupyterhub_prod_active_users`, etc. would result in the metric `jupyterhub_prod_active_users`, etc.
## Customizing spawn bucket sizes
As of JupyterHub 5.3, override `JUPYTERHUB_SERVER_SPAWN_DURATION_SECONDS_BUCKETS` env variable in Hub's environment to allow custom bucket sizes. Otherwise default to, [0.5, 1, 2.5, 5, 10, 15, 30, 60, 120, 180, 300, 600, float("inf")]
For example,
```bash
export JUPYTERHUB_SERVER_SPAWN_DURATION_SECONDS_BUCKETS="1,2,4,6,12,30,60,120"
```
## Configuring metrics ## Configuring metrics
```{eval-rst} ```{eval-rst}

View File

@@ -37,6 +37,28 @@ from . import orm
from .utils import utcnow from .utils import utcnow
metrics_prefix = os.getenv('JUPYTERHUB_METRICS_PREFIX', 'jupyterhub') metrics_prefix = os.getenv('JUPYTERHUB_METRICS_PREFIX', 'jupyterhub')
_env_buckets = os.environ.get(
'JUPYTERHUB_SERVER_SPAWN_DURATION_SECONDS_BUCKETS', ""
).strip()
if _env_buckets:
spawn_duration_buckets = [float(_s) for _s in _env_buckets.split(",")]
else:
spawn_duration_buckets = [
0.5,
1,
2.5,
5,
10,
15,
30,
60,
120,
180,
300,
600,
float("inf"),
]
REQUEST_DURATION_SECONDS = Histogram( REQUEST_DURATION_SECONDS = Histogram(
'request_duration_seconds', 'request_duration_seconds',
@@ -51,7 +73,7 @@ SERVER_SPAWN_DURATION_SECONDS = Histogram(
['status'], ['status'],
# Use custom bucket sizes, since the default bucket ranges # Use custom bucket sizes, since the default bucket ranges
# are meant for quick running processes. Spawns can take a while! # are meant for quick running processes. Spawns can take a while!
buckets=[0.5, 1, 2.5, 5, 10, 15, 30, 60, 120, 180, 300, 600, float("inf")], buckets=spawn_duration_buckets,
namespace=metrics_prefix, namespace=metrics_prefix,
) )