Skip to content

Commit

Permalink
feat(drupal-cache-hit): new script
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Sep 7, 2018
1 parent 8161a70 commit e4234a4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions bin/drupal-cache-hit
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash


get_result() {
result_type="$1" # HIT or MISS
if [ "$result_type" == "HIT" ]; then
grep "^$domain" "$logfile" \
| grep -v "curl" \
| grep -v "admin_menu" \
| grep -v "HEAD" \
| grep -v "bot" \
| grep -v " 301 " \
| grep '\( 304 \)\|"HIT"'
fi

if [ "$result_type" == "MISS" ]; then
grep "^$domain" "$logfile" \
| grep -v "curl" \
| grep -v "admin_menu" \
| grep -v "HEAD" \
| grep -v "bot" \
| grep -v ' 301 ' \
| grep -v ' 304 ' \
| grep -v "HIT"
fi
}

main() {
domain="$1"
logfile="$2"
if [ ! -f "$logfile" ]; then
logfile="/var/log/nginx/drupal_cache_hit.log"
fi

hit=$(get_result HIT | wc -l)
miss=$(get_result MISS | wc -l)
total=$(( $hit + $miss ))
if [ $total -gt 0 ]; then
percent=$(awk "BEGIN { printf \"%.0f\n\", $hit/$total*100 }")
else
total=0
fi

echo "HIT: $hit"
echo "MISS: $miss"
echo "total: $total"
echo "percent: $percent"
}

if [ $# -lt 1 ] || [ "$1" = "--help" ]; then
echo "Usage: $0 domain /path/to/log"
exit 1
fi

main "$@"

0 comments on commit e4234a4

Please sign in to comment.