home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / db22re.zip / MON_DB.CMD < prev    next >
OS/2 REXX Batch file  |  1993-03-09  |  10KB  |  318 lines

  1. /*
  2.  ┌──────────────────────────────────────────────────────────────────┐
  3.  │  Name       : mon_db.cmd                                         │
  4.  │  Purpose    : Monitor log files for FRDEMO                       │
  5.  │  Platform   : DB2/2                                              │
  6.  │  Author     : Jeff Fisher                                        │
  7.  │               IBM Toronto Development Lab                        │
  8.  │  Disclaimer : This "sample" code is for demonstrations only, no  │
  9.  │               warrenties are made or implied as to correct       │
  10.  │               function. You should carefully test this code in   │
  11.  │               your own environment before using it.              │
  12.  │                                                                  │
  13.  └──────────────────────────────────────────────────────────────────┘
  14. */
  15.  
  16. signal on syntax
  17. signal on error
  18.  
  19. address cmd '@ECHO OFF'
  20. call SetColor
  21.  
  22.  
  23. Main:
  24. /*
  25.  ┌──────────────────────────────────────────────────────────────────┐
  26.  │ Main routine for program : run thru loop of collecting status    │
  27.  │                            and then freeing the resourse.        │
  28.  └──────────────────────────────────────────────────────────────────┘
  29. */
  30.     call CollectStatus
  31.  
  32.     call FreeResources
  33.  
  34.     signal Main
  35.  
  36.  
  37. CollectStatus:
  38. /*
  39.  ┌──────────────────────────────────────────────────────────────────┐
  40.  │ Collect the status, check and handle various types of sqlcodes.  │
  41.  │ if anyone is "on" the database, then do the display.             │
  42.  └──────────────────────────────────────────────────────────────────┘
  43. */
  44.     address cmd 'CLS'
  45.     say
  46.  
  47.     step = 'Collect All Status'
  48.     call SQLDBS 'COLLECT ALL STATUS for database FRDEMO USING :SSTAT'
  49.  
  50.     call CheckSafeSQLcode
  51.     if SafeSQLcode = 'Y' then signal CollectStatus
  52.     else
  53.         if SafeSQLcode = 'N' then signal ErrorSQL
  54.  
  55.     if SSTAT.10 > 0 then
  56.         do
  57.             dbname = SSTAT.12
  58.             call UserStat
  59.         end
  60.     else
  61.         do
  62.             say
  63.             say c.yellow '*** NO USERS AT THIS TIME ***'
  64.             say c.grey
  65.             pause
  66.         end
  67.  
  68.     return
  69.  
  70.  
  71. FreeResources:
  72. /*
  73.  ┌──────────────────────────────────────────────────────────────────┐
  74.  │ must free resources within the engine!                           │
  75.  └──────────────────────────────────────────────────────────────────┘
  76. */
  77.     step = 'Free Status Resources'
  78.     call SQLDBS 'FREE STATUS RESOURCES'
  79.  
  80.     call CheckSafeSQLcode
  81.     if SafeSQLcode = 'Y' then signal FreeResources
  82.     else
  83.         if SafeSQLcode = 'N' then signal ErrorSQL
  84.  
  85.     return
  86.  
  87.  
  88. UserStat:
  89. /*
  90.  ┌──────────────────────────────────────────────────────────────────┐
  91.  │ This loop is for individual users. The program will work for     │
  92.  │ as many users as are on the system.                              │
  93.  └──────────────────────────────────────────────────────────────────┘
  94. */
  95.     step = 'Get User Status loop'
  96.     tod = time()
  97.     CALL SQLDBS 'GET USER STATUS FOR DATABASE' dbname 'USING :USTAT'
  98.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  99.  
  100.     do i=1 to USTAT.0
  101.       address cmd 'CLS'
  102.       say
  103.       say
  104.  
  105.       if sstat.10 = 1 then
  106.         say c.yellow 'FRDEMO has'c.itmagenta sstat.10 c.yellow'user at' tod
  107.       else
  108.         say c.yellow 'FRDEMO has'c.itmagenta sstat.10 c.yellow'users at' tod
  109.       say
  110.  
  111.       if ustat.i.8 = '0' then ustat.i.8 = '00000'
  112.       say c.itmagenta '#'i c.itcyan 'Authid:'c.itgreen USTAT.i.6 c.itcyan 'Auth lvl:'c.itgreen USTAT.i.8
  113.  
  114.       checkvar = VERIFY(USTAT.i.7,' ')
  115.       if checkvar = 1 then USTAT.i.7 = '(local)'
  116.       say c.itcyan '    Node  :'c.itgreen USTAT.i.7
  117.  
  118.       say
  119.       say c.yellow   'Since START USING: '
  120.       say c.itcyan   '  UOWs                :'c.itgreen USTAT.i.1
  121.       say c.itcyan   '  SQL transactions    :'c.itgreen USTAT.i.2
  122.       say c.itcyan   '  Elapsed time (secs) :'c.itgreen USTAT.i.4
  123.       say
  124.       say c.yellow   'Current UOW:'
  125.       say c.itcyan   '  SQL transactions    :'c.itgreen USTAT.i.3
  126.       say c.itcyan   '  Elapsed time (secs) :'c.itgreen USTAT.i.5
  127.       call CalcTPS
  128.       say c.itcyan   '  TPS rate            :'c.itgreen TPS
  129.       if ustat.i.9 = 'S' then ustat.i.9 = 'Started'
  130.       if ustat.i.9 = 'R' then ustat.i.9 = 'Open, no changes'
  131.       if ustat.i.9 = 'C' then ustat.i.9 = 'Changed DB'
  132.         say c.itcyan '  Status              :'c.itgreen USTAT.i.9
  133.  
  134.       if ustat.i.10 = 'N' then
  135.         do
  136.           ustat.i.10 = 'NO'
  137.           say c.itcyan '  Waiting for LOCK?   :'c.itgreen USTAT.i.10
  138.         end
  139.       else
  140.         do
  141.           ustat.i.10 = 'YES'
  142.           say c.itcyan '  Waiting for LOCK?   :'c.itred   USTAT.i.10 '<---'
  143.         end
  144.       say
  145.       say c.normal
  146.       pause
  147.     end
  148.     return 0
  149.  
  150.  
  151. CalcTPS:
  152. /*
  153.  ┌──────────────────────────────────────────────────────────────────┐
  154.  │ Calculation of the TPS (within that UOW)                         │
  155.  └──────────────────────────────────────────────────────────────────┘
  156. */
  157.     tps = 0
  158.  
  159.     if ustat.i.3 = 0 then
  160.          do
  161.              tps = 0
  162.              return
  163.          end
  164.     if ustat.i.5 = 0 then
  165.          do
  166.              tps = 0
  167.              return
  168.          end
  169.  
  170.     tps = ustat.i.3 / ustat.i.5
  171.  
  172.     return
  173.  
  174.  
  175. CheckSafeSQLcode:
  176. /*
  177.  ┌──────────────────────────────────────────────────────────────────┐
  178.  │ Check for a "safe" sqlcode, which we will handle, versus a       │
  179.  │ fatal sqlcode. If there are further "safe" codes, they must      │
  180.  │ be hard coded in here along with their message.                  │
  181.  └──────────────────────────────────────────────────────────────────┘
  182. */
  183.     SafeSQLcode = 'N'
  184.  
  185.     SELECT
  186.         WHEN SQLCA.SQLCODE = 0 then
  187.           do
  188.             SafeSQLcode = '0'
  189.           end
  190.         WHEN SQLCA.SQLCODE = -1033 then
  191.           do
  192.             SafeSQLcode = 'Y'
  193.             say
  194.             say c.yellow '*** Database cannot be opened for status ***'
  195.             say c.yellow '*** Database directory being updated     ***'
  196.           end
  197.         WHEN SQLCA.SQLCODE = -1035 then
  198.           do
  199.             SafeSQLcode = 'Y'
  200.             say
  201.             say c.yellow '*** Database cannot be opened for status ***'
  202.             say c.yellow '*** Another user has exclusive use of it ***'
  203.           end
  204.         WHEN SQLCA.SQLCODE = -1119 then
  205.           do
  206.             SafeSQLcode = 'Y'
  207.             say
  208.             say c.yellow '*** A Database Restore is in progress ***'
  209.           end
  210.         WHEN SQLCA.SQLCODE = -1117 then
  211.           do
  212.             SafeSQLcode = 'Y'
  213.             say
  214.             say c.yellow '*** A Roll Forward is pending ***'
  215.           end
  216.         OTHERWISE SafeSQLcode = 'N'
  217.     END
  218.  
  219.     SELECT
  220.         WHEN SafeSQLcode = 'Y' then
  221.           do
  222.             say c.yellow '    Press <enter> when the   '
  223.             say c.yellow '    function is complete     '
  224.             say c.yellow '    in order to continue...  '
  225.             say c.grey
  226.             pause
  227.           end
  228.         OTHERWISE NOP
  229.     END
  230.  
  231.     return
  232.  
  233.  
  234. EndProg:
  235. /*
  236.  ┌──────────────────────────────────────────────────────────────────┐
  237.  │ end program, reset colors.                                       │
  238.  └──────────────────────────────────────────────────────────────────┘
  239. */
  240.     say c.normal
  241.  
  242.     address cmd 'CLS'
  243.  
  244.     'exit'
  245.  
  246.  
  247. Error:
  248. /*
  249.  ┌──────────────────────────────────────────────────────────────────┐
  250.  │ error                                                            │
  251.  └──────────────────────────────────────────────────────────────────┘
  252. */
  253.     call beep 220,1000
  254.     say c.itred
  255.     say '        >>>  Rexx has returned a signal on error'
  256.     say '             abending step = ' step
  257.     say '             source line   = ' sourceline(sigl)
  258.     say
  259.     pause
  260.     signal EndProg
  261.  
  262.  
  263. Syntax:
  264. /*
  265.  ┌──────────────────────────────────────────────────────────────────┐
  266.  │ rexx syntax bug                                                  │
  267.  └──────────────────────────────────────────────────────────────────┘
  268. */
  269.     call beep 220,1000
  270.     say c.itred
  271.     say '        >>>  Rexx has returned a signal on syntax'
  272.     say '             abending step = ' step
  273.     say '             source line   = ' sourceline(sigl)
  274.     say
  275.     pause
  276.     signal EndProg
  277.  
  278.  
  279. ErrorSQL:
  280. /*
  281.  ┌──────────────────────────────────────────────────────────────────┐
  282.  │ sql error handling routine                                       │
  283.  └──────────────────────────────────────────────────────────────────┘
  284. */
  285.     call beep 220,1000
  286.     say c.itred
  287.     say '        >>>  SQL has returned a fatal condition code'
  288.     say '             abending step = ' step
  289.     say '             SQLCODE       = ' SQLCA.SQLCODE
  290.     say '             MSG           = ' SQLMSG
  291.     say
  292.     pause
  293.     signal EndProg
  294.  
  295.  
  296. SetColor:
  297. /*
  298.  ┌──────────────────────────────────────────────────────────────────┐
  299.  │ set colors with ansi escape chars                                │
  300.  └──────────────────────────────────────────────────────────────────┘
  301. */
  302.     ansii.esc      = '1B'x
  303.     c.normal       = ansii.esc || '[0m'
  304.     c.highlite     = ansii.esc || '[1m'
  305.     c.blackback    = ansii.esc || '[40m'
  306.     c.grey         = c.normal || ansii.esc || '[37m'
  307.     c.itred        = c.highlite || ansii.esc || '[31m'
  308.     c.itnormal     = c.highlite || ansii.esc || '[32m'
  309.     c.yellow       = c.highlite || ansii.esc || '[33m'
  310.     c.itgreen      = c.highlite || ansii.esc || '[32m'
  311.     c.itblue       = c.highlite || ansii.esc || '[34m'
  312.     c.itmagenta    = c.highlite || ansii.esc || '[35m'
  313.     c.itcyan       = c.highlite || ansii.esc || '[36m'
  314.     c.white        = c.highlite || ansii.esc || '[37m'
  315.     c.std          = c.normal || c.itcyan || c.blackback
  316.     c.reset        = c.normal || c.grey || c.blackback
  317.     return 0
  318.