local -r log_file="$1"
(
- echo 'mac ip last first freq dist'
- echo '--- -- ---- ----- ---- ----'
+ echo 'mac ip staleness_cur staleness_avg age freq dist'
+ echo '--- -- ------------- ------------- --- ---- ----'
sort -n -k 1 "$log_file" \
| awk -v now="$(date '+%s')" \
'
mac = $2
ip = $3
+ interval[mac, ip, intervals[mac, ip]++] = ts - seen_last[mac, ip]
freq[mac, ip]++
if (!seen_last[mac, ip] || ts > seen_last[mac, ip] ) seen_last[mac, ip] = ts
if (!seen_first[mac, ip] || ts < seen_first[mac, ip]) seen_first[mac, ip] = ts
split(key, macip, SUBSEP)
mac = macip[1]
ip = macip[2]
- last = now - seen_last[mac, ip]
- first = now - seen_first[mac, ip]
+ staleness_cur = now - seen_last[mac, ip]
+ age = now - seen_first[mac, ip]
dist = 100 * (freq[mac, ip] / NR)
+ intervals_sum = 0
+ for (i=1; i<=intervals[mac, ip]; i++)
+ intervals_sum += interval[mac, ip, i]
+ staleness_avg = intervals_sum / intervals[mac, ip]
print \
mac, \
ip, \
- sprintf("%d", last), \
- sprintf("%d", first), \
+ sprintf("%d", staleness_cur), \
+ sprintf("%d", staleness_avg), \
+ sprintf("%d", age), \
freq[mac, ip], \
sprintf("%d", dist)
}