Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
Created October 27, 2010 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmrwoods/648570 to your computer and use it in GitHub Desktop.
Save mmrwoods/648570 to your computer and use it in GitHub Desktop.
Monitor a URL for downtime
#!/usr/bin/env ruby
require 'rubygems'
require 'term/ansicolor'
require 'net/ping'
String.send(:include, Term::ANSIColor)
url = ARGV[0]
raise "No url provided" if url.nil?
url = 'http://' + url unless url =~ /http(s)?:\/\//
pinger = Net::Ping::HTTP.new(url)
puts "Checking #{url} - pausing for 1 second between requests..."
last_status = nil
interrupted = false
trap('INT') { interrupted = true }
loop do
current_status = pinger.ping
if current_status != last_status
if current_status
# up
puts "\nUP #{Time.now}".green
else
# down
puts "\nDOWN #{Time.now}".red
end
end
print '.'
$stdout.flush
last_status = current_status
sleep 1
if interrupted
puts "\nEXIT #{Time.now}".yellow
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment