diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index c9eb5274..f9c8485b 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -759,6 +759,7 @@ class BaseHandler(RequestHandler): active_counts['spawn_pending'] + active_counts['proxy_pending'] ) active_count = active_counts['active'] + RUNNING_SERVERS.set(active_count) concurrent_spawn_limit = self.concurrent_spawn_limit active_server_limit = self.active_server_limit @@ -842,7 +843,6 @@ class BaseHandler(RequestHandler): "User %s took %.3f seconds to start", user_server_name, toc - tic ) self.statsd.timing('spawner.success', (toc - tic) * 1000) - RUNNING_SERVERS.inc() SERVER_SPAWN_DURATION_SECONDS.labels( status=ServerSpawnStatus.success ).observe(time.perf_counter() - spawn_start_time) @@ -854,6 +854,7 @@ class BaseHandler(RequestHandler): PROXY_ADD_DURATION_SECONDS.labels(status='success').observe( time.perf_counter() - proxy_add_start_time ) + RUNNING_SERVERS.inc() except Exception: self.log.exception("Failed to add %s to proxy!", user_server_name) self.log.error( @@ -1022,7 +1023,6 @@ class BaseHandler(RequestHandler): "User %s server took %.3f seconds to stop", user.name, toc - tic ) self.statsd.timing('spawner.stop', (toc - tic) * 1000) - RUNNING_SERVERS.dec() SERVER_STOP_DURATION_SECONDS.labels( status=ServerStopStatus.success ).observe(toc - tic) diff --git a/jupyterhub/metrics.py b/jupyterhub/metrics.py index 558167ff..27de7be6 100644 --- a/jupyterhub/metrics.py +++ b/jupyterhub/metrics.py @@ -39,9 +39,7 @@ RUNNING_SERVERS = Gauge( 'running_servers', 'the number of user servers currently running' ) -RUNNING_SERVERS.set(0) - -TOTAL_USERS = Gauge('total_users', 'toal number of users') +TOTAL_USERS = Gauge('total_users', 'total number of users') TOTAL_USERS.set(0) diff --git a/jupyterhub/user.py b/jupyterhub/user.py index 42dbcdf5..333175bb 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -21,6 +21,7 @@ from .crypto import decrypt from .crypto import encrypt from .crypto import EncryptionUnavailable from .crypto import InvalidToken +from .metrics import RUNNING_SERVERS from .metrics import TOTAL_USERS from .objects import Server from .spawner import LocalProcessSpawner @@ -753,6 +754,7 @@ class User: self.db.delete(oauth_client) self.db.commit() self.log.debug("Finished stopping %s", spawner._log_name) + RUNNING_SERVERS.dec() finally: spawner.orm_spawner.started = None self.db.commit()