Created
December 13, 2015 16:49
-
-
Save kirang89/cc2458d4421dbcd868f0 to your computer and use it in GitHub Desktop.
A simple example to illustrate log file parsing using AWK
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/awk -f | |
BEGIN { | |
requests = 0 | |
getrq = 0 | |
postrq = 0 | |
count = 0 | |
} | |
$0 ~ /(GET|POST)/ { | |
requests++; | |
if ($9 == "200") count++; | |
} | |
$0 ~ /GET/ { | |
getrq++; | |
# Remove a leading bracket from date column | |
sub(/^\[/, "", $4); | |
print $4 " <" $7 "> => " $9; | |
} | |
$0 ~ /POST/ { | |
postrq++; | |
} | |
END { | |
print "Total Requests: " requests; | |
print "GET Requests: " getrq; | |
print "POST Requests: " postrq; | |
print "200 served: " count; | |
print "success rate: " (count/requests)*100 "%" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment