Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Created April 5, 2013 19:25
Show Gist options
  • Save fuzzy/5321910 to your computer and use it in GitHub Desktop.
Save fuzzy/5321910 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'drb'
class PingCheck
attr_accessor :cfg
def initialize(count=3, wait=3)
@cfg = Hash.new
@cfg[:count] = count
@cfg[:wait] = wait
end
def commit(host=nil)
if host
output = `ping -c #{@cfg[:count]} -W #{@cfg[:wait]} #{host}`
output.split("\n").each {|ln|
if ln =~ /[0-9]+\ packets\ transmitted,\ [0-9]+.*/
data = ln.split
retv = Hash.new
retv[:pkt_xmit] = data[0].to_i
retv[:pkt_rcvd] = data[3].to_i
retv[:pkt_loss] = data[6].split('%')[0]
return retv
end
}
end
end
end
# Testing
#o = PingCheck.new('8.8.8.8')
#puts o.commit.inspect
# Drb
DRb.start_service nil, PingCheck.new
puts DRb.uri
DRb.thread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment