forked from ErickRamirezDS/cass_log_tools
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathparse_cqlsh_trace.py
More file actions
executable file
·52 lines (43 loc) · 1.47 KB
/
parse_cqlsh_trace.py
File metadata and controls
executable file
·52 lines (43 loc) · 1.47 KB
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
#!/usr/bin/python
# This script can be used to parse a cqlsh trace
# to show the node it was executed on and the
# request complete time.
#
# Useful if you have a file with many traces from
# different nodes
import os
import re
import sys
# Argument checks
if len(sys.argv) != 2:
print "\n***",sys.argv[0], "***\n"
print 'Incorrect number of arguments, please run script as follows:'
print '\n'+str(sys.argv[0])+' <file name>'
sys.exit(0)
# Setup variables etc
path = '.'
file_to_parse = sys.argv[1]
time = ''
node = ''
raw_results = [ ]
# open file
current_file = open (file_to_parse, 'r')
# check for patterns
pattern1 = '.*xecute.*query.*'
pattern2 = '.*Request complete.*'
# parse file
for myline in current_file:
matched1 = re.match(pattern1, myline, re.M)
matched2 = re.match(pattern2, myline, re.M)
words = myline.split('|')
if matched1: # usually the beginning of the trace
node = words[2].strip()
if matched2: # usually the end of the trace
time = words[3].strip()
raw_results.append([node, time]) # only append when the end of trace is seen
# this is the part that sorts the results, the lambda can take several arguments
# the first tuple item is 0 and so on. So were sorting by item 1 then 2 and so on
results = sorted(raw_results, key=lambda tup: (tup[0], int(tup[1])))
# print out to console, allow the user to rrdirect to a file if they want
for row in results:
print 'node: ' + row[0] + ', time: ' + row[1]