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.
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.
On Mar 11, 2006, at 7:25 AM, Joe B. 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
dev/null 2>&1
require “net/http”
require “net/smtp”
require “yaml/store”
require “socket”
uris = %w(
foo.railsapp.com
bar.railsapp.com
whatever.net
)
recipients = %w(
[email protected]
)
msg_fmt = %Q(
URI: %s
TIME: %s
EXCEPTION: %s\n%s
)
user = “your_unix_user_name”
host = ENV[“HOSTNAME”] || ENV[“HOST”] || Socket::gethostname
msg_max = 3
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
class SiteDownError < StandardError; end
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
Here’s a second vote for Monastic. I use it to monitor two or three
sites. Fre and simple.
On 3/11/06, Ben R. [email protected] wrote:
hi all.
the placeholder info with the sites you want monitored and the emailsample cron line
array of urls to ping
[email protected]
)
end
raise SiteDownError unless msg = msg_fmt % [uri, now, e, e.backtrace.join("\n").gsub(%r/ end
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
=> the blog from beyond <=
=> www.eyeheartzombies.com <=
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.
On 3/11/06, Ezra Z. [email protected] wrote:
–
#! /usr/local/bin/ruby
require “net/smtp”attr "db" def []= uri, record
db = DB::new
record = db[uri]
“To: #{ recipient }\r\n” <<
end
end
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
Ben R.
http://www.benr75.com
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs