-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfasthtml-dashboard.py
54 lines (35 loc) · 1.27 KB
/
fasthtml-dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
from fasthtml.common import Title, fast_app, serve
from fh_plotly import plotly2fasthtml, plotly_headers
from utils import get_enabled_dagster_jobs, plot_time_series
from anomstack.config import specs
from anomstack.jinja.render import render
from anomstack.sql.read import read_sql
log = logging.getLogger("fasthtml")
app, rt = fast_app(hdrs=(plotly_headers,))
@app.get('/')
def home():
# get enabled jobs from Dagster
enabled_jobs = get_enabled_dagster_jobs()
figs = []
# loop through metric batches
for i, metric_batch in enumerate(specs, start=1):
if i > 3:
break
# check if the job is enabled
if f'{metric_batch}_ingest' in enabled_jobs:
spec = specs[metric_batch]
sql = render("dashboard_sql", spec, params={"alert_max_n": 90})
db = spec["db"]
df = read_sql(sql, db=db)
for metric_name in df["metric_name"].unique():
metric_df = df[df["metric_name"] == metric_name]
fig = plotly2fasthtml(plot_time_series(metric_df, metric_name))
figs.append(fig)
else:
log.debug(f"job {metric_batch}_ingest is not enabled.")
return (
Title("Anomstack"),
figs
)
serve()