1# --- prefix is inserted above by make ---
2#
3# Extract collection & expiration statistics from Log file.
4#
5# From: Mark Moraes <moraes@csri.toronto.edu>
6#
7# Heavily modified by Kim F. Storm:
8#  Added expiration statistics
9#  Will now make daily statistics & grand summary
10#  Split into two awk scripts to fit in argument list space
11#  (and as a side-effect to be able to use functions in old awk!!!)
12
13CHECK="0>0"
14LONG=0
15SUMMARY=1
16debug=false
17
18LOOP=true
19while $LOOP; do
20  case "$1" in
21  -l)	LONG=1
22	shift;;
23  -d)	CHECK="\$2!=\"$2\" || \$3!=\"$3\""
24	shift; shift; shift;;
25  -m)	CHECK="\$2!=\"$2\""
26	shift; shift;;
27  -t)   SUMMARY=0
28	shift;;
29  -D)	debug=true
30	shift;;
31  -*)   echo "unknown option: $1"
32	exit 1;;
33  *)	LOOP=false
34	;;
35  esac
36done
37
38grep '^[CX]:' `ls -tr ${@-$LOG}` |
39${AWK} 'BEGIN{
40  day="0"; l='$LONG'; t='$SUMMARY'
41  f=" %d %d %d %d %d %d %d\n"
42}
43'"$CHECK"' { next }
44day!=$3{
45  if(day!="0")print "d " date
46  if(l && day!="0" && (run>0 || xrun>0)){
47    print "h"
48    printf "c" f,run,art,Mart,gr,Mgr,sec,Msec
49    printf "e" f,xrun,xart,xMart,xgr,xMgr,xsec,xMsec
50  }
51  day=$3
52  date=$2 " " $3
53  run=art=gr=sec=0
54  Mart=Mgr=Msec=0
55  xrun=xart=xgr=xsec=0
56  xMart=xMgr=xMsec=0
57}
58$6=="Collect:" {
59  if ($7 <= 0) next
60  run++; art+=$7; gr+=$9; sec+=$11
61  Trun++; Tart+=$7; Tgr+=$9; Tsec+=$11
62  if ($7 > Mart) Mart=$7;
63  if ($9 > Mgr) Mgr=$9;
64  if ($11 > Msec) Msec=$11;
65  if ($11 > 0) A=$7 / $11; else A=$7;
66  if (A > Mps) Mps=A;
67  next
68}
69$6=="Expire:" {
70  if ($7 <= 0) next
71  xrun++; xart+=$7; xgr+=$9; xsec+=$11
72  xTrun++; xTart+=$7; xTgr+=$9; xTsec+=$11
73  if ($7 > xMart) xMart=$7
74  if ($9 > xMgr) xMgr=$9
75  if ($11 > xMsec) xMsec=$11
76  if ($11 > 0) A=$7 / $11; else A=$7
77  if (A > xMps) xMps=A
78  next
79}
80END{
81  if (day == "0") { print "Z"; exit }
82  print "d " date
83  if (l && (run > 0 || xrun > 0)) {
84    print "h"
85    printf "c" f,run,art,Mart,gr,Mgr,sec,Msec
86    printf "e" f,xrun,xart,xMart,xgr,xMgr,xsec,xMsec
87  }
88  if (t) {
89    print "H"
90    printf "C %d %d %d %d\n",Trun,Tart,Tsec,Mps
91    printf "E %d %d %d %d\n",xTrun,xTart,xTsec,xMps
92  }
93}' |
94if $debug ; then
95  cat
96else
97${AWK} 'BEGIN{
98 first=""
99}
100/^d/{
101 last=$2 " " $3
102 if (first == "") first=last
103 next
104}
105/^h/{
106 printf "\nStatistics for %s\n", last
107 next
108}
109/^H/{
110 tostr=""
111 if (first != last) tostr=" to " last
112 printf "\nSummary for %s%s:\n", first, tostr
113 next
114}
115/^[cC]/{tp="Collection"}
116/^[eE]/{tp="Expiration"}
117/^[ce]/{
118 if ($2 == 0) next
119 printf "\n  %s runs: %d\n", tp, $2
120 printf "%10d articles, average of %5d per run, maximum %6d\n", $3, $3/$2, $4
121 printf "%10d groups,   average of %5d per run, maximum %6d\n", $5, $5/$2, $6
122 printf "%10d seconds,  average of %5d per run, maximum %6d\n", $7, $7/$2, $8
123 next
124}
125/^[CE]/{
126 printf "\n  %s runs: %d\n", tp, $2
127 if ($2 == 0) next
128 printf "%10d articles, average of %5d per run\n", $3, $3/$2
129 printf "%10d seconds,  average of %5d per run\n", $4, $4/$2
130 if ($4>0) avg=$3/$4; else avg=$3
131 printf "    average of %d articles per second, maximum %d\n", avg, $5
132}
133/^Z/{
134 printf "Log is empty\n"
135}'
136fi
137
138