|
24 | 24 | # -p | --ping: Host to ping to measure latency (default - gstatic.com)
|
25 | 25 | # -n | --number: Number of simultaneous sessions (default - 5 sessions)
|
26 | 26 |
|
27 |
| -# Copyright (c) 2014 - Rich Brown [email protected] |
| 27 | +# Copyright (c) 2014-2022 - Rich Brown [email protected] |
28 | 28 | # GPLv2
|
29 | 29 |
|
30 |
| -# Summarize the contents of the ping's output file to show min, avg, median, max, etc. |
31 |
| -# input parameter ($1) file contains the output of the ping command |
32 |
| - |
33 |
| -summarize_pings() { |
34 |
| - |
35 |
| - # Process the ping times, and summarize the results |
36 |
| - # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them |
37 |
| - # awk builds an array of those values, and prints first & last (which are min, max) |
38 |
| - # and computes average. |
39 |
| - # If the number of samples is >= 10, also computes median, and 10th and 90th percentile readings |
40 |
| - sed 's/^.*time=\([^ ]*\) ms/\1/' < $1 | grep -v "PING" | sort -n | \ |
41 |
| - awk 'BEGIN {numdrops=0; numrows=0;} \ |
42 |
| - { \ |
43 |
| - if ( $0 ~ /timeout/ ) { \ |
44 |
| - numdrops += 1; \ |
45 |
| - } else { \ |
46 |
| - numrows += 1; \ |
47 |
| - arr[numrows]=$1; sum+=$1; \ |
48 |
| - } \ |
49 |
| - } \ |
50 |
| - END { \ |
51 |
| - pc10="-"; pc90="-"; med="-"; \ |
52 |
| - if (numrows == 0) {numrows=1} \ |
53 |
| - if (numrows>=10) \ |
54 |
| - { ix=int(numrows/10); pc10=arr[ix]; ix=int(numrows*9/10);pc90=arr[ix]; \ |
55 |
| - if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ |
56 |
| - }; \ |
57 |
| - pktloss = numdrops/(numdrops+numrows) * 100; \ |
58 |
| - printf(" Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ |
59 |
| - }' |
| 30 | + # Process the ping times from the passed-in file, and summarize the results |
| 31 | + # grep to keep lines that have "time=", then sed to isolate the time stamps, and sort them |
| 32 | + # Use awk to build an array of those values, and print first & last (which are min, max) |
| 33 | + # and compute average. |
| 34 | + # If the number of samples is >= 10, also compute median, and 10th and 90th percentile readings |
| 35 | + |
| 36 | + # Display the values as: |
| 37 | + # Latency: (in msec, 11 pings, 8.33% packet loss) |
| 38 | + # Min: 16.556 |
| 39 | + # 10pct: 16.561 |
| 40 | + # Median: 22.370 |
| 41 | + # Avg: 21.203 |
| 42 | + # 90pct: 23.202 |
| 43 | + # Max: 23.394 |
| 44 | + |
| 45 | +summarize_pings() { |
| 46 | + |
| 47 | +grep "time" < "$1" | cat | \ |
| 48 | +sed 's/^.*time=\([^ ]*\) ms/\1/'| \ |
| 49 | + # tee >&2 | \ |
| 50 | + sort -n | \ |
| 51 | + awk 'BEGIN {numdrops=0; numrows=0} \ |
| 52 | + { \ |
| 53 | + # print ; \ |
| 54 | + if ( $0 ~ /timeout/ ) { \ |
| 55 | + numdrops += 1; \ |
| 56 | + } else { \ |
| 57 | + numrows += 1; \ |
| 58 | + arr[numrows]=$1; sum+=$1; \ |
| 59 | + } \ |
| 60 | + } \ |
| 61 | + END { \ |
| 62 | + pc10="-"; pc90="-"; med="-"; \ |
| 63 | + if (numrows == 0) {numrows=1} \ |
| 64 | + if (numrows>=10) \ |
| 65 | + { # get the 10th pctile - never the first one |
| 66 | + ix=int(numrows/10); if (ix=1) {ix+=1}; pc10=arr[ix]; \ |
| 67 | + # get the 90th pctile |
| 68 | + ix=int(numrows*9/10);pc90=arr[ix]; \ |
| 69 | + # get the median |
| 70 | + if (numrows%2==1) med=arr[(numrows+1)/2]; else med=(arr[numrows/2]); \ |
| 71 | + }; \ |
| 72 | + pktloss = numdrops/(numdrops+numrows) * 100; \ |
| 73 | + printf("\n Latency: (in msec, %d pings, %4.2f%% packet loss)\n Min: %4.3f \n 10pct: %4.3f \n Median: %4.3f \n Avg: %4.3f \n 90pct: %4.3f \n Max: %4.3f\n", numrows, pktloss, arr[1], pc10, med, sum/numrows, pc90, arr[numrows] )\ |
| 74 | + }' |
60 | 75 | }
|
61 | 76 |
|
62 | 77 | # ------- Start of the main routine --------
|
|
0 commit comments