peer.awk revision 54359
154359Sroberto# awk program to scan peerstats files and report errors/statistics 254359Sroberto# 354359Sroberto# usage: awk -f peer.awk peerstats 454359Sroberto# 554359Sroberto# format of peerstats record 654359Sroberto# MJD sec ident stat offset (s) delay (s) disp (s) 754359Sroberto# 49235 11.632 128.4.2.7 f414 -0.000041 0.21910 0.00084 854359Sroberto# 954359Sroberto# format of output dataset (time values in milliseconds) 1054359Sroberto# peerstats.19960706 1154359Sroberto# ident cnt mean rms max delay dist disp 1254359Sroberto# ========================================================================== 1354359Sroberto# 140.173.112.2 85 -0.509 1.345 4.606 80.417 49.260 1.092 1454359Sroberto# 128.4.1.20 1364 0.058 0.364 4.465 3.712 10.540 1.101 1554359Sroberto# 140.173.16.1 1415 -0.172 0.185 1.736 3.145 5.020 0.312 1654359Sroberto#... 1754359Sroberto# 1854359SrobertoBEGIN { 1954359Sroberto n = 0 2054359Sroberto MAXDISTANCE = 1.0 2154359Sroberto} 2254359Sroberto# 2354359Sroberto# scan all records in file 2454359Sroberto# 2554359Sroberto# we toss out all distances greater than one second on the assumption the 2654359Sroberto# peer is in initial acquisition 2754359Sroberto# 2854359Sroberto{ 2954359Sroberto if (NF >= 7 && ($7 + $6 / 2) < MAXDISTANCE) { 3054359Sroberto i = n 3154359Sroberto for (j = 0; j < n; j++) { 3254359Sroberto if ($3 == peer_ident[j]) 3354359Sroberto i = j 3454359Sroberto } 3554359Sroberto if (i == n) { 3654359Sroberto peer_ident[i] = $3 3754359Sroberto peer_tmax[i] = peer_dist[i] = -1e9 3854359Sroberto peer_tmin[i] = 1e9 3954359Sroberto n++ 4054359Sroberto } 4154359Sroberto peer_count[i]++ 4254359Sroberto if ($5 > peer_tmax[i]) 4354359Sroberto peer_tmax[i] = $5 4454359Sroberto if ($5 < peer_tmin[i]) 4554359Sroberto peer_tmin[i] = $5 4654359Sroberto dist = $7 + $6 / 2 4754359Sroberto if (dist > peer_dist[i]) 4854359Sroberto peer_dist[i] = dist 4954359Sroberto peer_time[i] += $5 5054359Sroberto peer_time_rms[i] += $5 * $5 5154359Sroberto peer_delay[i] += $6 5254359Sroberto peer_disp[i] += $7 5354359Sroberto } 5454359Sroberto} END { 5554359Sroberto printf " ident cnt mean rms max delay dist disp\n" 5654359Sroberto printf "==========================================================================\n" 5754359Sroberto for (i = 0; i < n; i++) { 5854359Sroberto peer_time[i] /= peer_count[i] 5954359Sroberto peer_time_rms[i] = sqrt(peer_time_rms[i] / peer_count[i] - peer_time[i] * peer_time[i]) 6054359Sroberto peer_delay[i] /= peer_count[i] 6154359Sroberto peer_disp[i] /= peer_count[i] 6254359Sroberto peer_tmax[i] = peer_tmax[i] - peer_time[i] 6354359Sroberto peer_tmin[i] = peer_time[i] - peer_tmin[i] 6454359Sroberto if (peer_tmin[i] > peer_tmax[i]) 6554359Sroberto peer_tmax[i] = peer_tmin[i] 6654359Sroberto 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 6754359Sroberto } 6854359Sroberto} 69