Commit e9c44f5c authored by Nicolas Herbaut's avatar Nicolas Herbaut
Browse files

full page support

parent 1efcabb3
all : clean build docker-build
all : clean build docker-build
clean: clean-build clean-pyc
......@@ -26,5 +26,5 @@ build:
docker-build:
docker build . -t nherbaut/flowmatrix
docker-push:
push:
docker push nherbaut/flowmatrix
......@@ -27,7 +27,8 @@ def data():
@app.route("/full")
def data_full():
return render_template('index.html', data=get_data_full(args.influxdb_host, args.influxdb_port).to_dict())
matrix, svg = get_data_full(args.influxdb_host, args.influxdb_port)
return render_template('index.html', data=matrix.to_dict(), svg=svg)
app.template_folder = "/usr/local/lib/python3.6/site-packages/Flow_Matrix_Web_page-0.0.3-py3.6.egg/flowmatrix/templates/"
......
......@@ -3,6 +3,7 @@ import pandas as pd
import numpy as np
import networkx as nx
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
......@@ -14,16 +15,19 @@ to_blue = list(white.range_to(Color("blue"), 10))
to_red = list(white.range_to(Color("red"), 10))
query_template = """SELECT last("bytes") as value FROM "telegraf"."autogen"."nftables" WHERE time > now() - 1h AND "host_app_dst"='%s' AND "host_app_src"='%s' GROUP BY time(10w) FILL(null)"""
query_template_full = """SELECT last("bytes") as value FROM "telegraf"."autogen"."nftables" WHERE time > now() - 1h AND "host_app_dst_port"='%s' AND "host_app_src_port"='%s' GROUP BY time(10w) FILL(null)"""
query_template_full = """SELECT last("bytes") as value FROM "telegraf"."autogen"."nftables" WHERE time > now() - 1h AND "host_app_dst_port"='%s' AND "host_app_src"='%s' GROUP BY time(10w) FILL(null)"""
def sizeof_get_color(num, matrix_mean=0, std_dev=999999999999):
if num < matrix_mean:
col = to_blue[min(int(abs(num - matrix_mean) / std_dev), len(to_blue) - 1)]
else:
col = to_red[min(int(abs(num - matrix_mean) / std_dev), len(to_red) - 1)]
try:
if num < matrix_mean:
col = to_blue[min(int(abs(num - matrix_mean) / std_dev), len(to_blue) - 1)]
else:
col = to_red[min(int(abs(num - matrix_mean) / std_dev), len(to_red) - 1)]
return col.get_web()
return col.get_web()
except:
return white.get_web()
def sizeof_fmt(num, suffix='B'):
......@@ -76,12 +80,15 @@ def get_data(influxdb_host, influxdb_port, formatter=sizeof_fmt):
def get_data_full(influxdb_host, influxdb_port, formatter=sizeof_fmt):
client = DataFrameClient(influxdb_host, influxdb_port, "", "", "telegraf")
apps = [app["value"] for app in list(client.query('SHOW TAG VALUES ON "telegraf" WITH KEY="host_app_src_port"'))[0]
apps = [app["value"] for app in list(client.query('SHOW TAG VALUES ON "telegraf" WITH KEY="host_app_dst_port"'))[0]
if 'salt' not in app["value"]]
apps2 = [app["value"] for app in list(client.query('SHOW TAG VALUES ON "telegraf" WITH KEY="host_app_src"'))[0] if
'salt' not in app["value"]]
matrix = pd.DataFrame.from_items(
items=[(a, [matrix_value(query_template_full, client, a, b) for b in apps]) for a in apps],
columns=apps,
items=[(a, [matrix_value(query_template, client, a, b) for b in apps2]) for a in apps],
columns=apps2,
orient="index")
svg = get_svg(matrix)
......@@ -98,23 +105,28 @@ def get_svg(d):
d.apply(lambda x: 1 / x)
def sizeof_get_color(num, matrix_mean=0, std_dev=999999999999):
if num < matrix_mean:
col = to_blue[min(int(abs(num - matrix_mean) / std_dev), len(to_blue) - 1)]
else:
col = to_red[min(int(abs(num - matrix_mean) / std_dev), len(to_red) - 1)]
return col.get_web(), (num - matrix_mean) / std_dev
try:
if num < matrix_mean:
col = to_blue[min(int(abs(num - matrix_mean) / std_dev), len(to_blue) - 1)]
else:
col = to_red[min(int(abs(num - matrix_mean) / std_dev), len(to_red) - 1)]
return col.get_web(), min(max((num - matrix_mean) / std_dev, 1), 15)
except:
return black.get_web(), 1
def type_to_col(name_full):
name = name_full.split("_")[-1]
if name == "cass":
return "green"
if name == "zoo":
elif name == "zoo":
return "gray"
if name == "kafka":
elif name == "kafka":
return "blue"
if name == "spark":
elif name == "spark":
return "red"
else:
return "red"
#Todo adapt for FULL page
upper = d.where(~np.tril(np.ones(d.shape)).astype(np.bool))
bottom = d.transpose().where(~np.tril(np.ones(d.shape)).astype(np.bool))
bc = upper + bottom
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment