1c0b746e5SOllivier Robert# awk program to scan peerstats files and report errors/statistics 2c0b746e5SOllivier Robert# 3c0b746e5SOllivier Robert# usage: awk -f peer.awk peerstats 4c0b746e5SOllivier Robert# 5c0b746e5SOllivier Robert# format of peerstats record 6c0b746e5SOllivier Robert# MJD sec ident stat offset (s) delay (s) disp (s) 7c0b746e5SOllivier Robert# 49235 11.632 128.4.2.7 f414 -0.000041 0.21910 0.00084 8c0b746e5SOllivier Robert# 9c0b746e5SOllivier Robert# format of output dataset (time values in milliseconds) 10c0b746e5SOllivier Robert# peerstats.19960706 11c0b746e5SOllivier Robert# ident cnt mean rms max delay dist disp 12c0b746e5SOllivier Robert# ========================================================================== 13c0b746e5SOllivier Robert# 140.173.112.2 85 -0.509 1.345 4.606 80.417 49.260 1.092 14c0b746e5SOllivier Robert# 128.4.1.20 1364 0.058 0.364 4.465 3.712 10.540 1.101 15c0b746e5SOllivier Robert# 140.173.16.1 1415 -0.172 0.185 1.736 3.145 5.020 0.312 16c0b746e5SOllivier Robert#... 17c0b746e5SOllivier Robert# 18c0b746e5SOllivier RobertBEGIN { 19c0b746e5SOllivier Robert n = 0 20c0b746e5SOllivier Robert MAXDISTANCE = 1.0 21c0b746e5SOllivier Robert} 22c0b746e5SOllivier Robert# 23c0b746e5SOllivier Robert# scan all records in file 24c0b746e5SOllivier Robert# 25c0b746e5SOllivier Robert# we toss out all distances greater than one second on the assumption the 26c0b746e5SOllivier Robert# peer is in initial acquisition 27c0b746e5SOllivier Robert# 28c0b746e5SOllivier Robert{ 29c0b746e5SOllivier Robert if (NF >= 7 && ($7 + $6 / 2) < MAXDISTANCE) { 30c0b746e5SOllivier Robert i = n 31c0b746e5SOllivier Robert for (j = 0; j < n; j++) { 32c0b746e5SOllivier Robert if ($3 == peer_ident[j]) 33c0b746e5SOllivier Robert i = j 34c0b746e5SOllivier Robert } 35c0b746e5SOllivier Robert if (i == n) { 36c0b746e5SOllivier Robert peer_ident[i] = $3 37c0b746e5SOllivier Robert peer_tmax[i] = peer_dist[i] = -1e9 38c0b746e5SOllivier Robert peer_tmin[i] = 1e9 39c0b746e5SOllivier Robert n++ 40c0b746e5SOllivier Robert } 41c0b746e5SOllivier Robert peer_count[i]++ 42c0b746e5SOllivier Robert if ($5 > peer_tmax[i]) 43c0b746e5SOllivier Robert peer_tmax[i] = $5 44c0b746e5SOllivier Robert if ($5 < peer_tmin[i]) 45c0b746e5SOllivier Robert peer_tmin[i] = $5 46c0b746e5SOllivier Robert dist = $7 + $6 / 2 47c0b746e5SOllivier Robert if (dist > peer_dist[i]) 48c0b746e5SOllivier Robert peer_dist[i] = dist 49c0b746e5SOllivier Robert peer_time[i] += $5 50c0b746e5SOllivier Robert peer_time_rms[i] += $5 * $5 51c0b746e5SOllivier Robert peer_delay[i] += $6 52c0b746e5SOllivier Robert peer_disp[i] += $7 53c0b746e5SOllivier Robert } 54c0b746e5SOllivier Robert} END { 55c0b746e5SOllivier Robert printf " ident cnt mean rms max delay dist disp\n" 56c0b746e5SOllivier Robert printf "==========================================================================\n" 57c0b746e5SOllivier Robert for (i = 0; i < n; i++) { 58c0b746e5SOllivier Robert peer_time[i] /= peer_count[i] 59c0b746e5SOllivier Robert peer_time_rms[i] = sqrt(peer_time_rms[i] / peer_count[i] - peer_time[i] * peer_time[i]) 60c0b746e5SOllivier Robert peer_delay[i] /= peer_count[i] 61c0b746e5SOllivier Robert peer_disp[i] /= peer_count[i] 62c0b746e5SOllivier Robert peer_tmax[i] = peer_tmax[i] - peer_time[i] 63c0b746e5SOllivier Robert peer_tmin[i] = peer_time[i] - peer_tmin[i] 64c0b746e5SOllivier Robert if (peer_tmin[i] > peer_tmax[i]) 65c0b746e5SOllivier Robert peer_tmax[i] = peer_tmin[i] 66c0b746e5SOllivier Robert printf "%-15s%5d%9.3f%9.3f%9.3f%9.3f%9.3f%9.3f\n", peer_ident[i], peer_count[i], peer_time[i] * 1e3, peer_time_rms[i] * 1e3, peer_tmax[i] * 1e3, peer_delay[i] * 1e3, peer_dist[i] * 1e3, peer_disp[i] * 1e3 67c0b746e5SOllivier Robert } 68c0b746e5SOllivier Robert} 69