#!/bin/sh - # $Id: mh-list-traffic,v 1.3 2003/06/01 18:37:13 sra Exp $ # # Hack to calculate some traffic statistics that I find useful in # trying to understand certain forms of pathological behavior on large # mailing lists. Assumes that you have a local archive of the # messages to be analyzed in an MH folder. Default period is the last # seven days, use the "since" shell variable to change this. # # Sort order in the final list is weighted 50/50 by number of messages # and number of bytes, carried to some ridiculous number of # significant digits because awk was calculating all those digits for # me anyway, so what the heck. # # This script was developed using nmh, GNU sort, and GNU awk. It may # work for other variants on these programs, then again it may not. # # This script is hereby explictly placed in the public domain as # Beer-Ware. If we meet some day and you think this script is worth # it, you can buy me a beer. Your mileage may vary. We decline # responsibilities, all shapes, all sizes, all colors. If this # script breaks, you get to keep both pieces. : ${since=-7} pick -after "$since" | xargs scan -format '%(size) %(mbox{from})@%(host{from})' | tr A-Z a-z | awk ' { nm++; nb += $1; m[$2]++; b[$2] += $1; } function oneline(mi, bi, i) { pm = mi * 100 / nm; pb = bi * 100 / nb; p = (pm + pb); printf "%14.10f |%6.2f%% |%5d |%6.2f%% |%9d | %s\n", p, pm, mi, pb, bi, i; } END { for (i in m) oneline(m[i], b[i], i); oneline(nm, nb, "Total"); }' | sort -nr | awk ' BEGIN { print " Messages | Bytes | Who"; print "--------+------+--------+----------+------------------------"; } { sub(/^[0-9. ]+\|/,""); if (NR == 1) total = $0; else print; } END { print "--------+------+--------+----------+------------------------"; print total; }'