Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created July 5, 2016 19:23
Show Gist options
  • Save mostlygeek/ced63809af921c8281305e2bb1adeb56 to your computer and use it in GitHub Desktop.
Save mostlygeek/ced63809af921c8281305e2bb1adeb56 to your computer and use it in GitHub Desktop.
Getting cache hit rate from nginx

assumes that $upstream_cache_status is at the end of the log line:

tail -n 50000 access.log | \
  grep -v heartbeat | \
  awk 'BEGIN {C=0;T=0; } {if ( $NF == "HIT" || $NF=="EXPIRED" ) { C = C + 1 }; T=T+1} END { print C,T,C/T*100 }'

Output:

45454 49550 91.7336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment