Skip to content

Instantly share code, notes, and snippets.

@yitznewton
Last active February 17, 2020 15:51
Show Gist options
  • Save yitznewton/3e7339b992989dc931c7b037ca52ff8c to your computer and use it in GitHub Desktop.
Save yitznewton/3e7339b992989dc931c7b037ca52ff8c to your computer and use it in GitHub Desktop.
Heroku H12 errors from API
#!/bin/bash
errors_for_date () {
START_DATE=$1
END_DATE=$2
echo $START_DATE $END_DATE
curl "https://api.metrics.heroku.com/metrics/1df0f834-36ae-4f6c-8acb-4e1ec975e166/router/errors?process_type=web&start_time=${START_DATE}T16%3A00%3A00.000Z&end_time=${END_DATE}T16%3A00%3A00.000Z&step=1440m&region=" \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0' \
-H 'Accept: application/vnd.heroku+json; version=3.monitoring-events' -H 'Accept-Language: en-US,en;q=0.5' \
-s --compressed -H 'Referer: https://dashboard.heroku.com/' -H 'X-Origin: https://dashboard.heroku.com' \
-H "Authorization: Bearer $TOKEN" -H 'Origin: https://dashboard.heroku.com' \
-H 'Connection: keep-alive' -H 'TE: Trailers' | ruby -e "require 'json'; puts JSON.parse(gets).dig('data', 'H12').map(&:to_i).reduce(&:+)"
}
TOKEN=$1
for i in 5 4 3 2 ; do
START_DATE=`date -d "$i days ago" '+%Y-%m-%d'`
END_DATE=`date -d "$(($i-1)) days ago" '+%Y-%m-%d'`
errors_for_date $START_DATE $END_DATE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment