tiz.io
05/01/2020, 6:49 PMJenny
05/01/2020, 6:51 PMJoe Schmid
05/01/2020, 7:05 PMfrom datetime import datetime, timedelta
from dateutil import parser
import prefect
c = prefect.Client()
r = c.graphql(
"""
query {
flow_run(where: {
_and: {
flow_id: {
_eq: "<your flow id>"
}
}
}, order_by: {
scheduled_start_time: desc
}) {
id
duration
scheduled_start_time,
start_time,
state
}
}
"""
)
flow_runs = r["data"]["flow_run"]
total_d = 0
total_st = 0
st_iterations = 0
states = {}
for fr in flow_runs:
states[fr["state"]] = states.get(fr["state"], 0) + 1
if fr["state"] != "Success":
continue
dstr = fr["duration"]
d = 0
if dstr:
t = datetime.strptime(dstr, "%H:%M:%S.%f")
delta = timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
d = delta.total_seconds()
total_d += d
sst = fr["scheduled_start_time"]
st = fr["start_time"]
if sst and st:
sstd = parser.isoparse(sst)
std = parser.isoparse(st)
delta = std - sstd
total_st += delta.total_seconds()
st_iterations += 1
print("Flow runs: {}".format(len(flow_runs)))
print("Valid runs: {}".format(st_iterations))
avg_duration = total_d / st_iterations
print("Average duration: {} seconds".format(round(avg_duration, 2)))
avg_startup_latency = total_st / st_iterations
print("Average startup latency: {} minutes".format(round(avg_startup_latency / 60, 2)))
print("State counts: {}".format(states))
Jenny
05/01/2020, 7:16 PMtiz.io
05/01/2020, 7:30 PMJenny
05/01/2020, 7:40 PMtiz.io
05/01/2020, 9:25 PMJenny
05/01/2020, 9:38 PM