peer.awk revision 285612
1263646Sbapt# awk program to scan peerstats files and report errors/statistics 2263646Sbapt# 3263646Sbapt# usage: awk -f peer.awk peerstats 4263646Sbapt# 5263646Sbapt# format of peerstats record 6263646Sbapt# MJD sec ident stat offset (s) delay (s) disp (s) 7263646Sbapt# 49235 11.632 128.4.2.7 f414 -0.000041 0.21910 0.00084 8263646Sbapt# 9263646Sbapt# format of output dataset (time values in milliseconds) 10263646Sbapt# peerstats.19960706 11263646Sbapt# ident cnt mean rms max delay dist disp 12263646Sbapt# ========================================================================== 13263646Sbapt# 140.173.112.2 85 -0.509 1.345 4.606 80.417 49.260 1.092 14263646Sbapt# 128.4.1.20 1364 0.058 0.364 4.465 3.712 10.540 1.101 15263646Sbapt# 140.173.16.1 1415 -0.172 0.185 1.736 3.145 5.020 0.312 16263646Sbapt#... 17263646Sbapt# 18263646SbaptBEGIN { 19263646Sbapt n = 0 20263646Sbapt MAXDISTANCE = 1.0 21263646Sbapt} 22263646Sbapt# 23263646Sbapt# scan all records in file 24263646Sbapt# 25263646Sbapt# we toss out all distances greater than one second on the assumption the 26263646Sbapt# peer is in initial acquisition 27263646Sbapt# 28263646Sbapt{ 29263646Sbapt if (NF >= 7 && ($7 + $6 / 2) < MAXDISTANCE) { 30263646Sbapt i = n 31263646Sbapt for (j = 0; j < n; j++) { 32263646Sbapt if ($3 == peer_ident[j]) 33263646Sbapt i = j 34263646Sbapt } 35263646Sbapt if (i == n) { 36263646Sbapt peer_ident[i] = $3 37263646Sbapt peer_tmax[i] = peer_dist[i] = -1e9 38263646Sbapt peer_tmin[i] = 1e9 39263646Sbapt n++ 40263646Sbapt } 41263646Sbapt peer_count[i]++ 42263646Sbapt if ($5 > peer_tmax[i]) 43263646Sbapt peer_tmax[i] = $5 44263646Sbapt if ($5 < peer_tmin[i]) 45263646Sbapt peer_tmin[i] = $5 46263646Sbapt dist = $7 + $6 / 2 47263646Sbapt if (dist > peer_dist[i]) 48263646Sbapt peer_dist[i] = dist 49263646Sbapt peer_time[i] += $5 50263646Sbapt peer_time_rms[i] += $5 * $5 51263646Sbapt peer_delay[i] += $6 52263646Sbapt peer_disp[i] += $7 53263646Sbapt } 54263646Sbapt} END { 55263646Sbapt printf " ident cnt mean rms max delay dist disp\n" 56263646Sbapt printf "==========================================================================\n" 57263646Sbapt for (i = 0; i < n; i++) { 58263646Sbapt peer_time[i] /= peer_count[i] 59263646Sbapt peer_time_rms[i] = sqrt(peer_time_rms[i] / peer_count[i] - peer_time[i] * peer_time[i]) 60263646Sbapt peer_delay[i] /= peer_count[i] 61263646Sbapt peer_disp[i] /= peer_count[i] 62263646Sbapt peer_tmax[i] = peer_tmax[i] - peer_time[i] 63263646Sbapt peer_tmin[i] = peer_time[i] - peer_tmin[i] 64263646Sbapt if (peer_tmin[i] > peer_tmax[i]) 65263646Sbapt peer_tmax[i] = peer_tmin[i] 66263646Sbapt 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 67263646Sbapt } 68263646Sbapt} 69263646Sbapt