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.
Ansible playbooks
To assist with the configuration changes required for ESM integration with SAS Viya, Boemska provide a set of Ansible playbooks. We recommend that these are used with the assistance of Boemska Support. For basic integration with the SAS Viya microservices and SPRE runtimes, follow the steps below.
Viya Microservices¶
Instances of microservices can be configured to report in to ESM automatically by modifying the sas_check_pid()
function in /opt/sas/viya/home/lib/envesntl/sas-init-functions
. Add the following code after the result=0 # is running
(typically line 125):
Values need to be updated
The snippet below contains an incomplete path starting with ###
. Please update this line for your environment.
# ESM CONFIG START
esmconfig=/opt/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] [name] [type]
function reportPid () {
pidowner=$(ps -o user= -p $1)
# echo "\"$pidowner\" \"$3\" \"$2\" \" \" \" \" \" \" " > $ESMEVENTS/new'_'$1'_'$ESMNODENAME
eventString=[{\"pid\":$1\,\"owner\":\"$pidowner\"\,\"esmType\":\"$3\"\,\"jobName\":\"$2\"\,\"logFile\":\"$4\"\,\"hostname\":\"$ESMNODENAME\"}]
echo $eventString
echo $eventString > $ESMEVENTS/new'_'$1'_'$ESMNODENAME
# echo "$2 reported to $ESMEVENTS"
}
function findPidfiles () {
# make sure there are pidfiles
if [ $(find $viyapidfiles/*.pid 2>/dev/null | wc -l) -gt 0 ]; then
for pidfile in $viyapidfiles/*.pid; do
# remove directory prefix
fileshort=$(basename $pidfile)
# removelog suffix
servicename=$(echo ${fileshort} | cut -d '.' -f 1)
# some things like apache have multiple pids
for pidno in $(cat $pidfile); do
# then there are multiple handles open to the same file
fds=$(ls -latr /proc/${pidno}/fd | grep ${viyalogroot} | sed 's/.*> //' | sort | uniq)
for fd in $fds; do
# if there happen to be multiple open get the latest
lastLogfile=${fd}
done
# reportPid $pidno "$servicename" "uS"
reportPid ${pidno} "${servicename}" "viya" "${lastLogfile}"
done
done
fi
}
findPidfiles
# ESM CONFIG END
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.
- Ensure that you have completed the Compute Server configuration above.
-
After making a backup, modify
jesbegin.sas
in/opt/sas/spre/home/SASFoundation/sasautos
putting the following lines just before the closing%mend
tag:/* ESM CONFIG START */ %include "%sysget(ESMHOME)/sasautos/startjes.sas"; /* ESM CONFIG END */
-
After making a backup, modify
jesend.sas
in/opt/sas/spre/home/SASFoundation/sasautos
putting the following lines just before theoptions nonotes;
(circa line 51)/* ESM CONFIG START */ %include "%sysget(ESMHOME)/sasautos/endjes.sas"; /* ESM CONFIG END */