Skip to content

Instantly share code, notes, and snippets.

@raymyers
Created June 13, 2016 20:25
Show Gist options
  • Save raymyers/4cb135574dc116353ed78f5792785b14 to your computer and use it in GitHub Desktop.
Save raymyers/4cb135574dc116353ed78f5792785b14 to your computer and use it in GitHub Desktop.
Scheduling periodic monitoring tasks with Rufus and Librato
unless self.class.const_defined?('SCHEDULER')
SCHEDULER = Rufus::Scheduler.new(:lockfile => ".rufus-scheduler.lock")
unless SCHEDULER.down?
SCHEDULER.every('60s', :first_in => '10s') do
active_count = DASHBOARD.find_recent_users(10.minutes.ago).count()
# Rails.logger.info "======== active users #{active_count}"
Librato.measure('users.active', active_count)
end
SCHEDULER.every('60s', :first_in => '10s') do
es_health = ELASTICSEARCH_CLIENT.cluster.health() # master_timeout ?
status_numeric = es_health['status'] == 'green' ? 100 : (es_health['status'] == 'yellow' ? 50 : 0)
Librato.group 'elasticsearch' do |g|
g.measure('status', status_numeric)
g.measure('number_of_nodes', es_health['number_of_nodes'])
g.measure('number_of_data_nodes', es_health['number_of_data_nodes'])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment