Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodfersou/9a3bad07d1aae026c66156b8a18828a7 to your computer and use it in GitHub Desktop.
Save rodfersou/9a3bad07d1aae026c66156b8a18828a7 to your computer and use it in GitHub Desktop.
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requesters by user agent
cut -d' ' -f12- /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requests by URL
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top IP addresses requesting non-existent content
awk '($9 ~ /404/) {print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top URL returning 404 Not Found
awk '($9 ~ /404/) {print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top user agents requesting non-existent content
awk '($9 ~ /404/)' /var/log//nginx/access.log | cut -d' ' -f12- | sort | uniq -c | sort -rn | head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment