Pages

Ruby On Rails : "God Monitoring With backgroundrb".

Saturday, August 1, 2009 Posted by Shrikant Lokhande
vi config/backgroundrb.god
#--------------------------------------------------------------
#run on command line with 'god -c backgroundrb.god -D'
RAILS_ROOT = '/mnt/app/application/current'
#load required rails and backgroundrb files
require File.dirname(__FILE__) + '/boot'
require File.dirname(__FILE__) + '/environment'
require 'erb'
$LOAD_PATH << "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib"
require "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib/backgroundrb.rb"

#create custom condition for checking that QueryProcessingWorker is running
# MiddleMan = BackgrounDRb::ClusterConnection.new
module God
module Conditions
class Backgroundrb < PollCondition
def initialize; super; end
def valid?; true; end

def test
begin
queue_worker = MiddleMan.all_worker_info.values.flatten.select { |w| :queue_processing_worker == w[:worker] }
queue_worker.empty?
rescue #if all_worker_info raises exception, then bdrb isn't running and we were unable to connect
true
end
end
end
end
end
God::Contacts::Email.message_settings ={
:from => 'shrii@gmail.com'
}


God::Contacts::Email.server_settings = {
:address => "Ipaddress_of mail server",
:port => 25,
:domain => "Ipaddress_of mail server",
:user_name => "user",
:password => "passwd",
:authentication => :login
}


God.contact(:email) do |c|
c.name = 'Username'
c.email = 'shrikant@gmail.com'
end
God.watch do |w|
w.name = 'backgroundrb'
w.interval = 1.minute
w.restart = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb stop && /usr/local/bin/ruby script/backgroundrb -e production start"
w.stop = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb stop"
w.start = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb -e production start"
w.grace = 1.minute
w.pid_file = "#{RAILS_ROOT}/tmp/pids/backgroundrb_11006.pid"
w.start_if do |start|
start.condition(:process_running) do |c|
c.running = false
c.notify = "username"
end
end
w.restart_if do |restart|
restart.condition(:cpu_usage) do |c|
c.above = 70.percent
c.times = [3,5]
c.notify = "username"
end
end
end

#----------------------------------------------------------

* To Start God. in RAILS_ROOT

god -c config/backgroundrb.god

* To Check Prosess id of GOD:

ps -aufx| grep god

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root 11219 0.0 0.0 60260 732 ttyp1 S+ 07:48 0:00 \_ grep god
root 26944 0.2 0.3 163240 61476 ttyp0 S 07:14 0:05 /usr/local/bin/ruby /usr/local/bin/god -c config/backgroundrb.god

Thats It.. Please let me know if there is any issue.
Labels:
  1. Hey cool
    This is very helpful article.
    It saved my time.
    Nice job. Keep it up ;-)

Post a Comment