Sha256: ab03b8335f4929ab5b833e515080227110f96af6ab0bc449f7b9b220294801dc

Contents?: true

Size: 745 Bytes

Versions: 27

Compression:

Stored size: 745 Bytes

Contents

require 'open3'
require 'timeout'

module Ring
class SQA

  class MTR
    BIN  = 'mtr'
    def self.run host
      MTR.new.run host
    end

    def run host, args=nil
      Timeout::timeout(@timeout) do
        args ||= CFG.mtr.args.split(' ')
        mtr host, args
      end
    rescue Timeout::Error
      "MTR runtime exceeded #{@timeout}s"
    end

    private

    def initialize timeout=CFG.mtr.timeout
      @timeout = timeout
    end

    def mtr host, *args
      out = ''
      args = [*args, host].flatten
      Open3.popen3(BIN, *args) do |stdin, stdout, stderr, wait_thr|
        out << stdout.read until stdout.eof?
      end
      'mtr ' + args.join(' ') + "\n" + out.each_line.to_a[1..-1].join rescue ''
    end
  end

end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ring-sqa-0.4.3 lib/ring/sqa/mtr.rb
ring-sqa-0.4.2 lib/ring/sqa/mtr.rb
ring-sqa-0.4.1 lib/ring/sqa/mtr.rb
ring-sqa-0.3.1 lib/ring/sqa/mtr.rb
ring-sqa-0.3.0 lib/ring/sqa/mtr.rb
ring-sqa-0.2.2 lib/ring/sqa/mtr.rb
ring-sqa-0.2.1 lib/ring/sqa/mtr.rb
ring-sqa-0.2.0 lib/ring/sqa/mtr.rb
ring-sqa-0.1.12 lib/ring/sqa/mtr.rb
ring-sqa-0.1.11 lib/ring/sqa/mtr.rb
ring-sqa-0.1.10 lib/ring/sqa/mtr.rb
ring-sqa-0.1.9 lib/ring/sqa/mtr.rb
ring-sqa-0.1.8 lib/ring/sqa/mtr.rb
ring-sqa-0.1.7 lib/ring/sqa/mtr.rb
ring-sqa-0.1.6 lib/ring/sqa/mtr.rb
ring-sqa-0.1.5 lib/ring/sqa/mtr.rb
ring-sqa-0.1.4 lib/ring/sqa/mtr.rb
ring-sqa-0.1.3 lib/ring/sqa/mtr.rb
ring-sqa-0.1.2 lib/ring/sqa/mtr.rb
ring-sqa-0.1.1 lib/ring/sqa/mtr.rb