home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3209 < prev    next >
Internet Message Format  |  1991-04-19  |  4KB

  1. From: vince@bcsaic.UUCP (Vince Skahan)
  2. Newsgroups: comp.mail.uucp,comp.lang.perl,alt.sources
  3. Subject: Re: Log summaries
  4. Message-ID: <45432@bcsaic.UUCP>
  5. Date: 18 Apr 91 15:19:21 GMT
  6.  
  7. In article <1991Apr16.070654.15375@pronto.mh.nl> Johan Vromans <jv@mh.nl> writes:
  8. >
  9. >>  Has anybody written a program (Perl?) to parse UUCP log files, to
  10. >> give an idea how much each UUCP connection's being used, and for how
  11. >> long?
  12. >
  13.  
  14. Here's a HDB UUCP report generator in sh and awk.... it should scream if you
  15. run it through a2p and use split rather than awk-isms   
  16.  
  17.  
  18.  
  19. #------------------------- cut here --------------------------------
  20. #!/bin/sh
  21.  
  22. STATS="/usr/spool/uucp/.Admin/xferstats"
  23. TMP="/tmp/hdb.tmp"
  24. cat $STATS | sort > $TMP            # sort by system then process
  25.  
  26. awk '{
  27.  
  28. #
  29. # ------------ sample data for incoming information ------------
  30. #
  31. #dsinc!uucp M (11/9-7:37:59) (C,701,1) [sio1] <- 475 / 5.933 secs, 80 bytes/sec
  32. #
  33. # ----------- sample data for outgoing information --------------
  34. #
  35. #dsinc!bcs212 M (11/9-8:02:16) (C,828,1) [sio1] -> 341 / 0.450 secs, 757 bytes/sec
  36. #
  37. #-------------------------------------------------------------------
  38.  
  39. BEGIN{
  40.  
  41. # initialize NAME to nothing
  42.    NAME=" "
  43.  
  44. # print header
  45.  
  46.    printf ("\n                        Summary of UUCP Statistics\n")
  47.    printf ("\n                               Total     Incoming     Outgoing      Percent\n")
  48.    printf ("                      Bytes  Bytes/sec   Bytes/sec    Bytes/sec     Outgoing\n")
  49.    printf ("                      -----  ----------  ---------    ---------     --------\n")
  50. }
  51.     
  52. # step through the data file
  53. # outcoming data indicated by ->
  54. # ingoing data indicated by <-
  55. # find which system by /systemname/
  56.  
  57. # incoming
  58. /<-/ {
  59.      time_in = time_in + $9 
  60.      bytes_in = bytes_in + $7
  61.      total_intime = total_intime + $9
  62.      total_inbytes = total_inbytes + $7
  63.     }                          
  64.  
  65. #outgoing
  66. /->/ {
  67.      time_out = time_out + $9 
  68.      bytes_out = bytes_out + $7
  69.      total_outtime = total_outtime + $9
  70.      total_outbytes = total_outbytes + $7
  71.     }
  72.  
  73. {
  74.  
  75.  if  ( $1 != NAME ) 
  76.   {  
  77.     if ( NAME != " " ) 
  78.       {
  79.       printf ("%15s   %7d %7d %11d %11d %13d  \n",  NAME, host_bytes, host_rate, host_inrate, host_outrate, host_pct_out);
  80.       }
  81.       NAME = $1
  82.       host_intime = 0
  83.       host_inbytes = 0
  84.       host_outtime = 0
  85.       host_outbytes = 0
  86.       host_time = 0
  87.       host_bytes = 0
  88.       host_inrate = 0
  89.       host_outrate = 0
  90.       host_pct_out = 0
  91.   }
  92.  if (( ( $1 == NAME ) || ( $1 == " " ) ))
  93.    {                                             
  94.     if ( $6 == "<-" ) {
  95.         host_intime = host_intime + $9 
  96.         host_inbytes = host_inbytes + $7 
  97.         }
  98.      else {
  99.          host_outtime = host_outtime + $9 
  100.          host_outbytes = host_outbytes + $7
  101.          }
  102.  
  103.     host_time = host_intime + host_outtime
  104.     host_bytes = host_inbytes + host_outbytes
  105.  
  106.     if ( host_time > 0 ) {
  107.         host_rate = host_bytes/host_time
  108.         }
  109.     if ( host_intime > 0 ) {
  110.         host_inrate = host_inbytes/host_intime
  111.         }
  112.      if ( host_outtime > 0 ) {
  113.         host_outrate = host_outbytes/host_outtime
  114.         }
  115.      if (host_bytes > 0 ) {
  116.         host_pct_out = host_outbytes * 100 / host_bytes
  117.        }
  118.     }
  119. }
  120. END {
  121.  
  122. # summarize, print the last guy, and print the totals pretty
  123.  
  124. printf ("%15s   %7d %7d %11d %11d %13d  \n",  NAME, host_bytes, host_rate, host_inrate, host_outrate, host_pct_out)
  125.  
  126. total_bytes = total_inbytes + total_outbytes
  127. total_time = total_intime + total_outtime
  128.  
  129. if ( total_time > 0 ) {
  130.     total_rate = total_bytes/total_time
  131.     }
  132. if ( total_intime > 0 ) {
  133.     total_inrate = total_inbytes/total_intime
  134.     }
  135. if ( total_outtime > 0 ) {
  136.     total_outrate = total_outbytes/total_outtime
  137.     }
  138.  
  139. if (( (total_inbytes > 0 ) || ( total_outbytes > 0 ) ))
  140.   {
  141.   total_bytes = total_inbytes + total_outbytes
  142.   total_time = total_intime + total_outtime
  143.   total_pct_out = total_outbytes * 100 / total_bytes
  144.   printf("\n")
  145.   printf("          total   %7d %7d %11d %11d %13d \n",  total_bytes, total_rate, total_inrate, total_outrate, total_pct_out);
  146.   printf("\n")
  147.   }
  148.  
  149. }' $TMP
  150.  
  151. rm $TMP
  152.  
  153.  
  154. -- 
  155. Vince Skahan   vince@atc.boeing.com  ...uw-beaver!bcsaic!vince
  156.  
  157. (what is there in the construction of mobile homes that seems 
  158.     to attract tornadoes ??? ) 
  159.