Skip to content

Instantly share code, notes, and snippets.

@distributedlife
Created January 9, 2013 06:32
Show Gist options
  • Select an option

  • Save distributedlife/4491131 to your computer and use it in GitHub Desktop.

Select an option

Save distributedlife/4491131 to your computer and use it in GitHub Desktop.
threw together some code to parse heroku downtime json to determine relevance to app
require 'rubygems'
require 'json'
require 'date'
ignore = ["Shared Database Server Offline", "Elevated Error Rates Around Bamboo", "Emergency Maintenance Window on Bamboo and Aspen HTTP stacks", "Emergency Maintenance Window for Aspen/Bamboo Deploys", "Intermittent Git Errors", "Emergency Maintenance on a Shared Database Server", "Emergency Maintenance on Logging Infrastructure ", "Errors Launching Terminal Attached Processes"]
records = ""
File.open("issues.json") do |file|
file.readlines.each do |line|
records += line
end
end
json = JSON.parse(records)
relevent = json.select {|incident| DateTime.parse(incident["created_at"]) <= DateTime.new(2012,4,1) && [incident["title"]] & ignore == []}
total_downtime = 0
relevent.each do |incident|
updates = incident["updates"].select { |update| update["update_type"] == "resolved"}
last_update = updates.first #there can be more than one 'resolved' update but the only example i've seen had the same timestamp for both records
duration = DateTime.parse(last_update["created_at"]) - DateTime.parse(incident["created_at"])
total_downtime += duration
end
puts "hours: #{(total_downtime * 24).to_f}"
puts "minutes: #{(total_downtime * 24 * 60).to_f}"
puts "seconds: #{(total_downtime * 24 * 60 * 60).to_i}"
puts "incidents: #{relevent.count}"
puts "descriptions:"
relevent.each { |incident| puts incident["title"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment