Last active
October 7, 2015 19:44
-
-
Save CameronBanga/c03a4bae7b3c1c8a5ab0 to your computer and use it in GitHub Desktop.
Grep through Papertrail logs from Heroku to get quick stats on API hit success and failure rates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE="2015-MM-DD" | |
DIR="/Users/cmbang/path/to/file/" | |
APISTRING="unique_string_in_your_api" | |
echo "\`\`\`" | |
echo "Heroku API hit logs for "$FILE | |
echo "" | |
grep $APISTRING $DIR$FILE* | wc -l | awk '{print "API hits - "$1}' | |
grep $APISTRING $DIR$FILE* | grep "status=200" | wc -l | awk '{print "successful API hits - "$1}' | |
grep $APISTRING $DIR$FILE* | grep "code=H18" | wc -l | awk '{print "device stopped responding - "$1}' | |
grep $APISTRING $DIR$FILE* | grep "code=H12" | wc -l | awk '{print "server timeouts - "$1}' | |
echo "\`\`\`" | |
# note - this will print a log with following format. I've added "```" so Slack formats it fixed width | |
# Heroku logs for 2015-MM-DD | |
# | |
# API hits - 203500 | |
# successful API hits - 198479 | |
# device stopped responding - 3496 | |
# server timeouts - 1230 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had a client ask me to get stats on some API calls we have for a mobile app. We host our backend CMS on Heroku, and it was for a short term project that ended back in March. We used Papertrail for logs, but project isn't kept up to date, so couldn't search, just had compressed tsv.gz files that are stored on Papertrail.
Only problem was, I had 900MB in log files over about 3 days worth of server use. Was a pain to work, so wrote this quick script to automate process per day. Hopefully it can save someone some time?