Commit 07fdaef6 authored by Nicolas Herbaut's avatar Nicolas Herbaut
Browse files

building

parents
.venv2
.venv3
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from python:3.6-slim
COPY requirements-python3.txt /tmp/requirements-python3.txt
RUN pip install -r /tmp/requirements-python3.txt
COPY ./dist/Flow_Matrix_Web_page-0.0.3-py3.6.egg /tmp/Flow_Matrix_Web_page-0.0.3-py3.6.egg
RUN easy_install /tmp/Flow_Matrix_Web_page-0.0.3-py3.6.egg
all : clean build buildp2
clean: clean-build clean-pyc
clean-build:
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
install: clean
python setup.py install
build:
.venv3/bin/python setup.py bdist_egg
buildp2:
.venv2/bin/python setup.py bdist_egg
docker:
docker build . -t nherbaut/flowmatrix
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template
from flowmatrix.flowlib import get_data_full, get_data
app = Flask(__name__)
@app.route("/")
def data():
return render_template('./index.html', data=get_data())
@app.route("/full")
def data_full():
return render_template('./index.html', data=get_data_full())
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 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)
res = client.query(query)
if 'nftables' in res:
if 'value' in res["nftables"]:
return res["nftables"]['value'][0]
return 0
def get_data():
client = DataFrameClient("erods-ds-1.u-ga.fr", "8086", "", "", "telegraf")
df = pd.DataFrame(data=list(range(30)))
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")
return matrix.to_dict()
def get_data_full():
client = DataFrameClient("erods-ds-1.u-ga.fr", "8086", "", "", "telegraf")
df = pd.DataFrame(data=list(range(30)))
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
certifi==2017.11.5
chardet==3.0.4
click==6.7
Flask==0.12.2
idna==2.6
influxdb==5.0.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
numpy==1.13.3
pandas==0.21.0
python-dateutil==2.6.1
pytz==2017.3
requests==2.18.4
six==1.11.0
urllib3==1.22
Werkzeug==0.12.2
certifi==2017.11.5
chardet==3.0.4
click==6.7
Flask==0.12.2
idna==2.6
influxdb==5.0.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
numpy==1.13.3
pandas==0.21.0
python-dateutil==2.6.1
pytz==2017.3
requests==2.18.4
six==1.11.0
urllib3==1.22
Werkzeug==0.12.2
# -*- coding: utf-8 -*-
from setuptools import setup
from setuptools import find_packages
setup(
name='Flow Matrix Web page',
version='0.0.3',
description='print collected flow matrices from influxdb',
author='Nicolas Herbaut',
author_email='nicolas.herbaut@univ-grenoble-alpes.fr',
url='https://nextnet.top',
scripts=['bin/flow-matrix'],
install_requires=[
"chardet==3.0.4",
"click==6.7",
"Flask==0.12.2",
"idna==2.6",
"influxdb==5.0.0",
"itsdangerous==0.24",
"Jinja2==2.10",
"MarkupSafe==1.0",
"numpy",
"pandas==0.21.0",
"python-dateutil==2.6.1",
"pytz==2017.3",
"requests==2.18.4",
"six==1.11.0",
"urllib3==1.22",
"Werkzeug==0.12.2"],
packages=find_packages()
)
<html>
<header>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
</header>
<body>
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
{% for key1 in data %}
<th>{{ key1 }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for key1 in data %}
<tr>
<th scope="row">{{ key1 }}</th>
{% for key2 in data %}
<td>{{data[key1][key2] }}</td>
{% endfor %}
</tr>
{% endfor %}
</body>
</html>
\ No newline at end of file
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