Add prometheus metric to measure hub startup time (#2799)

Add prometheus metric to measure hub startup time
This commit is contained in:
Min RK
2019-12-03 13:19:51 +01:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -85,6 +85,8 @@ from .utils import (
print_ps_info,
make_ssl_context,
)
from .metrics import HUB_STARTUP_DURATION_SECONDS
from .metrics import INIT_SPAWNERS_DURATION_SECONDS
from .metrics import RUNNING_SERVERS
from .metrics import TOTAL_USERS
@@ -2220,6 +2222,7 @@ class JupyterHub(Application):
@catch_config_error
async def initialize(self, *args, **kwargs):
hub_startup_start_time = time.perf_counter()
super().initialize(*args, **kwargs)
if self.generate_config or self.generate_certs or self.subapp:
return
@@ -2292,14 +2295,20 @@ class JupyterHub(Application):
def log_init_time(f):
n_spawners = f.result()
spawner_initialization_time = time.perf_counter() - init_start_time
INIT_SPAWNERS_DURATION_SECONDS.observe(spawner_initialization_time)
self.log.info(
"Initialized %i spawners in %.3f seconds",
n_spawners,
time.perf_counter() - init_start_time,
spawner_initialization_time,
)
init_spawners_future.add_done_callback(log_init_time)
HUB_STARTUP_DURATION_SECONDS.observe(
time.perf_counter() - hub_startup_start_time
)
try:
# don't allow a zero timeout because we still need to be sure

View File

@@ -45,6 +45,14 @@ CHECK_ROUTES_DURATION_SECONDS = Histogram(
'check_routes_duration_seconds', 'Time taken to validate all routes in proxy'
)
HUB_STARTUP_DURATION_SECONDS = Histogram(
'hub_startup_duration_seconds', 'Time taken for Hub to start'
)
INIT_SPAWNERS_DURATION_SECONDS = Histogram(
'init_spawners_duration_seconds', 'Time taken for spawners to initialize'
)
PROXY_POLL_DURATION_SECONDS = Histogram(
'proxy_poll_duration_seconds', 'duration for polling all routes from proxy'
)