BookmarkSubscribeRSS Feed

A Viya Monitoring Report Showing Users' Session Information

Started ‎06-01-2017 by
Modified ‎06-05-2017 by
Views 2,820

With this blog I'd like to illustrate one way that a SAS administrator can programmatically generate session and usage reports. We know that it's possible to gather considerable information about a running CAS server, about such things as nodes in the deployment, resource usage, and in particular about users' sessions. Here I'm going to illustrate a few alternatives using the REST API, without the CAS Server Monitor. It turns out that there's a very simple REST API call that will return some basic data about all user sessions, including the following:


  • Name of Session
  • User
  • How long has it been since the last CAS action was performed in that session
  • How many CAS Actions has that user executed in that session
  • What was the most recent CAS action executed in that session
  • Whether the session is currently connected, and how many (software) clients are connected to it


One of the most common needs of an administrator is to know who is using their system, and how heavily they are using it. There's rarely a complete or direct answer, but this example goes part way to helping answer that question, for the Viya platform.


Here's the format of the REST API call, and what it looks like to issue this request from the Linux command prompt.  The

uID:password must be those of a CAS administrator:


curl -n -u uID:passwd -X GET http://< machine >:8777/cas/sessions





Notice that we receive a JSON file, with 15+ variables for each active session, as shown above.


Several of these fields, including the most interesting ones, are easily displayed using the CAS Server Monitor, for example:




However, there are times when you may want to access this data programmatically, for example, in a production environment you may want to audit usage data over a longer term, or you may want to monitor sessions that last too long in an idle state in order to terminate them. There are a few possible ways to do this--I'll illustrate one of them here, and point to some of the other possibilities.


The following simple SAS program does the following:


  • Use the URL fileref and the REST API to execute the command (shown above as a curl command) and return the JSON-formatted object containing the data that we want;
  • Define a (temporary) map file to be used when reading the JSON file;
  • Use the JSON fileref to read in the JSON file and create SAS data sets from it;
  • Combine the two data sets we want into one;
  • Print out our results in a simple report.


Here's the SAS code, which can be run in SAS Studio (or any other SAS client):




filename in url 'http://<myserver>:8777/cas/sessions' debug user='userID' pass='password';
filename map '/opt/sas/viya/config/' ;
libname in json map=map automap=replace;
data all;
merge in.root 
in.idleTime; proc print data=all; title 'display of current sessions, showing length of time since last CAS action'; title2 'and total number of CAS actions run in this session'; var uuid name user actioncount isidle hours minutes seconds; run;



Clearly this isn't perfect data, but it could be useful in indicating zombie sessions, and in pointing to overall usage by various users--for example, this could be run as a report once / day, and data sets created could be combined to get longer-term usage information about usage--something all administrators want to have.


Here's an example of an output table from the code listed above:






  • The URL fileref uses the REST API (with an implied GET), and logs on as a CAS administrator (userID/password), exactly as shown in the example at the top.
  • The JSON libname converts the JSON file and creates SAS data sets, based on the contents of the JSON file. The map is created by this libname statement, which is a character-based file that you can examine to help you understand how the conversion is done. You can actually edit and change this map file to modify the way the JSON data is interpreted into SAS data (see below).
  • In this particular case, two data sets were created (based on the structure of the JSON file), named root and idleTime, which had to be merged to provide our final SAS file.


Other approaches might include the following:


1.  Run the REST API command and pipe the output to a local file. Then process that file with SAS or another language to create a report needed.


2.  Rather than use the JSON libname, it's possible to write your own SAS datastep to convert the JSON file to a SAS data set. One example is shown in this SGF paper, using the SCANOVER data step function:


3.  Use GROOVY scripting language to process the JSON file, as illustrated in this SGF paper:


4.  Use the DS2 (SAS) procedure to process the JSON file. Documentation is found here:


Additional relevant documentation:


Article illustrating JSON libname from Enterprise Guide:


Finally, the JSON libname is fully documented here:  JSON Libref Documentation


The above document explains how you can modify the map file to re-structure the output data sets that are created.

Version history
Last update:
‎06-05-2017 09:50 AM
Updated by:


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags