Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Last active January 1, 2016 00:09
Show Gist options
  • Save alvin2ye/8064852 to your computer and use it in GitHub Desktop.
Save alvin2ye/8064852 to your computer and use it in GitHub Desktop.
RAILS_ROOT = File.join(File.dirname(__FILE__), '..')
ENV["RAILS_ENV"] ||= "development"
def generic_monitoring(w, options = {})
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 10.seconds
c.running = false
end
end
w.restart_if do |restart|
restart.condition(:memory_usage) do |c|
c.above = options[:memory_limit]
c.times = [3, 5] # 3 out of 5 intervals
end
restart.condition(:cpu_usage) do |c|
c.above = options[:cpu_limit]
c.times = 5
end
end
w.lifecycle do |on|
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 5
c.within = 5.minute
c.transition = :unmonitored
c.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
end
end
end
["4030", "4031"].each do |port|
God.watch do |w|
script = "cd #{RAILS_ROOT} && bundle exec thin -e #{ENV["RAILS_ENV"]} --pid ./tmp/pids/thin.#{port}.pid -p #{port} -d"
w.name = "customs_clearance-thin-#{port}"
w.group = "customs_clearance"
w.interval = 60.seconds
w.start = "#{script} start"
w.restart = "#{script} restart"
w.stop = "#{script} stop"
w.pid_file = "#{RAILS_ROOT}/tmp/pids/thin.#{port}.pid"
generic_monitoring(w, :cpu_limit => 80.percent, :memory_limit => 300.megabytes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment