Commit 85a7c82c authored by Nicolas Herbaut's avatar Nicolas Herbaut
Browse files

prettier

parent 14b56728
from influxdb import DataFrameClient
import pandas as pd
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)"""
def sizeof_fmt(num, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if num == 0:
return ""
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
def matrix_value(template, client, a, b):
query = template % (a, b)
print(query)
......@@ -27,7 +26,7 @@ def matrix_value(template, client, a, b):
return 0
def get_data(influxdb_host,influxdb_port):
def get_data(influxdb_host, influxdb_port):
client = DataFrameClient(influxdb_host, influxdb_port, "", "", "telegraf")
df = pd.DataFrame(data=list(range(30)))
......@@ -35,13 +34,14 @@ def get_data(influxdb_host,influxdb_port):
apps = [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, [sizeof_fmt(matrix_value(query_template,client, a, b)) for b in apps]) for a in apps],
columns=apps,
orient="index")
matrix = pd.DataFrame.from_items(
items=[(a, [sizeof_fmt(matrix_value(query_template, client, a, b)) for b in apps]) for a in apps],
columns=apps,
orient="index")
return matrix.to_dict()
def get_data_full(influxdb_host,influxdb_port):
def get_data_full(influxdb_host, influxdb_port):
client = DataFrameClient(influxdb_host, influxdb_port, "", "", "telegraf")
df = pd.DataFrame(data=list(range(30)))
......@@ -49,7 +49,8 @@ def get_data_full(influxdb_host,influxdb_port):
apps = [app["value"] for app in list(client.query('SHOW TAG VALUES ON "telegraf" WITH KEY="host_app_src_port"'))[0]
if 'salt' not in app["value"]]
matrix = pd.DataFrame.from_items(items=[(a, [sizeof_fmt(matrix_value(query_template_full,client, a, b)) for b in apps]) for a in apps],
columns=apps,
orient="index")
return matrix.to_dict()
\ No newline at end of file
matrix = pd.DataFrame.from_items(
items=[(a, [sizeof_fmt(matrix_value(query_template_full, client, a, b)) for b in apps]) for a in apps],
columns=apps,
orient="index")
return matrix.to_dict()
......@@ -30,7 +30,7 @@
<th scope="row">{{ key1 }}</th>
{% for key2 in data %}
<td>{{data[key1][key2] }}</td>
<td>{{data[key2][key1]}}</td>
{% endfor %}
</tr>
......
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