hi all. i have a site powered by ROR. now, i try to find a monitor based on ruby. any one have any idea? regards. -- Posted via http://www.ruby-forum.com/.
On Mar 11, 2006, at 7:25 AM, Joe Black wrote:> hi all. > i have a site powered by ROR. now, i try to find a monitor based on > ruby. > any one have any idea? > > regards. > > --Here is a simple monitor script. Make sure you read it and replace the placeholder info with the sites you want monitored and the email address and unix user the emails are sent from/to. Set it up with cron. Cheers- -Ezra ez@brainspl:~/mon$ cat site_monitor.rb #! /usr/local/bin/ruby # # simple script to monitor websites # # sample cron line # # */15 * * * * /usr/local/bin/ruby /home/ez/mon/site_monitor.rb > / dev/null 2>&1 # require "net/http" require "net/smtp" require "yaml/store" require "socket" # # array of urls to ping # uris = %w( foo.railsapp.com bar.railsapp.com whatever.net ) # # array of people to notify if urls are down # recipients = %w( your@emailaddress.com ) # # message format string # msg_fmt = %Q( URI: %s TIME: %s EXCEPTION: %s\n%s ) # # user to send messages as # user = "your_unix_user_name" # # host to send messages from # host = ENV["HOSTNAME"] || ENV["HOST"] || Socket::gethostname # # maximum number of messages to send # msg_max = 3 # # db class to store codes/notifications # class DB attr "path" attr "db" def initialize path = File::join(File::expand_path("~"), ".uri.db") @path = path @db = ::YAML::Store::new @path end def reset uri @db.transaction{ @db[uri] = {"success" => true, "msgs" => 0} } end def [] uri @db.transaction{ @db[uri] } || reset(uri) end def []= uri, record @db.transaction{ @db[uri] = record } end end # # umbrella error class # class SiteDownError < StandardError; end # # ping each url, mail messages if failure for any reason... # db = DB::new uris.each do |uri| begin raise SiteDownError unless Net::HTTPOK === Net::HTTP::new(uri, 80).get("/") y uri => "up" db.reset uri rescue Exception => e y uri => "down" record = db[uri] if record["msgs"] < msg_max now = Time::now msg = msg_fmt % [uri, now, e, e.backtrace.join("\n").gsub(%r/ ^/,"\t")] from = "%s@%s" % [user, host] Net::SMTP::start("localhost") do |smtp| recipients.each do |recipient| email = "From: #{ from }\r\n" << "To: #{ recipient }\r\n" << "Subject: #{ uri } DOWN @ #{ now }\r\n" << "\r\n#{ msg }" smtp.send_message email, from, recipient end end record["success"] = false record["msgs"] += 1 db[uri] = record end end end
If you just want to monitor if the server is up or not (monitor is a vague term), you could use Montastic. It is a free site monitor powered by RoR. http://www.montastic.com/ On 3/11/06, Ezra Zygmuntowicz <ezra@yakimaherald.com> wrote:> > On Mar 11, 2006, at 7:25 AM, Joe Black wrote: > > > hi all. > > i have a site powered by ROR. now, i try to find a monitor based on > > ruby. > > any one have any idea? > > > > regards. > > > > -- > > > Here is a simple monitor script. Make sure you read it and replace > the placeholder info with the sites you want monitored and the email > address and unix user the emails are sent from/to. Set it up with cron. > > Cheers- > -Ezra > > ez@brainspl:~/mon$ cat site_monitor.rb > #! /usr/local/bin/ruby > # > # simple script to monitor websites > # > # sample cron line > # > # */15 * * * * /usr/local/bin/ruby /home/ez/mon/site_monitor.rb > / > dev/null 2>&1 > # > > require "net/http" > require "net/smtp" > require "yaml/store" > require "socket" > # > # array of urls to ping > # > uris = %w( > foo.railsapp.com > bar.railsapp.com > whatever.net > ) > # > # array of people to notify if urls are down > # > recipients = %w( > your@emailaddress.com > ) > # > # message format string > # > msg_fmt = %Q( > URI: %s > > TIME: %s > > EXCEPTION: %s\n%s > ) > # > # user to send messages as > # > user = "your_unix_user_name" > # > # host to send messages from > # > host = ENV["HOSTNAME"] || ENV["HOST"] || Socket::gethostname > # > # maximum number of messages to send > # > msg_max = 3 > # > # db class to store codes/notifications > # > class DB > attr "path" > attr "db" > def initialize path = File::join(File::expand_path("~"), ".uri.db") > @path = path > @db = ::YAML::Store::new @path > end > def reset uri > @db.transaction{ @db[uri] = {"success" => true, "msgs" => 0} } > end > def [] uri > @db.transaction{ @db[uri] } || reset(uri) > end > def []= uri, record > @db.transaction{ @db[uri] = record } > end > end > # > # umbrella error class > # > class SiteDownError < StandardError; end > # > # ping each url, mail messages if failure for any reason... > # > db = DB::new > > uris.each do |uri| > begin > raise SiteDownError unless > Net::HTTPOK === Net::HTTP::new(uri, 80).get("/") > y uri => "up" > db.reset uri > > rescue Exception => e > y uri => "down" > record = db[uri] > > if record["msgs"] < msg_max > now = Time::now > msg = msg_fmt % [uri, now, e, e.backtrace.join("\n").gsub(%r/ > ^/,"\t")] > from = "%s@%s" % [user, host] > > Net::SMTP::start("localhost") do |smtp| > recipients.each do |recipient| > email = "From: #{ from }\r\n" << > "To: #{ recipient }\r\n" << > "Subject: #{ uri } DOWN @ #{ now }\r\n" << > "\r\n#{ msg }" > smtp.send_message email, from, recipient > end > end > > record["success"] = false > record["msgs"] += 1 > db[uri] = record > end > end > end > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com
Here''s a second vote for Monastic. I use it to monitor two or three sites. Fre and simple. On 3/11/06, Ben Reubenstein <benr@x-cr.com> wrote:> If you just want to monitor if the server is up or not (monitor is a > vague term), you could use Montastic. It is a free site monitor > powered by RoR. > > http://www.montastic.com/ > > On 3/11/06, Ezra Zygmuntowicz <ezra@yakimaherald.com> wrote: > > > > On Mar 11, 2006, at 7:25 AM, Joe Black wrote: > > > > > hi all. > > > i have a site powered by ROR. now, i try to find a monitor based on > > > ruby. > > > any one have any idea? > > > > > > regards. > > > > > > -- > > > > > > Here is a simple monitor script. Make sure you read it and replace > > the placeholder info with the sites you want monitored and the email > > address and unix user the emails are sent from/to. Set it up with cron. > > > > Cheers- > > -Ezra > > > > ez@brainspl:~/mon$ cat site_monitor.rb > > #! /usr/local/bin/ruby > > # > > # simple script to monitor websites > > # > > # sample cron line > > # > > # */15 * * * * /usr/local/bin/ruby /home/ez/mon/site_monitor.rb > / > > dev/null 2>&1 > > # > > > > require "net/http" > > require "net/smtp" > > require "yaml/store" > > require "socket" > > # > > # array of urls to ping > > # > > uris = %w( > > foo.railsapp.com > > bar.railsapp.com > > whatever.net > > ) > > # > > # array of people to notify if urls are down > > # > > recipients = %w( > > your@emailaddress.com > > ) > > # > > # message format string > > # > > msg_fmt = %Q( > > URI: %s > > > > TIME: %s > > > > EXCEPTION: %s\n%s > > ) > > # > > # user to send messages as > > # > > user = "your_unix_user_name" > > # > > # host to send messages from > > # > > host = ENV["HOSTNAME"] || ENV["HOST"] || Socket::gethostname > > # > > # maximum number of messages to send > > # > > msg_max = 3 > > # > > # db class to store codes/notifications > > # > > class DB > > attr "path" > > attr "db" > > def initialize path = File::join(File::expand_path("~"), ".uri.db") > > @path = path > > @db = ::YAML::Store::new @path > > end > > def reset uri > > @db.transaction{ @db[uri] = {"success" => true, "msgs" => 0} } > > end > > def [] uri > > @db.transaction{ @db[uri] } || reset(uri) > > end > > def []= uri, record > > @db.transaction{ @db[uri] = record } > > end > > end > > # > > # umbrella error class > > # > > class SiteDownError < StandardError; end > > # > > # ping each url, mail messages if failure for any reason... > > # > > db = DB::new > > > > uris.each do |uri| > > begin > > raise SiteDownError unless > > Net::HTTPOK === Net::HTTP::new(uri, 80).get("/") > > y uri => "up" > > db.reset uri > > > > rescue Exception => e > > y uri => "down" > > record = db[uri] > > > > if record["msgs"] < msg_max > > now = Time::now > > msg = msg_fmt % [uri, now, e, e.backtrace.join("\n").gsub(%r/ > > ^/,"\t")] > > from = "%s@%s" % [user, host] > > > > Net::SMTP::start("localhost") do |smtp| > > recipients.each do |recipient| > > email = "From: #{ from }\r\n" << > > "To: #{ recipient }\r\n" << > > "Subject: #{ uri } DOWN @ #{ now }\r\n" << > > "\r\n#{ msg }" > > smtp.send_message email, from, recipient > > end > > end > > > > record["success"] = false > > record["msgs"] += 1 > > db[uri] = record > > end > > end > > end > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Ben Reubenstein > http://www.benr75.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- => the blog from beyond <=> www.eyeheartzombies.com <=