God Presentation

Preview:

DESCRIPTION

Monitoring applications in ruby

Citation preview

GODA BETTER WAY TO MONITOR

Amit Solankihttp://amitsolanki.com

Why to Monitor?

To ensure proper functioning of our application

What to Monitor?

network connectivitydatabase connectivitybandwidthcomputer resources

free RAMCPU loaddisk spaceevents

What do you use?

Self monitoring toolsrunit monitnagios

Web based monitoring servicesMontastic (http://www.montastic.com)Monitor (http://mon.itor.us)Site24x7 (http://site24x7.com)

GodThe Ruby Way

Features

Open SourceConfiguration file written in rubyEasily write your own custom conditions in RubySupports both poll and event based conditionsDifferent poll conditions can have different intervalsIntegrated notification system (write your own too!)Easily control non-daemonizing scriptsBest for RubyOnRails and Merb

Installation

Available as a rubygem at http://github.com/mojombo/god, latest stable release is 0.7.11

Works on Linux (kernel 2.6.15+), BSD, and Darwin systems

The following systems have been tested.Darwin 10.4.10RedHat Fedora Core 6Ubuntu Dapper (no events)Ubuntu FeistyCentOS 4.5 (no events)

# run with: god -c /path/to/rails/root/config/monitor.rbRAILS_ROOT = "/path/to/rails/root"

%w{4000}.each do |port| God.watch do |w| w.group = "mongrel" w.name = "mongrel-#{port}" w.interval = 60.seconds # default w.start = "mongrel_rails start -c #{RAILS_ROOT} -p #{port} -P #{RAILS_ROOT}/log/mongrel.pid -d" w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.pid" w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.pid" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")

w.behavior(:clean_pid_file)

w.start_if do |start| start.condition(:process_running) do |c| c.interval = 30.seconds c.running = false end end

w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = 150.megabytes c.times = [3, 5] # 3 out of 5 intervals end

restart.condition(:cpu_usage) do |c| c.above = 50.percent 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 endend

Con

fig fi

le

God.watch do |w| w.group = "mongrel" w.name = "mongrel-4000" w.interval = 60.seconds # default w.start = "mongrel_rails start -c #{RAILS_ROOT} -p #{port} -P #{RAILS_ROOT}/log/mongrel.pid -d" w.stop = "mongrel_rails stop -P #{RAILS_ROOT}/log/mongrel.pid" w.restart = "mongrel_rails restart -P #{RAILS_ROOT}/log/mongrel.pid" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")

w.behavior(:clean_pid_file) ...end

Config file (contd.)

w.start_if do |start| start.condition(:process_running) do |c| c.interval = 30.seconds c.running = false end end

w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = 150.megabytes c.times = [3, 5] # 3 out of 5 intervals end

restart.condition(:cpu_usage) do |c| c.above = 50.percent c.times = 5 end end

Config file (contd.)

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

Config file (contd.)

God::Contacts::Email.message_settings = { :from => 'god@example.com'}

God::Contacts::Email.server_settings = { :address => "smtp.example.com", :port => 25, :domain => "example.com", :authentication => :plain, :user_name => "my_username", :password => "my_password"}

God.contact(:email) do |c| c.name = 'amit' c.email = 'amitkssolanki@gmail.com'end

Config file (contd.)

Commands

Starting godgod -c /path/to/file

Other commandsstart/restart/stopmonitor/unmonitorremoveloadlogstatussignalquitterminate

DEMO

Transitions & Events # determine the state on startup w.transition(:init, { true => :up, false => :start }) do |on| on.condition(:process_running) do |c| c.running = true end end

# determine when process has finished starting w.transition([:start, :restart], :up) do |on| on.condition(:process_running) do |c| c.running = true end

# failsafe on.condition(:tries) do |c| c.times = 5 c.transition = :start end end

Watching Non-Daemon Processes

God.pid_file_directory = '/path/to/pid_file_directory'

God.watch do |w| # watch with no pid_file attribute setend

Loading Config Files

# load in particular god configsGod.load "/path/to/config.god"

$ god load path/to/config.god

Drawbacks

No dashboard, statistical data, graphical UI

reduces ease of monitoring remotely

Uses ruby

installing it, other related rubygems

High memory consumption just for monitoring as compared to other command line monitoring tools like runit

THANKS

:)

http://amitsolanki.com

Recommended