Previous Topic: 10.5 Sample Programs

Next Topic: Appendix A. MESSAGES

USRMXA VM Sample Monitor Writer Driver Program


+----------+
| USRMXA   | VM Sample Monitor Writer Driver Program
+----------+

The USRMXA SAMPLE is a front-end program that drives VM
Monitor writer (MONWRITE), names Monitor data files, and
signals VM Data Transfer Program for VM Monitor data
transmission when data is created.

To use the distributed sample, enter the command:

COPYFILE USRMXA SAMPLE A USRMXA EXEC A (LRECL 72 TRUNC

The sample USRMXA EXEC provided with the distributed code can
be modified to suit the needs of your installation.  See the
EXEC's prolog for further information.  The modifications can
be made directly to the EXEC by using CMS XEDIT command.

The tailored EXEC program must be accessible to VM Monitor
writer's virtual machine (for example, copy the EXEC to its
191 disk).  This EXEC is intended to run as a pair with the
STARTMXA EXEC.

The code sample is distributed as follows.

 /*------------------------------------------------------------------*/
 /* //// NOTE ////////// NOTE //////////// NOTE ////////// NOTE //// */
 /*        *****  THIS IS  A  SAMPLE  PROGRAM  *****                 */
 /*                                                                  */
 /*  This program and the STARTMXA EXEC provides a support for       */
 /*  controlling the collection of monitor data in VM.               */
 /*                                                                  */
 /*  This EXEC program should be copied to one of VM monitor         */
 /*  writer's minidisk, which is always accessible (for example,     */
 /*  191 disk).                                                      */
 /*                                                                  */
 /*                                                                  */
 /*------------------------------------------------------------------*/

 /*------------------------------------------------------------------*/
 /*   //// IMPORTANT !!!!!! IMPORTANT !!!!!! IMPORTANT !!!!!! ////   */
 /*                                                                  */
 /*   Set up the following parameters before starting this program:  */
 /*                                                                  */
 /*   MONDCSS : is the name of the MONITOR DCSS.                     */
 /*   IUCV    : is the userid of the IUCV server that notifies       */
 /*             the Monitor writer about data in the DCSS.           */
 /*   APPL    : is the name of the IUCV application program running  */
 /*             in a virtual machine specified by IUCV.  It should   */
 /*             be null ('') if IUCV is defines to be '*MONITOR'.    */
 /*             Otherwise, it is required.                           */
 /*   MXAFM   : is the filemode to which the monitor output will     */
 /*             be written.                                          */
 /*   VMT     : is the userid on which the CA MICS VM Data Transfer  */
 /*             Program runs.                                        */
 /*   ERROP   : is a userid who will be notified if an error occurs. */
 /*                                                                  */
    MONDCSS  = 'MONDCSS'                  /*  <<<<-------  */
    IUCV     = '*MONITOR'                 /*  <<<<-------  */
    APPL     = ''                         /*  <<<<-------  */
    MXAFM    = 'A'                        /*  <<<<-------  */
    VMT      = 'MAICMS'                   /*  <<<<-------  */
    ERROP    = 'OPERATOR'                 /*  <<<<-------  */

 /* ---------------------------------------------------------------- */
 /* ///////         END OF PARAMETER TAILORING              //////// */
 /*------------------------------------------------------------------*/
 upper VMT

 parse value diag(0C) with date +8 time +8 .
 fname = 'D' || space(translate(date,' ','/'),0)
 ftype = 'T' || space(translate(time,' ',':'),0)

 'MONWRITE' MONDCSS IUCV APPL 'DISK' fname ftype MXAFM
 ec = rc
 if ec ^= 0 then do                                   /* PROBLEM !   */
    msgtext = 'Error!  MONWRITE program cannot be started',
              'or an error occurs.   RC=' ec
    say msgtext
    'CP MSG' errop msgtext
    call exit ec
 end
 /*   MONWRITE is running ..........                                 */
 /*   MONWRITE is stopped now.                                       */
 'ESTATE' fname ftype mxafm
 ec = rc
 if ec=0 then do
   say; say 'The data file created is:' fname ftype mxafm
   rx = diagrc(8,'SMSG' VMT 'TRANSFER MONXA' fname ftype)
   ec = word(rx,1)
   if ec ^= 0 then do
     msgtext = 'An error occurs when attempting to SMSG' VMT ,
     'to start the transmission of monitor data' fname ftype mxafm
     say msgtext
     'CP MSG' errop msgtext
     msgtext = 'Message:' substr(rx,17)
     say msgtext
     'CP MSG' errop msgtext
     'CP MSG' errop 'Please notify your CA MICS administrator or Systems',
     'Programmer'
   end
 end
 exit ec


USAGE NOTES

