home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NNTP-1.000 / NNTP-1 / nntp.1.5.11t / support / nntp_awk.ucbva < prev    next >
Encoding:
Text File  |  1993-10-17  |  12.3 KB  |  459 lines

  1. # an awk script 
  2. # an NNTP log summary report generator
  3. #
  4. # NOTE: for systems that are not as yet using the new 4.3 BSD syslog
  5. # (and therefore have nntp messages lumped with everything else), it
  6. # would be best to invoke this script thusly:
  7. #
  8. #    egrep nntp syslog.old | awk -f nntp_awk > report_of_the_week
  9. #
  10. # because this script will include in the report all messages in the log
  11. # that it does not recognize (on the assumption that they are errors to
  12. # be dealt with by a human).
  13. #
  14. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  15. # May 17, 1986 - Norwegian Independence Day
  16. #
  17. # Recognize some new things - February 22, 1987
  18. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  19. #
  20. # fix "xmt is not an array" bug - March 11, 1987
  21. # Change Elapsed/CPU fields to break out time values, HH:MM:SS
  22. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  23. #
  24. # Add reporting for newnews commands - August 27, 1987
  25. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  26. #
  27. # Add nntpxmit connection attempt counting/reporting - December 7, 1987
  28. # Erik E. Fair <fair@ucbarpa.berkeley.edu>
  29. #
  30. BEGIN{
  31.     readers = 0;
  32.     transmit = 0;
  33.     receive = 0;
  34.     polled = 0;
  35. }
  36. ### Skip stderr reports from rnews
  37. {
  38.     n = split($6, path, "/");
  39.     if (path[n] == "rnews:") next;
  40.     n = split($7, path, "/");
  41.     if (path[n] == "rnews") next;
  42.     host = $6;
  43. }
  44. $7 == "group" {
  45.     readers = 1;
  46.     ng[$8]++;
  47.     next;
  48. }
  49. $7 == "ihave" {
  50.     receive = 1;
  51.     rec[host]++;
  52.     if ($9 == "accepted") {
  53.         rec_accept[host]++;
  54.         if ($10 == "failed") rec_failed[host]++;
  55.     } else if ($9 == "rejected") rec_refuse[host]++;
  56.     next;
  57. }
  58. # this is from version 1.4 of nntpd
  59. $7 == "ihave_stats" {
  60.     receive = 1;
  61.     rec[host] += $9 + $11 + $13;
  62.     rec_accept[host] += $9;
  63.     rec_refuse[host] += $11;
  64.     rec_failed[host] += $13;
  65.     next;
  66. }
  67. $7 == "connect" {
  68.     systems[host]++;
  69.     next;
  70. }
  71. # nntpxmit connection errors
  72. # Ooooh! I *wish* awk had N dimensional arrays,
  73. # so I wouldn't have to throw away the error message here!
  74. $7 == "hello:" {
  75.     conn[host]++;
  76.     if ($8 == "Connection" && $9 == "refused")
  77.         rmt_fail[host]++;
  78.     else
  79.         open_fail[host]++;
  80.     next;
  81. }
  82. # we'll get stats from this, don't count conn[]
  83. $7 == "xfer:" {
  84.     open_fail[host]++;
  85. # since these are expected to be few in number, we still print
  86. # the exact error (no "next;" statement here).
  87. }
  88. $7 == "greeted" {
  89.     conn[host]++;
  90.     rmt_fail[host]++;
  91.     next;
  92. }
  93. $7 == "host" && $8 == "unknown" {
  94.     conn[host]++;
  95.     ns_fail[host]++;
  96.     next;
  97. }
  98. # nntpd connection abort - all "broken pipe" right now
  99. $7 == "disconnect:" { next }
  100. # syslogd shit
  101. $7 == "repeated" { next }
  102. # inews shit
  103. $11 == "spooled" { next }
  104. $7 == "exit" {
  105.     if ($8 > 0) readers = 1;
  106.     articles[host] += $8;
  107.     groups[host] += $10;
  108.     next;
  109. }
  110. $7 == "xmit" {
  111.     xmt_cpu[host] += $9 + $11;
  112.     xmt_ela[host] += $13;
  113.     next;
  114. }
  115. $7 == "times" {
  116.     cpu[host] += $9 + $11;
  117.     ela[host] += $13;
  118.     next;
  119. }
  120. $7 == "stats" {
  121.     transmit = 1;
  122.     conn[host]++;
  123.     xmt[host] += $8;
  124.     xmt_accept[host] += $10;
  125.     xmt_refuse[host] += $12;
  126.     xmt_failed[host] += $14;
  127.     next;
  128. }
  129. #
  130. #    For the Nth time, I wish awk had two dimensional associative
  131. #    arrays. I assume that the last request is the same as all the
  132. #    others in this section of logfile.
  133. #
  134. $7 == "newnews" {
  135.     polled = 1;
  136.     poll[host] ++;
  137.     poll_asked[host] = $8;
  138.     next;
  139. }
  140. $7 == "newnews_stats" {
  141.     poll_offered[host] += $9;
  142.     poll_took[host] += $11;
  143.     next;
  144. }
  145. $7 == "post" {
  146.     readers = 1;
  147.     post[host]++;
  148.     next;
  149. }
  150. $7 == "timeout" {
  151.     timeout[host]++;
  152.     timeouts = 1;
  153.     next;
  154. }
  155. $7 == "unrecognized" {
  156.     unknown[host] = 1;
  157.     curious = 1;
  158. }
  159. ### Print anything that we don't recognize in the report
  160. {
  161.     print;
  162. }
  163. END{
  164.     printf("\n");
  165. ###############################################################################
  166. ### Article Exchange With Peers (other servers) Statistics                  ###
  167. ###############################################################################
  168.     if (transmit || receive || polled)
  169.         printf("NNTP peer article transfers\n\n");
  170.  
  171.     if (polled) for(s in poll) servers[s]++;
  172.     if (receive) for(s in rec) servers[s]++;
  173.     if (transmit) for(s in xmt) servers[s]++;
  174.  
  175.     if (receive) {
  176.         printf("Article Reception (they contact us)\n");
  177.         printf("System                  Offered  Took  Toss  Fail Toss   Elapsed       CPU  Pct\n");
  178.         for(s in rec) {
  179.  
  180.             nrec += rec[s];
  181.             nrec_accept += rec_accept[s];
  182.             nrec_refuse += rec_refuse[s];
  183.             nrec_failed += rec_failed[s];
  184.             nrec_cpu += cpu[s];
  185.             nrec_ela += ela[s];
  186.  
  187.             they_offered = rec[s];
  188.             if (they_offered == 0) they_offered = 1;
  189.             we_toss = (rec_refuse[s] / they_offered) * 100 + 0.5;
  190.  
  191.             e_hours      = ela[s] / 3600;
  192.             e_sec        = ela[s] % 3600;
  193.             e_min        = e_sec / 60;
  194.             e_sec        %= 60;
  195.  
  196.             c_hours      = cpu[s] / 3600;
  197.             c_sec        = cpu[s] % 3600;
  198.             c_min        = c_sec / 60;
  199.             c_sec        %= 60;
  200.  
  201.             tmp = ela[s];
  202.             if (tmp == 0) tmp = 1;
  203.             pct = ((cpu[s] / tmp) * 100.0 + 0.5);
  204.  
  205.             printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, rec[s], rec_accept[s], rec_refuse[s], rec_failed[s], we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  206.         }
  207.  
  208.         e_hours      = nrec_ela / 3600;
  209.         e_sec        = nrec_ela % 3600;
  210.         e_min        = e_sec / 60;
  211.         e_sec        %= 60;
  212.  
  213.         c_hours      = nrec_cpu / 3600;
  214.         c_sec        = nrec_cpu % 3600;
  215.         c_min        = c_sec / 60;
  216.         c_sec        %= 60;
  217.  
  218.         they_offered = nrec;
  219.         if (they_offered == 0) they_offered = 1;
  220.         we_toss = (nrec_refuse / they_offered) * 100 + 0.5;
  221.  
  222.         if (nrec_ela == 0) nrec_ela = 1;
  223.         pct = ((nrec_cpu / nrec_ela) * 100.0 + 0.5);
  224.  
  225.         printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nrec, nrec_accept, nrec_refuse, nrec_failed, we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  226.     }
  227.  
  228. ###############################################################################
  229.     if (polled) {
  230.         printf("Article Transmission (they poll us)\n");
  231.         printf("System                     Conn Offrd  Took   Elapsed       CPU  Pct  Groups\n");
  232.         npoll = 0;
  233.         npoll_offered = 0;
  234.         npoll_took = 0;
  235.         npoll_cpu = 0;
  236.         npoll_ela = 0;
  237.  
  238.         for(s in poll) {
  239.             npoll += poll[s];
  240.             npoll_offered += poll_offered[s];
  241.             npoll_took += poll_took[s];
  242.  
  243.             if (rec[s]) {
  244.                 printf("%-25s %5d %5d %5d  (see Article Reception)  %s\n", s, poll[s], poll_offered[s], poll_took[s], poll_asked[s]);
  245.             } else {
  246.                 npoll_ela += ela[s];
  247.                 npoll_cpu += cpu[s];
  248.  
  249.                 e_hours = ela[s] / 3600;
  250.                 e_sec   = ela[s] % 3600;
  251.                 e_min   = e_sec / 60;
  252.                 e_sec   %= 60;
  253.  
  254.                 c_hours = cpu[s] / 3600;
  255.                 c_sec   = cpu[s] % 3600;
  256.                 c_min   = c_sec / 60;
  257.                 c_sec   %= 60;
  258.  
  259.                 tmp = ela[s];
  260.                 if (tmp == 0) tmp = 1;
  261.                 pct = ((cpu[s] / tmp) * 100.0 + 0.5);
  262.  
  263.                 printf("%-25s %5d %5d %5d %3d:%02d:%02d %3d:%02d:%02d %3d%%  %s\n", s, poll[s], poll_offered[s], poll_took[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct, poll_asked[s]);
  264.             }
  265.         }
  266.         printf("\n%-25s %5d %5d %5d", "TOTALS", npoll, npoll_offered, npoll_took);
  267.         if (npoll_ela > 0 && npoll_cpu > 0) {
  268.  
  269.             e_hours = npoll_ela / 3600;
  270.             e_sec   = npoll_ela % 3600;
  271.             e_min   = e_sec / 60;
  272.             e_sec   %= 60;
  273.  
  274.             c_hours = npoll_cpu / 3600;
  275.             c_sec   = npoll_cpu % 3600;
  276.             c_min   = c_sec / 60;
  277.             c_sec   %= 60;
  278.  
  279.             tmp = npoll_ela;
  280.             if (tmp == 0) tmp = 1;
  281.             pct = ((npoll_cpu / tmp) * 100.0 + 0.5);
  282.  
  283.             printf(" %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  284.         } else
  285.             printf("\n\n");
  286.     }
  287.  
  288. ###############################################################################
  289.     if (transmit) {
  290.         printf("Article Transmission (we contact them)\n");
  291.         printf("System                    Offrd  Took  Toss  Fail  Pct   Elapsed       CPU  Pct\n");
  292.         for(s in xmt) {
  293.             we_offered = xmt[s];
  294.             if (we_offered == 0) we_offered = 1;
  295.             they_toss = (xmt_refuse[s] / we_offered) * 100 + 0.5;
  296.  
  297.             e_hours = xmt_ela[s] / 3600;
  298.             e_sec   = xmt_ela[s] % 3600;
  299.             e_min   = e_sec / 60;
  300.             e_sec   %= 60;
  301.  
  302.             c_hours = xmt_cpu[s] / 3600;
  303.             c_sec   = xmt_cpu[s] % 3600;
  304.             c_min   = c_sec / 60;
  305.             c_sec   %= 60;
  306.  
  307.             elapsed = xmt_ela[s];
  308.             if (elapsed == 0) elapsed = 1;
  309.             pct = ((xmt_cpu[s] / elapsed) * 100.0 + 0.5);
  310.  
  311.             printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, xmt[s], xmt_accept[s], xmt_refuse[s], xmt_failed[s], they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  312.  
  313.             nxmt        += xmt[s];
  314.             nxmt_accept += xmt_accept[s];
  315.             nxmt_refuse += xmt_refuse[s];
  316.             nxmt_failed += xmt_failed[s];
  317.             nxmt_ela    += xmt_ela[s];
  318.             nxmt_cpu    += xmt_cpu[s];
  319.         }
  320.  
  321.         we_offered = nxmt;
  322.         if (we_offered == 0) we_offered = 1;
  323.         they_toss = (nxmt_refuse / we_offered) * 100 + 0.5;
  324.  
  325.         e_hours = nxmt_ela / 3600;
  326.         e_sec   = nxmt_ela % 3600;
  327.         e_min   = e_sec / 60;
  328.         e_sec   %= 60;
  329.  
  330.         c_hours = nxmt_cpu / 3600;
  331.         c_sec   = nxmt_cpu % 3600;
  332.         c_min   = c_sec / 60;
  333.         c_sec   %= 60;
  334.  
  335.         if (nxmt_ela == 0) nxmt_ela = 1;
  336.         pct = ((nxmt_cpu / nxmt_ela) * 100.0 + 0.5);
  337.  
  338.         printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nxmt, nxmt_accept, nxmt_refuse, nxmt_failed, they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  339.  
  340.         printf("Transmission Connection Attempts         ------errors-------\n");
  341.         printf("System                     Conn    OK    NS   Net   Rmt  Pct\n");
  342.         for(s in xmt) {
  343.             tot = conn[s];
  344.             if (tot == 0) tot = 1;
  345.             errs = rmt_fail[s] + ns_fail[s] + open_fail[s];
  346.             ok = (conn[s] - errs);
  347.             printf("%-25s %5d %5d %5d %5d %5d %3d%%\n", s, conn[s], ok, ns_fail[s], open_fail[s], rmt_fail[s], (100.0 * errs / tot + 0.5));
  348.             ct_tot += conn[s];
  349.             ct_ok  += ok;
  350.             ct_ns  += ns_fail[s];
  351.             ct_net += open_fail[s];
  352.             ct_rmt += rmt_fail[s];
  353.         }
  354.         tot = ct_tot;
  355.         if (tot == 0) tot = 1;
  356.         errs = ct_ns + ct_net + ct_rmt;
  357.         printf("\n%-25s %5d %5d %5d %5d %5d %3d%%\n\n", "TOTALS", ct_tot, ct_ok, ct_ns, ct_net, ct_rmt, (100.0 * errs / tot + 0.5));
  358.     }
  359.  
  360. ###############################################################################
  361. ### Article Readership Statistics                                           ###
  362. ###############################################################################
  363.  
  364.     if (readers) {
  365.         printf("NNTP readership statistics\n");
  366.         printf("System                     Conn Articles Groups Post   Elapsed       CPU  Pct\n");
  367.         for(s in systems) {
  368. ###
  369. ### servers are different animals; they don't belong in this part of the report
  370. ###
  371.             if (servers[s] > 0 && groups[s] == 0 && articles[s] == 0)
  372.                 continue;
  373. ###
  374. ### report the curious server pokers elsewhere
  375. ###
  376.             if (groups[s] == 0 && articles[s] == 0 && post[s] == 0) {
  377.                 unknown[s] += systems[s];
  378.                 curious = 1;
  379.                 continue;
  380.             }
  381.  
  382.             nconn += systems[s];
  383.             nart += articles[s];
  384.             ngrp += groups[s];
  385.             npost += post[s];
  386.             ncpu += cpu[s];
  387.             nela += ela[s];
  388.  
  389.             e_hours      = ela[s] / 3600;
  390.             e_sec        = ela[s] % 3600;
  391.             e_min        = e_sec / 60;
  392.             e_sec        %= 60;
  393.  
  394.             c_hours      = cpu[s] / 3600;
  395.             c_sec        = cpu[s] % 3600;
  396.             c_min        = c_sec / 60;
  397.             c_sec        %= 60;
  398.  
  399.             elapsed = ela[s];
  400.             if (elapsed == 0) elapsed = 1;
  401.             pct = ((cpu[s] / elapsed) * 100 + 0.5);
  402.  
  403.             printf("%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, systems[s], articles[s], groups[s], post[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  404.         }
  405.  
  406.         e_hours      = nela / 3600;
  407.         e_sec        = nela % 3600;
  408.         e_min        = e_sec / 60;
  409.         e_sec        %= 60;
  410.  
  411.         c_hours      = ncpu / 3600;
  412.         c_sec        = ncpu % 3600;
  413.         c_min        = c_sec / 60;
  414.         c_sec        %= 60;
  415.  
  416.         if (nela == 0) nela = 1;
  417.         pct = ((ncpu / nela) * 100 + 0.5);
  418.  
  419.         printf("\n%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nconn, nart, ngrp, npost, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct);
  420.     }
  421.  
  422. ###############################################################################
  423.     if (curious) {
  424.         printf("Unknown NNTP server explorers\nSystem                     Conn\n");
  425.         for(s in unknown) {
  426.             printf("%-25s %5d\n", s, unknown[s]);
  427.         }
  428.         printf("\n");
  429.     }
  430. ###############################################################################
  431.     if (timeouts) {
  432.         printf("Server timeouts\n");
  433.         for(s in timeout) {
  434.             printf("%-25s %5d\n", s, timeout[s]);
  435.         }
  436.         printf("\n");
  437.     }
  438. ###############################################################################
  439.     if (readers) {
  440.         for(g in ng) {
  441.             x = length(g);
  442.             if (x > max) max = x;
  443.  
  444.             i = index(g, ".");
  445.             if (i > 0) top = substr(g, 1, i - 1);
  446.             else top = g;
  447.             category[top] += ng[g];
  448.         }
  449.         fmt = sprintf("%%-%ds %%5d\n", max);
  450.  
  451.         printf("Newsgroup Request Counts (by category)\n");
  452.         for(g in category) printf(fmt, g, category[g]);
  453.  
  454.         printf("\nNewsgroup Request Counts (by newsgroup)\n");
  455.         for(g in ng) printf(fmt, g, ng[g]);
  456.         printf("\n");
  457.     }
  458. }
  459.