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

separated matrix formatting to reuse it for containers.data

parent 48f10ddb
......@@ -3,7 +3,7 @@
from flask import Flask
from jinja2 import Environment, PackageLoader
from flowmatrix.flowlib import get_data_full, get_data
from flowmatrix.flowlib import *
import argparse
import os
......@@ -22,15 +22,19 @@ args = parser.parse_args()
e = Environment(loader=PackageLoader("flowmatrix", "../flowmatrix/templates/"))
@app.route("/api/containers")
def get_containers_data():
matrix = get_flow_matrix(args.influxdb_host, args.influxdb_port)
print(matrix)
return ""
@app.route("/")
def data():
matrix, svg = get_data(args.influxdb_host, args.influxdb_port)
return e.get_template("index.html").render(data=matrix.to_dict(), svg=svg)
matrix = get_flow_matrix(args.influxdb_host, args.influxdb_port)
svg = get_flow_matrix_svg(matrix)
formattted_matrix = format_flow_matrix(matrix)
return e.get_template("index.html").render(data=formattted_matrix.to_dict(), svg=svg)
@app.route("/full")
def data_full():
matrix, svg = get_data_full(args.influxdb_host, args.influxdb_port)
return e.get_template("index.html").render(data=matrix.to_dict(), svg=svg)
app.run(host="0.0.0.0", port=args.flow_matrix_port)
......@@ -50,7 +50,7 @@ def matrix_value(template, client, a, b):
return 0
def get_data(influxdb_host, influxdb_port, formatter=sizeof_fmt):
def get_flow_matrix(influxdb_host, influxdb_port):
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"'))[0] if
......@@ -60,9 +60,10 @@ def get_data(influxdb_host, influxdb_port, formatter=sizeof_fmt):
items=[(a, [matrix_value(query_template, client, a, b) for b in apps]) for a in apps],
columns=apps,
orient="index")
return matrix
print(matrix.to_csv())
def format_flow_matrix(matrix, formatter=sizeof_fmt):
matrix_mean = np.mean((matrix != 0).mean())
matrix_std = np.mean((matrix.std()))
......@@ -70,11 +71,13 @@ def get_data(influxdb_host, influxdb_port, formatter=sizeof_fmt):
col = sizeof_get_color(v, matrix_mean, matrix_std)
return (col, formatter(v))
svg = get_svg(matrix)
matrix = matrix.applymap(custo_formatter)
return matrix, svg
return matrix
def get_flow_matrix_svg(matrix):
return get_svg(matrix)
def get_data_full(influxdb_host, influxdb_port, formatter=sizeof_fmt):
......@@ -126,7 +129,8 @@ def get_svg(d):
return "red"
else:
return "red"
#Todo adapt for FULL page
# 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
......
Markdown is supported
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