Skip to content

Instantly share code, notes, and snippets.

@mgarriss
Created May 5, 2011 18:52
Show Gist options
  • Save mgarriss/957641 to your computer and use it in GitHub Desktop.
Save mgarriss/957641 to your computer and use it in GitHub Desktop.
def update_events
open_downtime = open_events(:down)
probes = Config::Pingdom.probes_for_region(self.region.region)
check = Config::Pingdom.connection.check( check_id )
outages = Config::Pingdom.connection.summary( check_id ).
outages(:from => last_updated,
:probes => probes )
results = Config::Pingdom.connection.results( check_id, :from => last_updated, :probes => probes ).reverse
# Update outages
if check.status == 'down'
current_outage = outages.pop
unless open_downtime.present?
self.events << Event.new( :status => :down, :started_at => current_outage.timefrom )
end
else
open_downtime.each do |event|
event.ended_at = outages.pop.timeto
end
end
outages.each do |outage| # outages that occured between checks
self.events << Event.new( :status => :down, :started_at => outage.timefrom, :ended_at => outage.timeto )
end
# Update performance disruptions
results.each do |result|
if result.responsetime > Config::Pingdom.response_time_threshold_for( self.api )
if (open = open_events(:potential_slow, :slow)).present?
open.first.tap do |event|
event.event_count += 1
event.status = :slow
end
else
self.events << Event.new( :status => :potential_slow, :started_at => Time.at(result.time), :event_count => 1 )
end
else # result below threshold
if (open = open_events(:potential_slow, :slow)).present?
if open.first.event_count > 1
open.first.tap do |event|
event.ended_at = Time.at(result.time)
event.status = :slow
end
else
self.events.delete_if{ |e| e == open.first }
end
end
end
end
Config::Redis.connection.set(key, Time.now.to_i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment