summaryrefslogtreecommitdiff
path: root/examples/py-flow-dashboard
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-02-05 15:09:21 +0100
committerToni Uhlig <matzeton@googlemail.com>2022-02-05 15:27:13 +0100
commitcb80c415d8a20b03f0d6a8f2fc38e8c8250a04da (patch)
tree70e53424c24795b3e9a159f8cfaa05e1630064a8 /examples/py-flow-dashboard
parent6fd6dff14d964aa8e5cf7ff3ec5a70c220ea61b4 (diff)
Improved py-flow-info to provide more optional information about received timestamps.
* py-flow-dashboard: Added color mapping for PieCharts/Graph that make more sense * nDPId: Renamed `flow_type' to a more precisely `flow_state' * nDPId: Changed the default setting to process only as much packets as libnDPI does Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples/py-flow-dashboard')
-rw-r--r--examples/py-flow-dashboard/assets/flow-dash.css3
-rwxr-xr-xexamples/py-flow-dashboard/flow-dash.py16
-rw-r--r--examples/py-flow-dashboard/plotly_dash.py65
3 files changed, 66 insertions, 18 deletions
diff --git a/examples/py-flow-dashboard/assets/flow-dash.css b/examples/py-flow-dashboard/assets/flow-dash.css
new file mode 100644
index 000000000..4d813b5ef
--- /dev/null
+++ b/examples/py-flow-dashboard/assets/flow-dash.css
@@ -0,0 +1,3 @@
+body {
+ background: black;
+}
diff --git a/examples/py-flow-dashboard/flow-dash.py b/examples/py-flow-dashboard/flow-dash.py
index 2e3ea3dcf..947f5b48c 100755
--- a/examples/py-flow-dashboard/flow-dash.py
+++ b/examples/py-flow-dashboard/flow-dash.py
@@ -81,6 +81,8 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us
shared_flow_dict[flow_id]['is_risky'] = False
shared_flow_dict[flow_id]['total-l4-bytes'] = 0
+ shared_flow_dict[flow_id]['json'] = mgr.dict()
+
shared_flow_dict['total-flows'] += 1
shared_flow_dict['current-flows'] += 1
@@ -93,11 +95,15 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us
shared_flow_dict['current-midstream-flows'] += 1
shared_flow_dict[flow_id]['is_midstream'] = True
- if 'ndpi' in json_dict and 'flow_risk' in json_dict['ndpi']:
- if shared_flow_dict[flow_id]['is_risky'] is False:
- shared_flow_dict['total-risky-flows'] += 1
- shared_flow_dict['current-risky-flows'] += 1
- shared_flow_dict[flow_id]['is_risky'] = True
+ if 'ndpi' in json_dict:
+ # XXX: Will make use of that JSON string in Plotly. Soon..
+ shared_flow_dict[flow_id]['json']['ndpi'] = json_dict['ndpi']
+
+ if 'flow_risk' in json_dict['ndpi']:
+ if shared_flow_dict[flow_id]['is_risky'] is False:
+ shared_flow_dict['total-risky-flows'] += 1
+ shared_flow_dict['current-risky-flows'] += 1
+ shared_flow_dict[flow_id]['is_risky'] = True
if 'flow_event_name' not in json_dict:
return True
diff --git a/examples/py-flow-dashboard/plotly_dash.py b/examples/py-flow-dashboard/plotly_dash.py
index c3ce95e12..3577776cf 100644
--- a/examples/py-flow-dashboard/plotly_dash.py
+++ b/examples/py-flow-dashboard/plotly_dash.py
@@ -70,11 +70,12 @@ def build_gauge(key, max_value=100):
return shared_flow_dict[key], gauge_max, grad_dict
-def build_piechart(labels, values):
+def build_piechart(labels, values, color_map=None):
lay = dict(
plot_bgcolor = '#082255',
paper_bgcolor = '#082255',
font={"color": "#fff"},
+ uirevision=True,
autosize=True,
height=250,
margin = {'autoexpand': True, 'b': 0, 'l': 0, 'r': 0, 't': 0, 'pad': 0},
@@ -83,7 +84,20 @@ def build_piechart(labels, values):
uniformtext_mode = 'hide',
)
- return go.Figure(layout=lay, data=[go.Pie(labels=labels, values=values, textinfo='percent', textposition='inside')])
+ return go.Figure(layout=lay, data=[go.Pie(labels=labels, values=values, sort=False, marker_colors=color_map, textinfo='percent', textposition='inside')])
+
+COLOR_MAP = {
+ 'piechart-flows': ['rgb(153, 153, 255)', 'rgb(153, 204, 255)', 'rgb(255, 204, 153)', 'rgb(255, 255, 255)'],
+ 'piechart-midstream-flows': ['rgb(255, 255, 153)', 'rgb(153, 153, 255)'],
+ 'piechart-risky-flows': ['rgb(255, 153, 153)', 'rgb(153, 153, 255)'],
+ 'graph-flows': {'Current Active Flows': {'color': 'rgb(153, 153, 255)', 'width': 1},
+ 'Current Risky Flows': {'color': 'rgb(255, 153, 153)', 'width': 3},
+ 'Current Midstream Flows': {'color': 'rgb(255, 255, 153)', 'width': 3},
+ 'Current Guessed Flows': {'color': 'rgb(153, 204, 255)', 'width': 1},
+ 'Current Not-Detected Flows': {'color': 'rgb(255, 204, 153)', 'width': 1},
+ 'Current Unclassified Flows': {'color': 'rgb(255, 255, 255)', 'width': 1},
+ },
+}
def generate_tab_flow():
return html.Div([
@@ -96,6 +110,14 @@ def generate_tab_flow():
id='table-info',
columns=[{'id': c.lower(), 'name': c, 'editable': False}
for c in ['Name', 'Total']],
+ style_header={
+ 'backgroundColor': '#082233',
+ 'color': 'white'
+ },
+ style_data={
+ 'backgroundColor': '#082244',
+ 'color': 'white'
+ },
)
], style={'display': 'flex', 'flex-direction': 'row'}),
@@ -107,7 +129,7 @@ def generate_tab_flow():
'displayModeBar': False,
},
figure=build_piechart(['Detected', 'Guessed', 'Not-Detected', 'Unclassified'],
- [0, 0, 0, 0]),
+ [0, 0, 0, 0], COLOR_MAP['piechart-flows']),
),
], style={'padding': 10, 'flex': 1}),
@@ -117,8 +139,8 @@ def generate_tab_flow():
config={
'displayModeBar': False,
},
- figure=build_piechart(['Not Midstream', 'Midstream'],
- [0, 0]),
+ figure=build_piechart(['Midstream', 'Not Midstream'],
+ [0, 0], COLOR_MAP['piechart-midstream-flows']),
),
], style={'padding': 10, 'flex': 1}),
@@ -128,8 +150,8 @@ def generate_tab_flow():
config={
'displayModeBar': False,
},
- figure=build_piechart(['Not Risky', 'Risky'],
- [0, 0]),
+ figure=build_piechart(['Risky', 'Not Risky'],
+ [0, 0], COLOR_MAP['piechart-risky-flows']),
),
], style={'padding': 10, 'flex': 1}),
], style=generate_box()),
@@ -142,7 +164,8 @@ def generate_tab_flow():
dcc.Graph(
id="graph-flows",
config={
- 'displayModeBar': False,
+ 'displayModeBar': True,
+ 'displaylogo': False,
},
style={'height':'60vh'},
),
@@ -227,15 +250,18 @@ def tab_flow_update_components(n):
shared_flow_dict['current-flows']
- shared_flow_dict['current-detected-flows']
- shared_flow_dict['current-guessed-flows']
- - shared_flow_dict['current-not-detected-flows']]),
+ - shared_flow_dict['current-not-detected-flows']],
+ COLOR_MAP['piechart-flows']),
build_piechart(['Midstream', 'Not Midstream'],
[shared_flow_dict['current-midstream-flows'],
shared_flow_dict['current-flows'] -
- shared_flow_dict['current-midstream-flows']]),
+ shared_flow_dict['current-midstream-flows']],
+ COLOR_MAP['piechart-midstream-flows']),
build_piechart(['Risky', 'Not Risky'],
[shared_flow_dict['current-risky-flows'],
shared_flow_dict['current-flows'] -
- shared_flow_dict['current-risky-flows']])]
+ shared_flow_dict['current-risky-flows']],
+ COLOR_MAP['piechart-risky-flows'])]
@app.callback(output=[Output('graph-flows', 'figure'),
Output('graph-traces', 'data')],
@@ -246,7 +272,7 @@ def tab_flow_update_graph(n, i, traces):
if traces is None:
traces = ([], [], [], [], [], [])
- max_bins = 50
+ max_bins = 100
traces[0].append(shared_flow_dict['current-flows'])
traces[1].append(shared_flow_dict['current-risky-flows'])
@@ -289,11 +315,12 @@ def tab_flow_update_graph(n, i, traces):
"tickmode": 'linear',
"dtick": 10,
},
+ uirevision=True,
autosize=True,
bargap=0.01,
bargroupgap=0,
hovermode="closest",
- margin = {'b': 0, 'l': 0, 'r': 0, 't': 0, 'pad': 0},
+ margin = {'b': 0, 'l': 0, 'r': 0, 't': 30, 'pad': 0},
legend = {'borderwidth': 0},
)
@@ -304,31 +331,43 @@ def tab_flow_update_graph(n, i, traces):
x=x,
y=traces[0],
name='Current Active Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Active Flows'],
))
fig.add_trace(go.Scatter(
x=x,
y=traces[1],
name='Current Risky Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Risky Flows'],
))
fig.add_trace(go.Scatter(
x=x,
y=traces[2],
name='Current Midstream Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Midstream Flows'],
))
fig.add_trace(go.Scatter(
x=x,
y=traces[3],
name='Current Guessed Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Guessed Flows'],
))
fig.add_trace(go.Scatter(
x=x,
y=traces[4],
name='Current Not-Detected Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Not-Detected Flows'],
))
fig.add_trace(go.Scatter(
x=x,
y=traces[5],
name='Current Unclassified Flows',
+ mode='lines+markers',
+ line=COLOR_MAP['graph-flows']['Current Unclassified Flows'],
))
return [fig, traces]