Top Banner
GOD A BETTER WAY TO MONITOR Amit Solanki http://amitsolanki.com
19

God Presentation

Jan 15, 2015

Download

Technology

Amit Solanki

Monitoring applications in ruby
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: God Presentation

GODA BETTER WAY TO MONITOR

Amit Solankihttp://amitsolanki.com

Page 2: God Presentation

Why to Monitor?

To ensure proper functioning of our application

Page 3: God Presentation

What to Monitor?

network connectivitydatabase connectivitybandwidthcomputer resources

free RAMCPU loaddisk spaceevents

Page 4: God Presentation

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)

Page 5: God Presentation

GodThe Ruby Way

Page 6: God Presentation

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

Page 7: God Presentation

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)

Page 8: God Presentation

# 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

Page 9: God Presentation

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.)

Page 10: God Presentation

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.)

Page 11: God Presentation

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.)

Page 12: God Presentation

God::Contacts::Email.message_settings = { :from => '[email protected]'}

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 = '[email protected]'end

Config file (contd.)

Page 13: God Presentation

Commands

Starting godgod -c /path/to/file

Other commandsstart/restart/stopmonitor/unmonitorremoveloadlogstatussignalquitterminate

Page 14: God Presentation

DEMO

Page 15: God Presentation

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

Page 16: God Presentation

Watching Non-Daemon Processes

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

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

Page 17: God Presentation

Loading Config Files

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

$ god load path/to/config.god

Page 18: God Presentation

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

Page 19: God Presentation

THANKS

:)

http://amitsolanki.com