Created
April 5, 2017 17:58
-
-
Save Dkendal/7dc3d016a36074fb0feb6a8e0dcbfb47 to your computer and use it in GitHub Desktop.
Filter and aggregate rails log statements based on duration
This file contains hidden or 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
#!/usr/bin/gawk -f | |
BEGIN { | |
capturing = 0; | |
n = 0 | |
} | |
/Started GET "\/products\// { | |
capturing = 1; | |
} | |
function cmp(i1, v1, i2, v2, l, r) { | |
split(v1, x1, " ") | |
split(v2, x2, " ") | |
l = x1[1] | |
r = x2[1] | |
if (l < r) | |
return -1 | |
else if (l == r) | |
return 0 | |
else | |
return 1 | |
} | |
/Completed 200 OK/ { | |
capturing = 0; | |
n = 0 | |
asort(arr, result, "cmp") | |
for (i in result) { | |
print result[i] | |
} | |
delete arr | |
print "=====================================================" | |
print "END" | |
print "=====================================================" | |
} | |
match($0, /([0-9]+\.[0-9]+)ms/, a) && a[1] > 0 && capturing == 1 { | |
str = a[1] "\t|\t" substr($0, 0, 80) | |
arr[n] = str | |
n = n + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment