home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / N3 / NN-NNTP.TGZ / NN-NNTP.tar / usr / bin / nnstats < prev    next >
Text File  |  1994-09-13  |  3KB  |  158 lines

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