Update generate_html
This commit is contained in:
parent
1f3cf30127
commit
44b6a8b450
@ -1,30 +1,84 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
|
|
||||||
TABLE_NAME = "stats"
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
INTERVALS = [50, 100, 1000] # on cron interval is 10min
|
HERE = Path(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
|
TABLE_NAME = "dc_stats"
|
||||||
|
INTERVALS = [1] # on cron interval is 10min
|
||||||
|
|
||||||
|
|
||||||
# Create your connection.
|
def parse_args():
|
||||||
cnx = sqlite3.connect('data.sqlite')
|
parser = argparse.ArgumentParser(description="Extract docker stats in a sqlite db")
|
||||||
|
|
||||||
df = pd.read_sql_query(f"SELECT * FROM {TABLE_NAME}", cnx)
|
parser.add_argument(
|
||||||
df = df.set_index("date")
|
"sqlite",
|
||||||
print(f"Find {len(df)} items")
|
nargs="?",
|
||||||
|
type=Path,
|
||||||
|
help="Path to sqlite file",
|
||||||
|
default=HERE / "stats.sqlite",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"html",
|
||||||
|
nargs="?",
|
||||||
|
type=Path,
|
||||||
|
help="Path to sqlite file",
|
||||||
|
default=HERE / "stats.html",
|
||||||
|
)
|
||||||
|
parser.add_argument("--debug", "-d", action="store_true", help="Run in debug mode")
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args.sqlite, args.html, args.debug
|
||||||
|
|
||||||
df["granu"] = 1
|
|
||||||
|
|
||||||
dfs = pd.DataFrame()
|
def generate_html_report(sqlite_fn: Path, html_fn: Path):
|
||||||
for i in INTERVALS:
|
# Create your connection.
|
||||||
dfi = df[::i].copy()
|
cnx = sqlite3.connect(sqlite_fn)
|
||||||
dfi["granu"] = i
|
|
||||||
dfs = dfs.append(dfi)
|
|
||||||
|
|
||||||
print(f"Find {len(dfs)} items")
|
df = pd.read_sql_query(f"SELECT * FROM {TABLE_NAME}", cnx)
|
||||||
fig = px.area(dfs, title="Wide-Form Input", animation_frame="granu")
|
df = df.set_index("date")
|
||||||
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
log.info(f"Find {len(df)} items")
|
||||||
fig["layout"].pop("updatemenus") # optional, drop animation buttons
|
|
||||||
fig.update_layout(transition = {'duration': 1e12})
|
# df["granu"] = 1
|
||||||
fig.write_html("stats.html", include_plotlyjs="cdn")
|
|
||||||
|
dfs = pd.DataFrame()
|
||||||
|
for i in INTERVALS:
|
||||||
|
dfi = df[::i].copy()
|
||||||
|
breakpoint()
|
||||||
|
# dfi["granu"] = i
|
||||||
|
dfs = dfs.append(dfi)
|
||||||
|
|
||||||
|
log.info(f"Find {len(dfs)} items")
|
||||||
|
fig = px.area(dfs)
|
||||||
|
fig.for_each_trace(lambda trace: trace.update(fillcolor=trace.line.color))
|
||||||
|
fig["layout"].pop("updatemenus") # optional, drop animation buttons
|
||||||
|
fig.update_layout(transition={"duration": 1e12})
|
||||||
|
fig.update_layout(
|
||||||
|
title="Utilisation de RAM pour les docker-compose de l'eunuque"
|
||||||
|
" (pour voir une stat, mettre la sourie sur le haut des courbes,"
|
||||||
|
" vers les points)",
|
||||||
|
xaxis_title="Temps",
|
||||||
|
yaxis_title="RAM",
|
||||||
|
)
|
||||||
|
fig.write_html(html_fn, include_plotlyjs="cdn")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sqlite_fn, html_fn, debug = parse_args()
|
||||||
|
if debug:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
else:
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
generate_html_report(sqlite_fn, html_fn)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user