From: Dave Baldwin Date: 2005-11-21T19:56:58+09:00 Subject: Re: url-monitoring script question On 21 Nov 2005, at 10:44, Torsten Schmidt wrote: > Thanks for the input so far. > > another possible solution come to my (ruby-beginner) mind instead > of writing > the status-code to a seperate file and parse it: > > some kind of deamon-process: > what about to put something like 'sleep 300' in the script to make an > indefinetly loop. > so it's easier to store the exit-code of the http-requests and > compare them. > > with this it would be possible to send 5 error-emails (25 min) and > after > that, send another email when the url 'recovers'. > > What are your opinions for that solution? > > Torsten > > 2005/11/21, Heiko Leberer : >> >> If the number of sites is known, you could keep a file for all sites >> and the related status (e.g. one line per site) >> >> mysite.mydomain.org : ok >> could mean, last run the site could be accessed >> mysite.mydomain.org : 2 >> could mean, site not accesible for two consecutive tries >> >> Therefore, compare your findings against the file, send an email >> if 1<= >> errcount<=3, and update the file afterwards (incrementing or >> resetting >> the error count) >> I had a need recently to monitor my internet connection at home. This is the ruby program I wrote to do it. It just keeps track of the on line and off line time in a terminal window. require 'open-uri.rb' onAt = Time.now offAt = Time.now online = false working = true puts "Log starting at #{Time.now}" def printTime (text, start) dur = Time.now - start hours = (dur / 3600).to_i minutes = (dur / 60).to_i - hours * 60 print "#{text} #{start}, for #{hours} hours and #{minutes} minutes" $stdout.flush end while true working = false 3.times do begin ans = open("http://www.google.com/").read working = true break rescue Timeout::Error, StandardError end end if !online && working onAt = Time.now online = true printTime("\nOn line at", onAt) elsif !online && !working printTime("\rOff line at", offAt) elsif online && working printTime("\rOn line at", onAt) else online && !working offAt = Time.now online = false printTime("\nOff line at", offAt) end sleep 10 end