Issue #13 Outreachy: add running_servers metric

This commit is contained in:
GeorgianaElena
2018-09-23 18:31:37 +03:00
parent e9753fd65d
commit 493f9ab331
2 changed files with 11 additions and 0 deletions

View File

@@ -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())

View File

@@ -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