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

  1. From: vince@bcsaic.UUCP (Vince Skahan)
  2. Newsgroups: alt.sources
  3. Subject: Re: Log summaries
  4. Message-ID: <45562@bcsaic.UUCP>
  5. Date: 19 Apr 1991 20:55:46 GMT
  6.  
  7. I've had a couple of requests for perl-versions of the HDB report
  8. generator I posted the other day...
  9.  
  10. (there was a typo in the original awk one...there's an extra 
  11.     "{" in there at the beginning of the awk...
  12.     sorry 'bout that)
  13.  
  14. I've also included a sample data file to test on...
  15.  
  16. 1. unshar this puppy
  17. 2. invoke by "sort < hdb-summ.dat | hdb-summ.pl"
  18. 3. let me know if you improve or drastically simplify this
  19. 4. enjoy...
  20.  
  21.                     Vince
  22.  
  23. #!/bin/sh
  24. # to extract, remove the header and type "sh filename"
  25. if `test ! -s ./hdb_summ.pl`
  26. then
  27. cat > ./hdb_summ.pl << '\End\Of\Shar\'
  28. #!/usr/local/bin/perl
  29. #
  30. # hdb_summ.pl
  31. #
  32. # this generates a report totalled on a system!user basis for HDB uucp
  33. # (basically an edited a2p output of an old-awk original program)
  34. #
  35. # invoke by "sort < hdb-data-file | this_program.pl"
  36. #
  37. # ------------ sample data for incoming information ------------
  38. #
  39. #dsinc!uucp M (11/9-7:37:59) (C,701,1) [sio1] <- 475 / 5.933 secs, 80 bytes/sec
  40. #
  41. # ----------- sample data for outgoing information --------------
  42. #
  43. #dsinc!bcs212 M (11/9-8:02:16) (C,828,1) [sio1] -> 341 / 0.450 secs, 757 bytes/sec
  44. #
  45. #-------------------------------------------------------------------
  46.  
  47. # initialize NAME to nothing
  48. $NAME = ' ';
  49.  
  50. # step through the data file
  51. # outcoming data indicated by ->
  52. # ingoing data indicated by <-
  53. # find which system by /systemname/
  54.  
  55. # incoming
  56.  
  57. while (<>) {
  58.  
  59.     ($user,$Fld2,$start,$Fld4,$interface,$in_out,$bytes,$Fld8,$time) = split(' ', $_, 9999);
  60.  
  61.     #incoming
  62.     if (/<-/) {
  63.     $time_in = $time_in + $time;
  64.     $bytes_in = $bytes_in + $bytes;
  65.     $total_intime = $total_intime + $time;
  66.     $total_inbytes = $total_inbytes + $bytes;
  67.     }
  68.  
  69.     #outgoing
  70.     if (/->/) {
  71.     $time_out = $time_out + $time;
  72.     $bytes_out = $bytes_out + $bytes;
  73.     $total_outtime = $total_outtime + $time;
  74.     $total_outbytes = $total_outbytes + $bytes;
  75.     }
  76.  
  77.     if ($user ne $NAME) {
  78.     if ($NAME ne ' ') {
  79.         write;
  80.     }
  81.     $NAME = $user;
  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.  
  93.     if ((($user eq $NAME) || ($user eq ' '))) {    
  94.     if ($in_out eq '<-') {
  95.         $host_intime = $host_intime + $time;
  96.         $host_inbytes = $host_inbytes + $bytes;
  97.     }
  98.     else {
  99.         $host_outtime = $host_outtime + $time;
  100.         $host_outbytes = $host_outbytes + $bytes;
  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.  
  121. # summarize, print the last guy, and print the totals pretty
  122.  
  123. write;
  124.  
  125. $total_bytes = $total_inbytes + $total_outbytes;
  126. $total_time = $total_intime + $total_outtime;
  127.  
  128. if ($total_time > 0) {
  129.     $total_rate = $total_bytes / $total_time;
  130. }
  131. if ($total_intime > 0) {
  132.     $total_inrate = $total_inbytes / $total_intime;
  133. }
  134. if ($total_outtime > 0) {
  135.     $total_outrate = $total_outbytes / $total_outtime;
  136. }
  137.  
  138. if ((($total_inbytes > 0) || ($total_outbytes > 0))) {
  139.     $total_bytes = $total_inbytes + $total_outbytes;
  140.     $total_time = $total_intime + $total_outtime;
  141.     $total_pct_out = $total_outbytes * 100 / $total_bytes;
  142.  
  143.     $~ = "TOTALS";
  144.     write;
  145. }
  146.  
  147. format top =
  148.                                   Summary of UUCP Statistics
  149.                           Total              Incoming           Outgoing       Percent
  150.                       Bytes  Bytes/sec   Bytes  Bytes/sec   Bytes  Bytes/sec   Outgoing
  151.                       -----  ----------  ----   ---------   ----   ---------   --------
  152. .
  153.  
  154. format =
  155. @<<<<<<<<<<<        @>>>>>>>    @>>     @>>>>>>>   @>>   @>>>>>>>     @>>        @>>>
  156. $NAME,           $host_bytes, $host_rate, $host_inbytes, $host_inrate, $host_outbytes, $host_outrate, $host_pct_out
  157. .
  158.  
  159. format TOTALS =
  160.  
  161.                     @>>>>>>>    @>>     @>>>>>>>   @>>   @>>>>>>>     @>>        @>>>
  162.                 $total_bytes,$total_rate, $host_inbytes, $total_inrate, $total_outbytes,$total_outrate, $total_pct_out
  163.  
  164. .
  165.  
  166. \End\Of\Shar\
  167. fi
  168. if `test ! -s ./hdb_summ.dat`
  169. then
  170. cat > ./hdb_summ.dat << '\End\Of\Shar\'
  171. system1!username M (12/5-17:06:02) (C,991,1) [tty000] <- 101292 / 462.083 secs, 219 bytes/sec
  172. system1!username M (1/4-7:55:19) (C,1623,1) [tty000] -> 179 / 0.600 secs, 298 bytes/sec
  173. system1!username M (1/4-8:24:53) (C,1670,1) [tty000] <- 21514 / 98.616 secs, 218 bytes/sec
  174. system1!username M (1/4-8:29:42) (C,1679,1) [tty000] <- 18821 / 86.400 secs, 217 bytes/sec
  175. system1!username M (1/4-8:32:38) (C,1689,1) [tty000] -> 189 / 0.650 secs, 290 bytes/sec
  176. system1!username M (1/4-8:43:53) (C,1707,1) [tty000] <- 2341 / 11.066 secs, 211 bytes/sec
  177. system3!username M (1/5-14:57:46) (C,2345,1) [tty000] <- 49824 / 247.333 secs, 201 bytes/sec
  178. system1!username M (3/1-13:24:41) (C,526,1) [tty000] <- 112050 / 510.983 secs, 219 bytes/sec
  179. system1!username M (3/2-1:05:48) (C,913,1) [tty000] <- 21514 / 22.800 secs, 943 bytes/sec
  180. system2!username M (3/31-4:24:13) (C,2683,1) [tty000] <- 10343 / 47.683 secs, 216 bytes/sec
  181. system2!username M (4/13-5:30:16) (C,7613,1) [tty000] <- 705099 / 3215.050 secs, 219 bytes/sec
  182. \End\Of\Shar\
  183. fi
  184. exit
  185. -- 
  186.                          Vince Skahan   
  187.  vince@atc.boeing.com                  ...uw-beaver!bcsaic!vince
  188.  
  189. (ensure your child's future... fire and prosecute striking teachers !)
  190.