Configuring SAS Viya for ESM

Once the ESM Server and Agent components are installed, some additional configuration is required to integrate ESM monitoring with the various SAS Viya components.

Viya Microservices

Instances of microservices can be configured to report in to ESM automatically by modifying the /opt/sas/viya/home/lib/envesntl/sas-init-functions file to include a new ESM reporting function.

  1. Append the following code the end of the file. Please update this snippet for your environment by changing the path to the esmconfig.sh file as well as the viyalogroot if required:

    # ESM CONFIG BLOCK START
    esmconfig=/opt/sas/esm/esm-agent/conf/esmconfig.sh
    source $esmconfig
    viyalogroot=/opt/sas/viya/config/var/log
    viyaname=sas-viya
    viyapidfiles=/var/run/sas
    
    # format here is reportPid [pid] [pidfile]
    function reportViyaPid () {
        esmpidno=$1
        esmfileshort=$(basename $2)
        esmservicename=$(echo ${esmfileshort} | cut -d '.' -f 1)
    
    esmfds=$(ls -latr /proc/${esmpidno}/fd | grep ${viyalogroot} | sed 's/.*> //' | sort | uniq)
        for fd in $esmfds; do
        # if there happen to be multiple open get the latest
            lastLogfile=${fd}
    done
        esmpidowner=$(ps -o user= -p $esmpidno)
        eventString=[{\"pid\":$esmpidno\,\"owner\":\"$esmpidowner\"\,\"esmType\":\"viya\"\,\"jobName\":\"$esmservicename\"\,\"logFile\":\"$lastLogfile\"\,\"hostname\":\"$ESMNODENAME\"}]
        echo $eventString > $ESMEVENTS/new'_'$esmpidno'_'$ESMNODENAME
    }
    # ESM CONFIG BLOCK END
    

  2. Add the following code after the result=0 # is running (this will be on roughly line 117):

    # ESM CONFIG BLOCK START
    reportViyaPid ${pidno} ${pidfile}
    # ESM CONFIG BLOCK END
    

If your SAS Microservices are running while these changes are made you will need to run /etc/init.d/sas-viya-all-services status in order to add your services to ESM.

SPRE Sessions

Configuring SPRE workspace servers is similar to configuring a SAS9 Workspace Server instance.

In order to associate SAS sessions to their parent server types we need to configure some ESM environment variables. Add the following snippet to the following files:

  • /opt/sas/viya/config/etc/workspaceserver/default/workspaceserver_usermods.sh
  • /opt/sas/viya/config/etc/connectserver/default/connectserver_usermods.sh
  • /opt/sas/viya/config/etc/batchserver/default/batchserver_usermods.sh

Update values

The snippet below contains an incomplete path starting with ###. Please update this line for your environment.

# ESM CONFIG START
export ESMBASEDIR=###/pub/esm/esm-agent
if [[ -f $ESMBASEDIR/conf/esmconfig.sh ]]
then
    . $ESMBASEDIR/conf/esmconfig.sh
    # set the active flag as 1 for active, 0 for inactive
    export ESMACTIVE=1
    # This is the name given to non-job sessions (for example)
    export ESMSESSIONNAME=####SAS-Studio|SAS-Connect|Batch
    export ESMSESSIONTYPE=###WS|CS|Batch
fi
# ESM CONFIG END

And then source the integration macros via each server's autoexec_usermods.sas:

/* ESM CONFIG START */
%if %sysfunc(envlen(ESMHOME)) > 0 %then %do;
    %let ESMHOME=%sysfunc(sysget(ESMHOME));
    %include "&ESMHOME/sasautos/esmtags.sas";
%end;
/* ESM CONFIG END */

Compute Server Sessions

The compsrv configuration does not have a shell script in the configuration directory from which it is executed. As such, we need to configure the required ESM environment variables differently. To do this we will use the server's autoexec_usermods.sas file /opt/sas/viya/config/etc/compsrv/default/autoexec_usermods.sas. Add the following lines modifying the ESMBASEDIR for your environment:

/* START ESM BOOTSTRAP */
%let ESMBASEDIR="/pub/esm/esm-agent";
%if %sysfunc(fileexist(&ESMBASEDIR./sasautos/esmtags.sas)) %then %do;
    options set = ESMHOME &ESMBASEDIR.;
    options set = ESMACTIVE = 1;
    options set = ESMSESSIONTYPE="CMP";
    options set = ESMSESSIONNAME="compsrv_default";
    options set = LOGPATH="/opt/sas/viya/config/var/log/compsrv/default/";
    %let esmh=%sysget(ESMHOME);
    %include "&esmh./sasautos/esmtags.sas";
%end;
/* END ESM BOOTSTRAP */

JES Job Name

Minimum version requirement

The minimum version of ESM tags required for this is 1.27 and startjes.sas and endjes.sas v1.0. Please contact Boemska support for these files.

If you are using the SAS Job Execution Service to execute jobs then it can be very useful to be able to search for and track the performance of those jobs. With a small inclusion in the JESBEGIN and JESEND macros from SAS, ESM can track and measure JES jobs specifically while enabling extended searching and filtering in the ESM user interface.

  1. Ensure that you have completed the Compute Server configuration above.
  2. After making a backup, modify jesbegin.sas in /opt/sas/spre/home/SASFoundation/sasautos putting the following lines just before the closing %mendtag:

    /* ESM CONFIG START */
    %include "%sysget(ESMHOME)/sasautos/startjes.sas";
    /* ESM CONFIG END */
    

  3. After making a backup, modify jesend.sas in /opt/sas/spre/home/SASFoundation/sasautos putting the following lines just before the options nonotes; (circa line 51)

    /* ESM CONFIG START */
    %include "%sysget(ESMHOME)/sasautos/endjes.sas";
    /* ESM CONFIG END */