Skip to content

Instantly share code, notes, and snippets.

@yszheda
Last active October 8, 2016 09:25
Show Gist options
  • Save yszheda/999fd330d0a00866eb7e1ea13d70b4a9 to your computer and use it in GitHub Desktop.
Save yszheda/999fd330d0a00866eb7e1ea13d70b4a9 to your computer and use it in GitHub Desktop.
count nginx requests by a certain POST pattern
#!/usr/bin/env bash
# The POST string is like
# \"id\"=<some number>
# Count the requests by mid
# The result is like:
# count id
# ... ...
# known search patterns:
# %22mid%22%2A
# %2522mid%2522%253A
access_log=$1
grep -oP '%[^%]+mid%[^%]+%[^%]+[0-9]*' $access_log | sed -ne 's/%\([^%]\+\)mid%\([^%]\+\)%\([^%]\+\)3A\([0-9]\+\)/\4/p' | sort | uniq -c | sort -rn | awk 'BEGIN{print "count", "mid"};{printf("%d 0x%04x\n", $1, $2)};' | column -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment