Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add real-time CPU utilization plot to dashboard #2922

Merged
merged 2 commits into from Aug 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions distributed/dashboard/scheduler.py
Expand Up @@ -18,6 +18,7 @@
Range1d,
Plot,
Quad,
Span,
value,
LinearAxis,
NumeralTickFormatter,
Expand Down Expand Up @@ -309,6 +310,8 @@ def __init__(self, scheduler, width=600, **kwargs):
"nbytes": [1, 2],
"nbytes-half": [0.5, 1],
"nbytes_text": ["1B", "2B"],
"cpu": [1, 2],
"cpu-half": [0.5, 1],
"worker": ["a", "b"],
"y": [1, 2],
"nbytes-color": ["blue", "blue"],
Expand Down Expand Up @@ -353,6 +356,33 @@ def __init__(self, scheduler, width=600, **kwargs):
)
rect.nonselection_glyph = None

cpu = figure(
title="CPU Utilization",
tools="",
id="bk-cpu-worker-plot",
width=int(width / 2),
name="cpu_hist",
**kwargs
)
rect = cpu.rect(
source=self.source,
x="cpu-half",
y="y",
width="cpu",
height=1,
color="blue",
)
rect.nonselection_glyph = None
uine = cpu.line(x=[100, 100], y=[0, 1], color="gray")
mrocklin marked this conversation as resolved.
Show resolved Hide resolved
hundred_span = Span(
location=100,
dimension="height",
line_color="gray",
line_dash="dashed",
line_width=3,
)
cpu.add_layout(hundred_span)

nbytes.axis[0].ticker = BasicTicker(mantissas=[1, 256, 512], base=1024)
nbytes.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
nbytes.xaxis.major_label_orientation = -math.pi / 12
Expand Down Expand Up @@ -382,17 +412,27 @@ def __init__(self, scheduler, width=600, **kwargs):
hover.point_policy = "follow_mouse"
nbytes.add_tools(hover)

hover = HoverTool()
hover.tooltips = "@worker : @cpu %"
hover.point_policy = "follow_mouse"
cpu.add_tools(hover)

self.processing_figure = processing
self.nbytes_figure = nbytes
self.cpu_figure = cpu

processing.y_range = nbytes.y_range
cpu.y_range = nbytes.y_range

@without_property_validation
def update(self):
with log_errors():
workers = list(self.scheduler.workers.values())

y = list(range(len(workers)))

cpu = [int(ws.metrics["cpu"]) for ws in workers]

nprocessing = [len(ws.processing) for ws in workers]
processing_color = []
for ws in workers:
Expand Down Expand Up @@ -427,6 +467,8 @@ def update(self):
if any(nprocessing) or self.last + 1 < now:
self.last = now
result = {
"cpu": cpu,
"cpu-half": [c / 2 for c in cpu],
"nprocessing": nprocessing,
"nprocessing-half": [np / 2 for np in nprocessing],
"nprocessing-color": processing_color,
Expand Down Expand Up @@ -1495,6 +1537,14 @@ def individual_nbytes_doc(scheduler, extra, doc):
doc.theme = BOKEH_THEME


def individual_cpu_doc(scheduler, extra, doc):
current_load = CurrentLoad(scheduler, sizing_mode="stretch_both")
current_load.update()
add_periodic_callback(doc, current_load, 100)
doc.add_root(current_load.cpu_figure)
doc.theme = BOKEH_THEME


def individual_nprocessing_doc(scheduler, extra, doc):
current_load = CurrentLoad(scheduler, sizing_mode="stretch_both")
current_load.update()
Expand Down Expand Up @@ -1619,6 +1669,7 @@ def __init__(self, scheduler, io_loop=None, prefix="", **kwargs):
"/individual-profile": individual_profile_doc,
"/individual-profile-server": individual_profile_server_doc,
"/individual-nbytes": individual_nbytes_doc,
"/individual-cpu": individual_cpu_doc,
"/individual-nprocessing": individual_nprocessing_doc,
"/individual-workers": individual_workers_doc,
}
Expand Down