Class: Pinger
- Inherits:
-
Object
- Object
- Pinger
- Defined in:
- lib/pingman/pinger.rb
Instance Method Summary collapse
Instance Method Details
#ping(line) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/pingman/pinger.rb', line 4 def ping(line) return unless line.hostname || line.address line.log = line.log.slice(0, 14) pe = Net::Ping::External.new(line.address || line.hostname) start = Time.now line.res = pe.ping line.rtt = Time.now - start line.loss = (line.snt * line.loss + (line.res ? 0 : 1)) / (line.snt + 1).to_f line.avg = (line.snt * line.avg + line.rtt) / (line.snt + 1).to_f if line.res line.snt += 1 line.log.unshift line.res end |