Monitoring with God
Posted by Linus Mon, 26 May 2008 18:06:00 GMT
This week I discovered a great (though very poorly named) program called God. It is a ruby monitoring gem that, as the author describes, “is like monit, only awesome”. It actually is pretty awesome because it makes monitoring scripts SO much easier to write versus monit. Plus it’s all in ruby so we can use all the regular ruby shortcuts without learning how to do them in monit.
The only drawback however is that God doesn’t not support monitoring. If you read the message boards and the blogs out there you can see that this is a feature that many have requested. However since the purpose of God is to simply start/stop/restart processes, the author of the gem has neglated to build in this feature.
I however have a work around to this problem. What you do is make a transition condition that monitors when the process is up and transitions it to a restart. The KEY here is to make sure that your restart command does nothing. For me I just have it sleep 0 which is close to a noop. See the code snippet below:
God.watch do |w|
w.name = “FOO”
w.interval = 5.minutes
w.start = “sudo /usr/bin/ruby FOO”
w.stop = “sleep 0” # stop command - HACK
w.restart = “sleep 0” # restart command - HACK
w.pid_file = “/tmp/FOO.pid”
w.start_grace = 5.minutes
w.restart_grace = 5.minutes
w.start_if do |start|
start.condition(:process_running) do |c|
c.running = false
end
end
# Hack: GOD doesn’t currently do monitoring. Therefore we need to run a
# restart command that doesn’t do anything. The w.restart_grace variable
# is the time in between checks, since after it does this transition, it
# will requery the state of the rails app
#
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 1.megabytes
end
end
hiiiiiiiiiiiiiiiii