Website monitor?


#1

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.


#2

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

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(
removed_email_address@domain.invalid
)

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


#3

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. removed_email_address@domain.invalid wrote:

hi all.
the placeholder info with the sites you want monitored and the email

sample cron line

array of urls to ping

 removed_email_address@domain.invalid

)

 end

   raise SiteDownError unless
     msg = msg_fmt % [uri, now, e, e.backtrace.join("\n").gsub(%r/
       end

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


=> the blog from beyond <=
=> www.eyeheartzombies.com <=


#4

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 Z. removed_email_address@domain.invalid 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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Ben R.
http://www.benr75.com