Created
October 8, 2012 05:34
-
-
Save MinCha/3850876 to your computer and use it in GitHub Desktop.
Extracting error-count contained specified string from Nelo log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import csv | |
import sys | |
import operator | |
filepath = sys.argv[1] | |
patterns = sys.argv[2].split(";") | |
matched_count = 0 | |
total_count = 0 | |
count = {} | |
for p in patterns: | |
count.update({p:0}) | |
with open (filepath) as csvfile: | |
reader = csv.reader(csvfile, delimiter=',', quotechar='|') | |
for r in reader: | |
if r[1].isdigit(): | |
total_count = total_count + int(r[1]) | |
for i, p in enumerate(patterns): | |
if p in r[2]: | |
count[p] = count[p] + int(r[1]) | |
matched_count = matched_count + int(r[1]) | |
count = sorted(count.iteritems(), key=operator.itemgetter(1)) | |
count.reverse() | |
for r in count: | |
print "%s : %d" % (r[0], r[1]) | |
print "Other : %d" % (total_count - matched_count) | |
print "$$$ TOTAL : %d" % (total_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./count.py "2012-10-01~07_APIError.csv" "change residence;NullPointer;slow query;Facebook"
slow query : 12389
NullPointer : 807
Facebook : 785
change residence : 564
Other : 242
$$$ TOTAL : 14787