diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index f21779bc..05dc497b 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -31,6 +31,7 @@ from ..utils import maybe_future, url_path_join from ..metrics import ( SERVER_SPAWN_DURATION_SECONDS, ServerSpawnStatus, PROXY_ADD_DURATION_SECONDS, ProxyAddStatus, + CURRENTLY_RUNNING_SERVERS ) # pattern for the authentication token header @@ -729,6 +730,7 @@ class BaseHandler(RequestHandler): toc = IOLoop.current().time() self.log.info("User %s took %.3f seconds to start", user_server_name, toc-tic) self.statsd.timing('spawner.success', (toc - tic) * 1000) + CURRENTLY_RUNNING_SERVERS.inc() SERVER_SPAWN_DURATION_SECONDS.labels( status=ServerSpawnStatus.success ).observe(time.perf_counter() - spawn_start_time) @@ -880,6 +882,7 @@ class BaseHandler(RequestHandler): toc = IOLoop.current().time() self.log.info("User %s server took %.3f seconds to stop", user.name, toc - tic) self.statsd.timing('spawner.stop', (toc - tic) * 1000) + CURRENTLY_RUNNING_SERVERS.dec() try: await gen.with_timeout(timedelta(seconds=self.slow_stop_timeout), stop()) diff --git a/jupyterhub/metrics.py b/jupyterhub/metrics.py index 68d6673e..a4ec3103 100644 --- a/jupyterhub/metrics.py +++ b/jupyterhub/metrics.py @@ -18,6 +18,7 @@ them manually here. from enum import Enum from prometheus_client import Histogram +from prometheus_client import Gauge REQUEST_DURATION_SECONDS = Histogram( 'request_duration_seconds', @@ -34,6 +35,13 @@ SERVER_SPAWN_DURATION_SECONDS = Histogram( buckets=[0.5, 1, 2.5, 5, 10, 15, 30, 60, 120, float("inf")] ) +CURRENTLY_RUNNING_SERVERS = Gauge( + 'currently_running_servers', + 'the number of user servers currently running', +) + +CURRENTLY_RUNNING_SERVERS.set(0) + class ServerSpawnStatus(Enum): """ Possible values for 'status' label of SERVER_SPAWN_DURATION_SECONDS