-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc4a091
commit 60d710f
Showing
13 changed files
with
1,052 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Creating interactive dashboards | ||
_______________________________ | ||
|
||
.. notebook:: holoviews ../../examples/user_guide/15-Dashboards.ipynb | ||
.. notebook:: holoviews ../../examples/user_guide/16-Dashboards.ipynb | ||
:skip_execute: True | ||
:offset: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Working with Streaming Data | ||
___________________________ | ||
|
||
.. notebook:: holoviews ../../examples/user_guide/15-Streaming_Data.ipynb | ||
:skip_execute: True | ||
:offset: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import datetime as dt | ||
|
||
import psutil | ||
import pandas as pd | ||
import holoviews as hv | ||
|
||
hv.extension('bokeh') | ||
|
||
# Define functions to get memory and CPU usage | ||
def get_mem_data(): | ||
vmem = psutil.virtual_memory() | ||
df = pd.DataFrame(dict(free=vmem.free/vmem.total, | ||
used=vmem.used/vmem.total), | ||
index=[pd.Timestamp.now()]) | ||
return df*100 | ||
|
||
def get_cpu_data(): | ||
cpu_percent = psutil.cpu_percent(percpu=True) | ||
df = pd.DataFrame(list(enumerate(cpu_percent)), | ||
columns=['CPU', 'Utilization']) | ||
df['time'] = pd.Timestamp.now() | ||
return df | ||
|
||
|
||
# Define DynamicMap callbacks returning Elements | ||
|
||
def mem_stack(data): | ||
data = pd.melt(data, 'index', var_name='Type', value_name='Usage') | ||
areas = hv.Dataset(data).to(hv.Area, 'index', 'Usage') | ||
return hv.Area.stack(areas.overlay()).relabel('Memory') | ||
|
||
def cpu_box(data): | ||
return hv.BoxWhisker(data, 'CPU', 'Utilization').relabel('CPU Usage') | ||
|
||
|
||
# Set up StreamingDataFrame and add async callback | ||
|
||
cpu_stream = hv.streams.Buffer(get_cpu_data(), 800, index=False) | ||
mem_stream = hv.streams.Buffer(get_mem_data()) | ||
|
||
def cb(): | ||
cpu_stream.send(get_cpu_data()) | ||
mem_stream.send(get_mem_data()) | ||
|
||
|
||
# Define DynamicMaps and display plot | ||
|
||
cpu_dmap = hv.DynamicMap(cpu_box, streams=[cpu_stream]) | ||
mem_dmap = hv.DynamicMap(mem_stack, streams=[mem_stream]) | ||
|
||
cpu_opts = {'plot': dict(width=500, height=400, color_index='CPU'), | ||
'style': dict(box_fill_color=hv.Cycle('Category20'))} | ||
mem_opts = dict(height=400, width=400) | ||
|
||
plot = (cpu_dmap.redim.range(Utilization=(0, 100)).opts(**cpu_opts) + | ||
mem_dmap.redim.range(Usage=(0, 100)).opts(plot=mem_opts)) | ||
|
||
|
||
# Render plot and attach periodic callback | ||
|
||
doc = hv.renderer('bokeh').server_doc(plot) | ||
doc.add_periodic_callback(cb, 0.05) |
Oops, something went wrong.