Skip to content

Commit

Permalink
Return the kernels running and their details with the metrics API
Browse files Browse the repository at this point in the history
  • Loading branch information
GoelJatin committed Jul 7, 2018
1 parent 92e3542 commit a34cc7f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,26 @@ class PrometheusMetricsHandler(IPythonHandler):
@web.authenticated
def get(self):
self.set_header('Content-Type', prometheus_client.CONTENT_TYPE_LATEST)
self.write(
prometheus_client.generate_latest(prometheus_client.REGISTRY)
)
metrics = prometheus_client.generate_latest(prometheus_client.REGISTRY)
all_kernels = self.kernel_manager.list_kernels()

kernels = "\nList of all Kernels: \n\n"
for kernel in all_kernels:
kernels = (
"{kernels}\tNAME: {name}\n\t\tSTATE: {state}"
"\n\t\tLast Activity: {last_activity}\n\n"
).format(
kernels=kernels,
name=kernel.get("name", "NO NAME"),
state=kernel.get(
"execution_state", "Failed to get the connection state"
),
last_activity=kernel.get(
"last_activity", "Failed to get the last activity time"
)
)

self.write(metrics + kernels.encode())


#-----------------------------------------------------------------------------
Expand Down

0 comments on commit a34cc7f

Please sign in to comment.