-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_show_compactions_python2.py
executable file
·61 lines (55 loc) · 2.21 KB
/
parse_show_compactions_python2.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
59
60
61
#!/usr/bin/python2
import datetime
import fileinput
def parse_file():
global activeWorkers
global waitingCompactions
'''
split line looks like:
['', ' 1440816 ', ' dbname ', ' tblname ', ' partname ', ' MAJOR ', ' failed ', ' hostname ', ' 1583272973000 ', ' 0 ', ' None ', '\n']
'''
for line in fileinput.input():
if "|" not in line or "compactionid" in line or "Start Time" in line:
continue
lineContents = line.split("|")
dbname = lineContents[2].strip()
tablename= lineContents[3].strip()
partition = lineContents[4].strip()
compactionType = lineContents[5].strip()
status = lineContents[6].strip()
host = lineContents[7].strip()
if status != "initiated":
timestamp = int(lineContents[8].strip())
humanreadabletimestamp = datetime.datetime.fromtimestamp(timestamp/1000).strftime("%Y-%m-%d %H:%M:%S")
if status == "working":
activeWorkers += 1
else:
timestamp = "---"
humanreadabletimestamp = "---"
waitingCompactions += 1
partitionid = dbname + "," + tablename + "," + partition
compactioninfo = [dbname, tablename, partition, timestamp, humanreadabletimestamp, compactionType, status, host]
if partitionid not in partitionMap.keys() or timestamp > partitionMap[partitionid][3]:
partitionMap[partitionid] = compactioninfo
def print_last_compaction():
header = ["Database", "Table", "Partition", "UTC start", "Local time of start", "Compaction Type", "Status", "Host"]
for element in header:
print '{:>20}'.format(element),
print ""
for partitionid in partitionMap:
status = partitionMap[partitionid][6]
if status == "failed" or status == "attempted":
for element in partitionMap[partitionid]:
print '{:>20}'.format(element),
print ""
partitionMap = {}
activeWorkers = 0
waitingCompactions = 0
parse_file()
print "Active workers:", activeWorkers
print "Waiting compactions:", waitingCompactions
print "The following tables/partitions' most recent compaction is in a failed or attempted state:"
print_last_compaction()
print
print "Active workers:", activeWorkers
print "Waiting compactions:", waitingCompactions