The USRMXA EXEC retrieves the current date and time for the
filename and filetype of the Monitor data file by using
Diagnose X'0C' with all the nonalphanumeric characters
removed.  The format of the file ID is 'Ddate Ttime'.

STARTMXA VM Sample Monitor Data Collection Driver

+----------+
| STARTMXA | VM Sample Monitor Data Collection Driver
+----------+

The STARTMXA EXEC is a sample program that controls the
USRMXA EXEC from another virtual machine.  A virtual machine
to run this EXEC is required to be set up as the secondary
user of the MONWRITE virtual machine.

The EXEC uses the CP SEND command to pass commands to the
MONWRITE virtual machine for execution.  The program starts
the MONWRITE and monitor by executing the USRMXA EXEC, and
stops the MONWRITE (therefore stops the monitor) by issuing a
#CP EXTERNAL command at a predetermined schedule.  The
timetable to control the process of monitor collection can be
set by modifying CLOCK.i variables, where i is an integer
ranging from 1 to as many times as you want to cut the VM
Monitor data each day.

To use the distributed sample, enter the command:

COPYFILE STARTMXA SAMPLE A STARTMXA EXEC A (LRECL 72 TRUNC

The sample STARTMXA EXEC provided with the distributed code
can be modified to suit the needs of your installation.  See
the EXEC's prolog for further information.  The modifications
can be made directly to the EXEC by using CMS XEDIT command.

This EXEC is intended to run as a pair with the USRMXA EXEC.


 /*------------------------------------------------------------------*/
 /* //// NOTE ////////// NOTE //////////// NOTE ////////// NOTE //// */
 /*            ***** THIS IS A SAMPLE PROGRAM *****                  */
 /*                                                                  */
 /*  Set up the cut-off time for VM Monitor data here.               */
 /*                                                                  */
 /*  MONSESS : Number of times the monitor data will be cut per day. */
 /*  CLOCK.x : The wall clock time at which the monitor data is cut. */
 /*            The format is 'HH:MM:SS', where HH is the hour of     */
 /*            day, MM is the minute of the hour, SS is the second   */
 /*            of the minute.                                        */
 /*            x is one of the value from 1 to MONSESS               */
 /*                                                                  */
 /*      The following example shows that monitor data should be     */
 /*  cut three times a day: at midnight, 9 o'clock in the morning    */
 /*  and 5:30 in the afternoon, respectively.                        */
 /*                                                                  */
     MONSESS  = 3
     CLOCK.1  = '00:00:00'                    /*     1st session     */
     CLOCK.2  = '09:00:00'                    /*     2nd session     */
     CLOCK.3  = '17:30:00'                    /*     3rd session     */
                                              /*     ......          */
 /*------------------------------------------------------------------*/

 call ValidClock

 /*------------------------------------------------------------------*/
 /*   //// IMPORTANT !!!!!! IMPORTANT !!!!!! IMPORTANT !!!!!! ////   */
 /*                                                                  */
 /*  Specify the VM Monitor writer and CP MONITOR commands here:     */
 /*                                                                  */
 /*   WRITER   : is the userid of the VM Monitor writer.  The        */
 /*              default is 'MONWRITE'.  If your system uses a       */
 /*              different name, be sure to change it here.          */
 /*                                                                  */
 /*   ERROP    : specifies the userid that will be notified if an    */
 /*              error occurs.                                       */
 /*                                                                  */
     WRITER = 'MONWRITE'           /*  <<<--- Enter correct ID here  */
     ERROP  = 'OPERATOR'           /*  <<<--- Error message receiver */
 /*                                                                  */
 /*   MONITOR EVENT:                                                 */
 /*   MONITOR SAMPLE:                                                */
 /*              establish a profile for event and sample data       */
 /*              collection here.  For exact syntax, please refer    */
 /*              to the IBM manual.                                  */
 /*              The VM Monitor writer must be in privilege          */
 /*              class A or E to issue the MONITOR commands.         */
 /*                                                                  */
 /*   Note:  The following MONITOR commands have been commented out. */
 /*          Remove the comment if enabling of monitor domain will   */
 /*          be controlled here.                                     */
 /*                                                                  */
 /* !!!!!!   DELETE THIS LINE TO ISSUE MONITOR COMMANDS !!!!!!       */

     SENDMXA = 'CP SEND' WRITER
     SENDMXA '#CP MONITOR EVENT ENABLE I/O ALL'
     SENDMXA '#CP MONITOR EVENT ENABLE USER ALL'
     SENDMXA '#CP MONITOR EVENT ENABLE PROCESSOR'
     SENDMXA '#CP MONITOR EVENT ENABLE STORAGE'
     SENDMXA '#CP MONITOR SAMPLE ENABLE I/O ALL'
     SENDMXA '#CP MONITOR SAMPLE ENABLE USER ALL'
     SENDMXA '#CP MONITOR SAMPLE ENABLE PROCESSOR'
     SENDMXA '#CP MONITOR SAMPLE ENABLE STORAGE'
     SENDMXA '#CP MONITOR SAMPLE INTERVAL 1 MIN'
     SENDMXA '#CP MONITOR SAMPLE RATE 1 SEC'

 /*  !!!!!!   DELETE THIS LINE TO ISSUE MONITOR COMMANDS   !!!!!!    */
 /* ---------------------------------------------------------------- */
 /* ///////         END OF PARAMETER TAILORING              //////// */
 /*------------------------------------------------------------------*/
 upper WRITER

 do forever
   ec = StartUp()
   if ec ^= 0 then leave
   newclock = clock.1
   ctime = substr(diag(0C),9,8); say 'Current time is:' ctime
   do i=1 to monsess
     if clock.i > ctime then do
        newclock = clock.i
        leave
     end
   end

   /*   SLEEPUNTIL can be replaced by your own timer utility         */
   call SleepUntil newclock

   rx = diagrc(8,'SEND' WRITER '#CP EXTERNAL')
   ec = word(rx,1)
   if ec ^= 0 then do
     msg1 = 'An error occurred when attempting to stop' WRITER ,
            '( RC=' ec ')'
     msg2 = 'Message:' substr(rx,17)
     call ErrMsg msg1
     call ErrMsg msg2
     leave
  end

 end
 exit

 StartUp:
  rx = diagrc(8,'SEND' WRITER 'EXEC USRMXA')
  ec = word(rx,1)
  if ec ^= 0 then do
    msg1 = 'An error occurred while attempting to start USRMXA',
           '( RC=' ec ')'
    msg2 = 'Message:' substr(rx,17)
    call ErrMsg msg1
    call ErrMsg msg2
    return ec
  end
  'CP SLEEP 10 SEC'
  rx = diagrc(8,'SEND' WRITER '#CP MONITOR START')
  ec = word(rx,1)
  if ec ^= 0 then do
    msg1 = 'An error occurred while attempting to start the MONITOR',
           '( RC=' ec ')'
    msg2 = 'Message:' substr(rx,17)
    call ErrMsg msg1
    call ErrMsg msg2
    return ec
  end
 return 0

 SleepUntil:
 arg newclock
   call Waitm ctime newclock
   if hourwait > 0 then  'CP SLEEP' hourwait 'HR'
   if minwait > 0  then  'CP SLEEP' minwait 'MIN'
   if secwait > 0  then  'CP SLEEP' secwait 'SEC'
 return

 Waitm: procedure expose hourwait minwait secwait
 arg ctime ntime .
 parse var ctime chour ':' cmin ':' csec
 parse var ntime nhour ':' nmin ':' nsec
 select
   when nhour < chour then  nhour = nhour + 24
   when nhour = chour then
      if ^ (nmin > cmin) then nhour = nhour + 24
   otherwise nop
 end
 wsec = nhour * 3600 + nmin * 60 + nsec - chour * 3600 - cmin*60 - csec
 secwait  = wsec // 60
 wmin     = wsec % 60
 hourwait = wmin % 60
 minwait  = wmin // 60
 return

 ValidClock:
 if ^ datatype(monsess,'W') then do
   say 'Invalid number specified for MONSESS.'
   exit
 end
 do i=1 to monsess
  parse var clock.i hr ':' mn ':' sc .
  if datatype(hr,'W') & datatype(mn,'W') & datatype(sc,'W') then nop
  else do
     say 'Invalid clock time specified for CLOCK.'i
     exit
  end
  clock.i = right(hr,2,'0') || ':' || right(mn,2,'0') || ':' ,
            || right(sc,2,'0')
 end
 return

 ErrMsg: procedure expose ERROP
 arg msgtext
  say msgtext
  'CP MSG' ERROP msgtext
 return

USAGE NOTES

The MONSESS variable contains the frequency of VM Monitor
data to be cut each day.  The timetable variable CLOCK.i
determines the wall clock time when the VM Monitor data
collection is to be started/stopped.  The variables CLOCK.1,
CLOCK.2 ..., and CLOCK.n (where n is the value of MONSESS)
must be properly defined in the format of 'hh:mm:ss' ranging
from '00:00:00' to '23:59:59'.

At StartUp subroutine, there is a 10-second time lag for
MONWRITE to connect to *MONITOR CP System Service before
starting the monitor.

Note that a saved segment for monitor must be defined and
saved prior to start the application.

The SleepUntil subroutine, which uses the CP SLEEP command to
control the schedule, can be replaced by another timer
utility if one exists at your installation.