-
-
Save Zarthus/e882cc945418a698a0a9fcd588851604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_mtr | |
@mtr_out = Array.new | |
h = Hash.new | |
mtr_cmd = "mtr -i 2 -t #{@options[:host]} --report -c #{@options[:mtr_count]} --report-wide" | |
stdout = `#{mtr_cmd}` | |
@mtr_out.push(mtr_cmd) | |
stdout.each do |line| | |
if line =~ /^\s+\d/ | |
re = /^\s+(\d*)\.\s*(\?\?\?)|^\s*(\d*).\s*(\S*).*?(\d*?.\d*?)%\s*.*?\d\s+(.*?)\s.*?/ | |
m = re.match(line) | |
if m.captures.count < 4 | |
STDOUT.puts("encountered ??? on #{$1}") | |
next | |
end | |
id,host,packet_loss,latency_avg = m.captures | |
h[id] = Hash.new() | |
h[id]['host'] = host | |
h[id]['packet_loss'] = packet_loss | |
h[id]['latency_avg'] = latency_avg | |
end | |
@mtr_out.push(line) | |
end | |
h | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment