stwissel
stwissel

Reputation: 20384

Script to extract highest latency from traceroute

I'm looking for a script that can extract the line with the highest latency hop from a traceroute. Ideally it would look at the max or avg of the 3 values by line. How can I so that?

This is what I tried so far:

     traceroute www.google.com | awk '{printf "%s\t%s\n", $2, $3+$4+$5; }' | sort -rgk2 | head -n1
     traceroute -w10 www.google.com | awk '{printf "%s\t%s\n", $2, ($3+$4+$5)/3; }' | sort -rgk2 | head -n1

It seemed a step in the right direction, except some of the values coming back from a traceroute are *, so both the sum and the average provide a wrong value.

Update Got one step further:

     traceroute www.cnn.com | awk '{count = 0;sum = 0;for (i=3; i<6; i++){ if ($i != "*") {sum += $i;count++;}}; printf "%s\t%s\t%s\t%s\n", $2, count, sum, sum/count }' | sort -rgk2

now need to intercept if I dont' have a column 4,5. Sometimes traceroute only provides 3 stars like this:

     17   207.88.13.153  235.649ms  234.864ms  239.316ms 
     18   *  *  *

Upvotes: 0

Views: 869

Answers (4)

Lorenz
Lorenz

Reputation: 2269

Use mtr --raw -c 1 google.com. It's wayy faster and easier to parse.

Upvotes: 0

garethTheRed
garethTheRed

Reputation: 2297

Try:

$ traceroute 8.8.8.8 | awk ' BEGIN { FPAT="[0-9]+\\.[0-9]{3} ms" }
                           /[\\* ]{3}/ {next}
                           NR>1  {
                                   for (i=1;i<4;i++) {gsub("*","5000.00 ms",$i)}
                                   av = (gensub(" ms","",1,$1) + gensub(" ms","",1,$2) + gensub(" ms","",1,$3))/3
                                   if (av > worst) {
                                     ln = $0
                                     worst = av
                                   }
                                 }
                           ND { print "Highest:", ln, " Average:", worst, "ms"}'

which gives:

Highest:  6  72.14.242.166 (72.14.242.166)  7.383 ms 72.14.232.134 (72.14.232.134)  7.865 ms  7.768 ms  Average: 7.672  ms

If there are three asterix (asteri?) * * * the script assumes that the hop isn't responding with the IGMP response and ignores it completely. If there are one or two * in a line, it gives them the value of 5.0 seconds.

Upvotes: 1

Rayd123
Rayd123

Reputation: 21

Stephan, you could try and use pchar a derivative of pathchar. It should be in the Ubuntu repository.

I takes a while to run though so you need some patience. It will show you throughput and that will be much better than latency for determining the bottleneck.

http://www.caida.org/tools/taxonomy/perftaxonomy.xml

Here is an example:

rayd@raydHPEliteBook8440p ~ sudo pchar anddroiddevs.com
pchar to anddroiddevs.com (31.221.38.104) using UDP/IPv4
Using raw socket input
Packet size increments from 32 to 1500 by 32
46 test(s) per repetition
32 repetition(s) per hop
 0: 192.168.0.20 (raydHPEliteBook8440p.local)
    Partial loss:      0 / 1472 (0%)
    Partial char:      rtt = 6.553065 ms, (b = 0.000913 ms/B), r2 = 0.241811
                       stddev rtt = 0.196989, stddev b = 0.000244
    Partial queueing:  avg = 0.012648 ms (13848 bytes)
    Hop char:          rtt = 6.553065 ms, bw = 8759.575088 Kbps
    Hop queueing:      avg = 0.012648 ms (13848 bytes)
 1: 80.5.69.1 (cpc2-glfd6-2-0-gw.6-2.cable.virginm.net)

Upvotes: 1

user9517
user9517

Reputation: 221

You will have to

  • Kick off a traceroute
  • Collect each line of output ( a pipe would likely work well here)
  • Use a tool like awk to
    • Analyze the line and extract the information you want
    • Compare the values you just got with previous values and store the current line if appropriate
    • At the end of the input print the stored value

Upvotes: 5

Related Questions