home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / statgen / line.nawk next >
Encoding:
Text File  |  1991-12-18  |  4.3 KB  |  189 lines

  1. #! /bin/sh
  2.  
  3. # nawk script for producing summary listings of stats
  4. #
  5. #
  6.  
  7. nawk '
  8. BEGIN { 
  9.     FS = "|"
  10. }
  11. NF > 1 {
  12.     split ($1, parts, ":")
  13.     if (NR == 1) {
  14.         first_month = parts[1]; first_day = parts[2]
  15.         first_hour = parts[3]
  16.         first_min = parts[4] + 0
  17.         first_sec = parts[5] + 0
  18.     }
  19.     last_month = parts[1]; last_day = parts[2]
  20.     last_hour = parts[3]
  21.     last_min = parts[4]
  22.     last_sec = parts[5]
  23. }
  24. $2 == "Deliv" {
  25. # Format
  26. # date-time|Deliv|msgid|inchan|outchan|p1id|size|sender|inmta|recip|outmta|
  27. # 1         2     3     4      5       6    7    8      9     10    11
  28. # sub-time|queue-time
  29. # 12       13
  30.     next
  31. }
  32. $2 == "DR" {
  33. # Format
  34. # date-time|DR|type|msgid|p1id|size|inchan|dest|inhost|outchan|src|host|
  35. # 1         2  3    4     5    6    7      8    9      10      11  12
  36. # cchan|reason|diag|mesg
  37. # 13    14     15   16
  38. #   OR for positive & transit
  39. # cchan|submit-time|queued-time
  40. # 13    14        15
  41.     if (NF < 13 && NF > 15) {
  42.         print "Bad record line", NR, $0 | "cat 1>&2"
  43.         next
  44.     }
  45.     type = $3
  46.     if (type == "positive")
  47.         good_drs ++
  48.     else if (type == "negative")
  49.         bad_drs ++
  50.     else if (type == "transit")
  51.         trans_drs ++
  52.     else print "Unknown DR type", type, NR, $0 | "cat 1>&2"
  53. }
  54. $2 == "ok" {
  55. # Format
  56. # date-time|ok|msgid|inchan|outchan|p1id|size|sender|inmta|recip|outmta|
  57. # 1        2  3     4        5        6     7    8         9     10    11
  58. # msg|submit-time
  59. # 12  13
  60.     if (NF != 13) { 
  61.         print "Bad record line NR", $0 | "cat 1>&2"
  62.         next
  63.     }
  64.  
  65.     total_addr ++
  66.     msgid = $3
  67.     inchan = $4
  68.     outchan = $5
  69.     size = $7
  70.     inmta = $9
  71.     outmta = $11
  72.     if (im[msgid] == 0) {
  73.         total_msgs ++
  74.         total_size += size
  75.         im[msgid] = 1
  76.         inchan_size[inchan] += size
  77.         if (ih[inchan inmta] == 0) {
  78.             inchan_nhosts[inchan] ++
  79.             ih[inchan inmta] = 1
  80.         }
  81.         if (ih[inmta] == 0) {
  82.             total_inmta ++
  83.             ih[inmta] = 1
  84.         }
  85.         inchan_nmsgs[inchan] ++
  86.     }
  87.     inchan_naddr[inchan] ++
  88.  
  89.     if (om[msgid outchan] == 0) {
  90.         om[msgid outchan] = 1
  91.         outchan_size[outchan] += size
  92.         if (oh[outchan outmta] == 0) {
  93.             outchan_nhosts[outchan] ++
  94.             oh[outchan outmta] = 1
  95.         }
  96.         if (oh[outmta] == 0) {
  97.             total_outmta ++
  98.             oh[outmta] = 1
  99.         }
  100.         outchan_nmsgs[outchan] ++
  101.     }
  102.     outchan_naddr[outchan] ++;
  103.  
  104.     
  105.     cp = inchan " -> " outchan
  106.     chpair_naddr[cp] ++
  107.     if (cm[msgid cp] == 0) {
  108.         cm[msgid cp] = 1
  109.         chpair_size[cp] += size
  110.         chpair_nmsgs[cp] ++
  111.     }
  112. }
  113. #BEGIN(nawk)
  114. func bytes(n) {
  115.     if (n < 1000)
  116.         return sprintf ("%d", n)
  117.     if (n < 1000000)
  118.         return sprintf ("%.2fK", n / 1000.0)
  119.     else return sprintf ("%.2fM", n / 1000000.0)
  120. }
  121. #END(nawk)
  122. END {
  123.     printf "SUMMARY for period %d/%d %d:%02d:%02d to %d/%d %d:%02d:%02d\n", \
  124.         first_month, first_day, first_hour, first_min, first_sec, \
  125.         last_month, last_day, last_hour, last_min, last_sec
  126.  
  127.     printf "%-20s: %s\n", "Messages", bytes(total_msgs)
  128.     printf "%-20s: %s\n", "Addresses", bytes(total_addr)
  129.     printf "%-20s: %s\n", "Bytes", bytes(total_size)
  130.     
  131.     printf "%-20s: %s\n", "Inbound MTAs", bytes(total_inmta)
  132.     printf "%-20s: %s\n", "Outbound MTAs", bytes(total_outmta)
  133.     if (good_drs)
  134.         printf "%-20s: %s\n", "Positive DRs", bytes(good_drs)
  135.     if (bad_drs)
  136.         printf "%-20s: %s\n", "Negative Drs", bytes(bad_drs)
  137.     if (trans_drs)
  138.         printf "%-20s: %s\n", "Transiting Drs", bytes(trans_drs)
  139.     print "\n"
  140.  
  141.     print "Inbound Channel Totals"
  142.     title =  "Channel"
  143.     maxw = length(title)
  144.     for (i in inchan_naddr)
  145.         if (length(i) > maxw)
  146.             maxw = length(i)
  147.     format = "%-" maxw "s %8d %8d %8s %8s\n"
  148.     printf "%-" maxw "s %8s %8s %8s %8s\n", title, \
  149.         "Msgs", "Addr", "Bytes", "MTAs"
  150.     for (i in inchan_naddr)
  151.         printf format, i, \
  152.             inchan_nmsgs[i], inchan_naddr[i], \
  153.             bytes(inchan_size[i]) ,    inchan_nhosts[i]
  154.  
  155.     print ""; print "";
  156.     print "Outbound Channel Totals"
  157.     title = "Channel"
  158.     maxw = length(title)
  159.     if (length(i) > maxw)
  160.         maxw = length(i)
  161.     
  162.     for (i in outchan_naddr)
  163.         if (length(i) > maxw)
  164.             maxw = length(i)
  165.     printf "%-" maxw "s %8s %8s %8s %8s\n", title,\
  166.         "Msgs", "Addr", "Bytes", "MTAs"
  167.  
  168.     for (i in outchan_naddr)
  169.         printf "%-" maxw "s %8d %8d %8s %8s\n", i, \
  170.             outchan_nmsgs[i], outchan_naddr[i], \
  171.             bytes(outchan_size[i]), outchan_nhosts[i]
  172.  
  173.     print ""; print ""
  174.     print "Channel Pair Totals"
  175.     title = "Channel"
  176.     maxw = length(title)
  177.  
  178.     for (i in chpair_naddr)
  179.         if (length(i) > maxw)
  180.             maxw = length(i)
  181.     printf "%-" maxw "s %8s %8s %8s\n", title, \
  182.             "Msgs", "Addrs", "Bytes"
  183.     for (i in chpair_naddr)
  184.         printf "%-" maxw "s %8d %8d %8s\n", i, \
  185.             chpair_nmsgs[i], chpair_naddr[i], \
  186.             bytes(chpair_size[i])
  187.  
  188. }' $*
  189.