home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / gpm108b.zip / Utils / GPMSTAT.CMD < prev    next >
OS/2 REXX Batch file  |  1999-06-26  |  12KB  |  289 lines

  1. /*=========================================================================*\
  2. |* GPMSTAT v1.0.beta4.                                                     *|
  3. |* Log analyzer for General Purpose Mailer.                                *|
  4. |* Written by Igor Vanin (2:5030/448@fidonet, vanin@gpmail.spb.ru).        *|
  5. |* Small changes by Alex Batickii (2:5054/8@fidonet).                      *|
  6. \*=========================================================================*/
  7.  
  8. /* rexxutil.dll initialization */
  9. call rxfuncadd 'sysloadfuncs','rexxutil','sysloadfuncs'
  10. call sysloadfuncs
  11.  
  12. say 'GPMSTAT v1.0.beta4 - Log analyzer for General Purpose Mailer. 01.05.1999.'
  13. say 'Written by Igor Vanin (2:5030/448@fidonet, vanin@gpmail.spb.ru).'
  14. say 'Small changes by Alex Batickii (2:5054/8@fidonet).'
  15. say
  16.  
  17. /* name of configuration file */
  18. configfile='GPMSTAT.CFG'
  19.  
  20. /* default settings */
  21. lines=1
  22. inlog.1='GPMail.Log'
  23. outstat='GPMSTAT.TXT'
  24.  
  25. /* reading configuration file */
  26. say 'Reading configuration file 'configfile'.'
  27. call stream configfile,'c','open read'
  28. do until lines(configfile)=0
  29.    st=space(linein(configfile))
  30.    if length(st)=0 then iterate
  31.    if substr(st,1,1)=';' then iterate
  32.    interpret st
  33. end
  34. call stream configfile,'c','close'
  35. if symbol('inlog')='VAR' then inlog.1=inlog
  36.  
  37. call sysfiledelete outstat
  38. call stream outstat,'c','open write'
  39.  
  40. total.sessions=0; total.size.in=0; total.size.out=0
  41. total.hr=0; total.mn=0; total.sc=0; total.cps=0
  42. total.addrs=0
  43.  
  44. do c=1 to lines
  45.    drop data.
  46.    drop adrlist
  47.    inlog=inlog.c
  48.    call stream inlog,'c','open read'
  49.    say 'Working with log #'c': "'inlog'".'
  50.  
  51.    do until lines(inlog)=0
  52.       st=linein(inlog)
  53.       if length(st)>=17 then do
  54.          firsttime=substr(st,3,15)
  55.          leave
  56.       end
  57.    end
  58.  
  59.    line.c.addrs=0; line.c.sessions=0; line.c.size.in=0; line.c.size.out=0
  60.    line.c.hr=0; line.c.mn=0; line.c.sc=0; line.c.cps=0
  61.    if lines(inlog)=0 then do
  62.       say 'No data in log.'
  63.       if lines>1 then call charout outstat,'Line #'c': '
  64.       call lineout outstat,'No data in log'
  65.       call lineout outstat,''
  66.       iterate
  67.    end
  68.  
  69.    say 'Analyzing log...'
  70.    mlr='[unknown]'
  71.  
  72.    call stream inlog,'c','seek =0'
  73.    do until lines(inlog)=0
  74.       st=linein(inlog)
  75.  
  76.       if substr(st,24,16)='Remote software:' then do
  77.          mlr=substr(st,41,21)
  78.          ptr1=pos('/',mlr)
  79.          if ptr1>0 then mlr=substr(mlr,1,ptr1-1)
  80.       end
  81.       else if substr(st,1,1)='>' then if datatype(substr(st,24,1),number) then do
  82.          lasttime=substr(st,3,15)
  83.          ptr1=pos(', bytes ',st)
  84.          adr=substr(st,24,ptr1-24); ptr1=ptr1+8
  85.          ptr2=pos('@',adr); if ptr2>0 then adr=substr(adr,1,ptr2-1)
  86.          ptr2=pos('/',substr(st,ptr1))+ptr1-1
  87.          bytes_in=substr(st,ptr1,ptr2-ptr1)
  88.          ptr1=pos(', t',st); bytes_out=substr(st,ptr2+1,ptr1-ptr2-1)
  89.          time=substr(st,ptr1+7)
  90.          ptr1=pos(':',time); ptr2=lastpos(':',time)
  91.          hr2=substr(time,1,ptr1-1);
  92.          mn2=substr(time,ptr1+1,ptr2-ptr1-1); sc2=substr(time,ptr2+1)
  93.  
  94.          if data.adr.check\='1' then do
  95.             data.adr.check='1'
  96.             data.adr.size.in=0; data.adr.size.out=0
  97.             data.adr.sessions=0
  98.             data.adr.hr=0; data.adr.mn=0; data.adr.sc=0; data.adr.cps=0
  99.             data.adr.mailer=mlr
  100.             a=line.c.addrs
  101.             adrlist.a=adr
  102.             line.c.addrs=a+1
  103.          end
  104.          else if data.adr.mailer='[unknown]' then data.adr.mailer=mlr
  105.          data.adr.sessions=data.adr.sessions+1
  106.          data.adr.size.in=data.adr.size.in+bytes_in
  107.          data.adr.size.out=data.adr.size.out+bytes_out
  108.          /*data.adr.hr=data.adr.hr+hr2*/
  109.          /*data.adr.mn=data.adr.mn+mn2*/
  110.          tt=sc2+60*mn2+3600*hr2
  111.          data.adr.sc=data.adr.sc+tt
  112.          total.sessions=total.sessions+1
  113.          total.size.in=total.size.in+bytes_in; total.size.out=total.size.out+bytes_out
  114.          /*total.hr=total.hr+hr2; total.mn=total.mn+mn2; total.sc=total.sc+sc2*/
  115.          total.sc=total.sc+tt
  116.          line.c.sessions=line.c.sessions+1
  117.          line.c.size.in=line.c.size.in+bytes_in; line.c.size.out=line.c.size.out+bytes_out
  118.          /*line.c.hr=line.c.hr+hr2; line.c.mn=line.c.mn+mn2; line.c.sc=line.c.sc+sc2*/
  119.          line.c.sc=line.c.sc+tt
  120.       end
  121.    end
  122.    
  123.    if (line.c.addrs=0) then do
  124.       if lines>1 then call charout outstat,'Line #'c': '
  125.       call lineout outstat,'No data in log'
  126.       call lineout outstat,''
  127.       iterate
  128.    end
  129.  
  130.    if symbol('sortmode')='VAR' then call sort
  131.    
  132.    say 'Writing output to 'outstat'.'
  133.    if lines>1 then call charout outstat,'Line #'c': '
  134.    call lineout outstat,'Statistics since 'firsttime' to 'lasttime
  135.    call lineout outstat,''
  136.    if tabletype=1 then do
  137.       call lineout outstat,'╔═════════════════╤════╤═══════════╤═══════════╤════════╤═════════════════════╗'
  138.       call lineout outstat,'║ Address         │Sess│ Bytes IN  │ Bytes OUT │ Time   │ Mailer              ║'
  139.       call lineout outstat,'╟─────────────────┼────┼───────────┼───────────┼────────┼─────────────────────╢'
  140.    end
  141.    else do
  142.       call lineout outstat,'╔════════════════════╤════╤════════════╤════════════╤═══════════╤═══════╗'
  143.       call lineout outstat,'║ Address            │Sess│  Bytes IN  │ Bytes OUT  │Time Online│Avg.CPS║'
  144.       call lineout outstat,'╟────────────────────┼────┼────────────┼────────────┼───────────┼───────╢'
  145.    end
  146.    do i=0 to line.c.addrs-1
  147.       a=adrlist.i
  148.       if data.a.sc>0 then data.a.cps=trunc((data.a.size.in+data.a.size.out)/data.a.sc)
  149.       do while data.a.sc>=60; data.a.sc=data.a.sc-60; data.a.mn=data.a.mn+1; end
  150.       do while data.a.mn>=60; data.a.mn=data.a.mn-60; data.a.hr=data.a.hr+1; end
  151.  
  152.       if tabletype=1 then w=11; else w=12
  153.       data.a.size.in = '│'Right(COMMA(data.a.size.in),w)
  154.       data.a.size.out = '│'Right(COMMA(data.a.size.out),w)
  155.  
  156.       if tabletype=1 then w=17; else w=20
  157.       call charout outstat,'║'a''copies(' ',w-length(a))
  158.       call charout outstat,'│'data.a.sessions''copies(' ',4-length(data.a.sessions))
  159.       call charout outstat, data.a.size.in
  160.       call charout outstat, data.a.size.out
  161.       if tabletype=1 then w=8; else w=11
  162.       tmp=twodig(data.a.hr,' ')':'twodig(data.a.mn)':'twodig(data.a.sc)
  163.       if length(tmp)<w then tmp=copies(' ',w-length(tmp))''tmp
  164.       call charout outstat,'│'tmp
  165.       if tabletype=1 then do
  166.          call lineout outstat,'│'data.a.mailer''copies(' ',21-length(data.a.mailer))'║'
  167.       end
  168.       else do
  169.          call lineout outstat,'│'right(data.a.cps,7)'║'
  170.       end
  171.    end
  172.    if tabletype=1 then call lineout outstat,'╟─────────────────┼────┼───────────┼───────────┼────────┼─────────────────────╢'
  173.    else call lineout outstat,'╟────────────────────┼────┼────────────┼────────────┼───────────┼───────╢'
  174.  
  175.    if line.c.sc>0 then line.c.cps=trunc((line.c.size.in+line.c.size.out)/line.c.sc)
  176.    do while line.c.sc>=60; line.c.sc=line.c.sc-60; line.c.mn=line.c.mn+1; end
  177.    do while line.c.mn>=60; line.c.mn=line.c.mn-60; line.c.hr=line.c.hr+1; end
  178.    if tabletype=1 then w=10; else w=13
  179.    call charout outstat,'║Total: 'line.c.addrs''copies(' ',w-length(line.c.addrs))
  180.    call charout outstat,'│'line.c.sessions''copies(' ',4-length(line.c.sessions))
  181.    if tabletype=1 then w=11; else w=12
  182.    call charout outstat,'│'Right(COMMA(line.c.size.in),w)
  183.    call charout outstat,'│'Right(COMMA(line.c.size.out),w)
  184.    
  185.    if tabletype=1 then w=8; else w=11
  186.    tmp=twodig(line.c.hr,' ')':'twodig(line.c.mn)':'twodig(line.c.sc)
  187.    if length(tmp)<w then tmp=copies(' ',w-length(tmp))''tmp
  188.    call charout outstat,'│'tmp'│'
  189.    if tabletype=1 then call lineout outstat,'G.P.Mail - rulez :-) ║'
  190.    else call lineout outstat,right(line.c.cps,7)'║'
  191.    
  192.    
  193.    if tabletype=1 then call lineout outstat,'╚═════════════════╧════╧═══════════╧═══════════╧════════╧═════════════════════╝'
  194.    else call lineout outstat,'╚════════════════════╧════╧════════════╧════════════╧═══════════╧═══════╝'
  195.    call lineout outstat,''
  196.  
  197.    call stream inlog,'c','close'
  198. end
  199.  
  200. if lines>1 then do
  201.    if total.sc>0 then total.cps=trunc((total.size.in+total.size.out)/total.sc)
  202.    do while total.sc>=60; total.sc=total.sc-60; total.mn=total.mn+1; end
  203.    do while total.mn>=60; total.mn=total.mn-60; total.hr=total.hr+1; end
  204.    call lineout outstat,'Summary statistics for all 'lines' lines'
  205.    call lineout outstat,'╔════════════╤════╤═════╤═══════════╤═══════════╤════════╤═══════╗'
  206.    call lineout outstat,'║Line        │Sess│Addrs│ Bytes IN  │ Bytes OUT │  Time  │Avg.CPS║'
  207.    call lineout outstat,'╟────────────┼────┼─────┼───────────┼───────────┼────────┼───────╢'
  208.  
  209.    do c=1 to lines
  210.       call charout outstat,'║Line #'Left(c,6)
  211.       call charout outstat,'│'line.c.sessions''copies(' ',4-length(line.c.sessions))
  212.       call charout outstat,'│'line.c.addrs''copies(' ',5-length(line.c.addrs))
  213.       call charout outstat,'│'Right(COMMA(line.c.size.in),11)
  214.       call charout outstat,'│'Right(COMMA(line.c.size.out),11)
  215.       call charout outstat,'│'twodig(line.c.hr,' ')':'twodig(line.c.mn)':'twodig(line.c.sc)
  216.       call charout outstat,'│'right(line.c.cps,7)
  217.       call lineout outstat,'║'
  218.       /*total.addrs = total.addrs + line.c.addrs*/ /* φΓ« ¡Ñ Γá¬! */
  219.    end
  220.  
  221.    call lineout outstat,'╟────────────┼────┼─────┼───────────┼───────────┼────────┼───────╢'
  222.    call charout outstat,'║Total: 'Left(lines,5)
  223.    call charout outstat,'│'total.sessions''copies(' ',4-length(total.sessions))
  224.    /*call charout outstat,'│'total.addrs''copies(' ',5-length(total.addrs))*/
  225.    call charout outstat,'│     '
  226.    call charout outstat,'│'Right(COMMA(total.size.in),11)
  227.    call charout outstat,'│'Right(COMMA(total.size.out),11)
  228.    call charout outstat,'│'twodig(total.hr,' ')':'twodig(total.mn)':'twodig(total.sc)
  229.    call charout outstat,'│'right(total.cps,7)
  230.    call lineout outstat,'║'
  231.    call lineout outstat,'╚════════════╧════╧═════╧═══════════╧═══════════╧════════╧═══════╝'
  232.    call lineout outstat,''
  233. end
  234.  
  235. call lineout outstat,'                                      Generated by GPMSTAT ('date(e)' 'time(n)')'
  236. call stream outstat,'c','close'
  237.  
  238. exit
  239.  
  240.  
  241. twodig: procedure
  242.    if length(arg(1))>1 then return arg(1)
  243.    if arg()<2'' then thischar='0'
  244.    else thischar=arg(2)
  245.    tmpstr=copies(thischar,2-length(arg(1)))arg(1)
  246.    return tmpstr
  247. end
  248.  
  249.  
  250. comma: procedure
  251.    sOUT = strip(arg(1))
  252.    if Length(sOUT) > 9 then sOUT = Insert(',',sOUT,Length(sOUT)-9)
  253.    if Length(sOUT) > 6 then sOUT = Insert(',',sOUT,Length(sOUT)-6)
  254.    if Length(sOUT) > 3 then sOUT = Insert(',',sOUT,Length(sOUT)-3)
  255.    return sOUT
  256. end
  257.  
  258.  
  259. sort: procedure expose line. c adrlist. data. sortmode sortdir
  260.    if sortdir=d then s='<'
  261.    else s='>'
  262.    
  263.    if      sortmode=address then operation = 'result=a's'b'
  264.    else if sortmode=size    then operation = 'result=data.a.size.in+data.a.size.out's'data.b.size.in+data.b.size.out'
  265.    else if sortmode=sizein  then operation = 'result=data.a.size.in's'data.b.size.in'
  266.    else if sortmode=sizeout then operation = 'result=data.a.size.out's'data.b.size.out'
  267.    else if sortmode=time    then operation = 'result=data.a.sc's'data.b.sc'
  268.    else if sortmode=sess    then operation = 'result=data.a.sessions's'data.b.sessions'
  269.    else if sortmode=mailer  then operation = 'result=translate(data.a.mailer)'s'translate(data.b.mailer)'
  270.    else return
  271.    
  272.    say 'Sorting...'
  273.    /* say 'operation is "'operation'"' */ /* debug */
  274.    
  275.    do i=0 to line.c.addrs-2
  276.       do j=i+1 to line.c.addrs-1
  277.          a=adrlist.i; b=adrlist.j
  278.          interpret operation
  279.          if result then do
  280.             tmpstr=adrlist.i
  281.             adrlist.i=adrlist.j
  282.             adrlist.j=tmpstr
  283.          end
  284.       end
  285.    end
  286.    return
  287. end
  288.  
  289.