Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Last active December 24, 2015 13:29
Show Gist options
  • Save jacaetevha/6805033 to your computer and use it in GitHub Desktop.
Save jacaetevha/6805033 to your computer and use it in GitHub Desktop.
Parses a Heroku log (defaults to /var/log/heroku, but you can pass it a log file as the first argument to the script), then prints out the date and hour, the error code, the count, and the percentage of the total.
#!/bin/bash
# ---------------
# Example output:
# ---------------
# Date/Hour Error Count % of Total
# 3-Oct 03 code=H12 98 73.68%
# 3-Oct 04 code=H12 35 26.32%
LOG=${1:-/var/log/heroku}
awk 'BEGIN{ printf "%12s %10s %10s %11s\n", "Date/Hour", "Error", "Count", "% of Total" }'
egrep 'code=(H|R)' $LOG | awk '{
split($3,time,":")
dayHour=$2"-"$1" "time[1]
a[dayHour]++;total++
}
END {
for(i in a){
printf "%12s %10s %10s %10.2f%%\n", i, $8, a[i], a[i]/total*100;
}
}' | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment