Module: SfcIkiteru
- Defined in:
- lib/sfc_ikiteru.rb
Constant Summary collapse
- VERSION =
'0.0.7'
Class Method Summary collapse
- .ikiteru(timeout = 3) ⇒ Object
- .ping(host, timeout = 5, service = "echo") ⇒ Object
- .servers ⇒ Object
Class Method Details
.ikiteru(timeout = 3) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sfc_ikiteru.rb', line 24 def SfcIkiteru.ikiteru(timeout=3) results = Array.new EM::run do EM::defer do loop do EM::stop if results.size >= servers.size sleep 0.1 end end servers.each{|s| EM::defer do res = ping(s[:host], timeout, s[:service]) results << {:host => s[:host], :ping => res} end } end count = 0 results.each{|i| count+=1 if i[:ping] == true } per = count.to_f / results.size return per, results end |
.ping(host, timeout = 5, service = "echo") ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sfc_ikiteru.rb', line 49 def SfcIkiteru.ping(host, timeout=5, service="echo") begin timeout(timeout) do TCPSocket.new(host, service).close end rescue Errno::ECONNREFUSED return true rescue Timeout::Error, StandardError return false end return true end |
.servers ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sfc_ikiteru.rb', line 9 def SfcIkiteru.servers [ {:host => 'web.sfc.keio.ac.jp', :service => 'echo'}, {:host => 'ccz01.sfc.keio.ac.jp', :service => 'ssh'}, {:host => 'ccz02.sfc.keio.ac.jp', :service => 'ssh'}, {:host => 'mail.sfc.keio.ac.jp', :service => 'echo'}, {:host => 'www.mag.keio.ac.jp', :service => 'echo'}, {:host => 'cpu0.mag.keio.ac.jp', :service => 'echo'}, {:host => 'gw2.sfc.keio.ac.jp', :service => 'echo'}, {:host => 'keio.gw.sinet.ad.jp', :service => 'echo'}, {:host => 'shonan.sfc.wide.ad.jp', :service => 'http'}, {:host => 'masui.sfc.keio.ac.jp', :service => 'http'} ] end |