-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatch-mlcp.py
58 lines (49 loc) · 2.24 KB
/
watch-mlcp.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
55
56
57
58
import re
import time
import datetime
import shutil
import asciichartpy as acp
# 24/05/13 19:57:56 INFO contentpump.LocalJobRunner: completed 0%
WARNING_TIME = 240
offset = datetime.timedelta(hours=4)
line_parser = re.compile('([0-9/]+) ([0-9:]+) INFO contentpump.LocalJobRunner:\s+completed ([0-9%]+)')
with open('nohup.out') as fh:
finished = False
percents = []
while not finished:
lines = fh.readlines()
for l in lines:
if "completed" in l:
m = line_parser.match(l)
(d, t, p) = m.groups()
(yy,mm,dd) = d.split('/')
dts = f"20{yy}-{mm}-{dd}T{t}"
dt = datetime.datetime.fromisoformat(dts)
percents.append((dt, p))
if len(percents) > 1:
prev = percents[-1][0]
diff = dt - prev
if diff.seconds > WARNING_TIME:
print(f" *** Took {diff.seconds} seconds for mark {p} ***")
x = list(range(len(percents)))
y = []
ts = shutil.get_terminal_size()
lines = ts.lines
for idx in range(1,len(percents)):
diff = percents[idx][0]-percents[idx-1][0]
y.append(diff.seconds)
maxes = [WARNING_TIME]*len(percents)
running = []
for idx in range(1,len(percents)):
running.append(sum(y[:idx])/idx)
print(acp.plot([y, maxes, running], {'height':lines-6, 'colors':[acp.green, acp.red, acp.yellow]}))
print(f"{' '*11}{''.join([str(x)*10 for x in range(10)])}")
print(f"{' '*11}{''.join([str(x) for x in range(10)])*10}")
pint = int(p.strip()[:-1])
left = 100-pint
expected = left * running[-1]
when = datetime.datetime.now() - offset + datetime.timedelta(seconds=expected)
print(f"Key: Green=Seconds/Percent;Yellow=Average;Red=Too Slow || Done {p}: finish at average rate: {when.isoformat()}")
if p == "100%":
finished = True
time.sleep(60)