Thursday, May 4, 2023

list size of tables in cas memory sas viya.

/* most of the code is somewhere borrowed, can't remember the exact site anymore */ 


options nonotes;

cas adminsession;

caslib _all_ assign;


proc cas;

/* need to be a super user */

accessControl.assumeRole / adminRole="superuser";

accessControl.accessPersonalCaslibs;

table.caslibinfo result=fileresult;

casliblist=findtable(fileresult);


/* loop caslibs */

SumDataSize=0;

SumCompressedSize=0;

SumMappedMemory=0;


do cvalue over casliblist;


if cvalue.name!=: 'demoCASUSER' then

do;


/* only look at caslibs that contain CASUSER */

table.tableinfo result=tabresult / caslib=cvalue.name;

tablelist=findtable(tabresult);

x=dim(tablelist);


if x>1 then

do;


/* there are tables available */

do tvalue over tablelist;


/* loop all tables in the caslib */

/* table.droptable / caslib="casuser" name="tableinfo"; */

table.tabledetails result=r / caslib=cvalue.name name=tvalue.name;


/* table.tableinfo / caslib=cvalue.name name=tvalue.name; */

val=findtable(r);

saveresult val caslib="CASUSER" casout="tableinfo" replace;


do xvalue over val;


/*  */

/* print (xvalue.DataSize); */

/* SumDataSize=0 ; */

SumDataSize=SumDataSize+xvalue.DataSize;

SumCompressedSize=SumCompressedSize+xvalue.CompressedSize;

SumMappedMemory=SumMappedMemory+xvalue.MappedMemory;


/* print cvalue.name, tvalue.name, xvalue.CompressedSize, "SumDataSize:" SumDataSize; */

print "INFO-001: LIBRARY: " cvalue.name " :tabel :" tvalue.name 

":DataSize :" xvalue.DataSize ":CompressedSize :" 

xvalue.CompressedSize ":AllocatedMemory : " xvalue.AllocatedMemory 

": Creator : " tvalue.creator;


/* print xvalue;   */

/* print tvalue; */

/* print cvalue; */

end;


/* print(r); */

/* describe(r); */

/* data CASUSER.tableinfo_total  ; */

/* set   CASUSER.tableinfo_total CASUSER.tableinfo; */

/*  table.append /  */

/*     source={caslib='CASUSER',name='tableinfo'} */

/*     target={caslib='CASUSER',name='tableinfo_total'}; */

end;


/* loop all tables in the caslib */

end;


/* there are tables available */

end;


/* only look at caslibs that contain CASUSER */

end;


/* loop caslibs */

print "INFO-001:SumDataSize :" round(SumDataSize/1024/1024) "MB";

print "INFO-001:SumCompressedSize :" round(SumCompressedSize/1024/1024) 

"MB";

print "INFO-001:SumMappedMemory : " round(SumMappedMemory/1024/1024) "MB";

accessControl.dropRole / adminRole='superuser';

quit;


cas adminsession terminate;

sas viya cas cache cascache disk usage history

 

cas sess1; 

caslib _all_ assign;


%let BASE_URI=%sysfunc(getoption(servicesbaseurl)) ;

 


/* proc casutil outcaslib="CASUSER" ; */

/*    load data=  path="dfcascachehistory.sashdat"; replace;   */



proc cas;

/* table.dropTable / table="dfcascachehistory";   */


  table.loadTable /

    path="dfcascachehistory.sashdat"

    casout={name="dfcascachehistory"} ;

    

  table.fileInfo /                                                /* 1*/

    path="dfcascachehistory.sashdat";

quit ;




proc cas; 

    session sess1; 

    accessControl.assumeRole / adminRole="superuser";       

    builtins.getCacheInfo result=results; 

    describe results  ;  

run;



SAVERESULT results dataout=dfcascache ;  




data casuser.dfcascache_with_date; 

set dfcascache;

format datum ddmmyy10. ;

  datum=date();

run;


data casuser.dfcascachehistory ( append=yes ) ;

set  casuser.dfcascache_with_date;

run;


proc contents data=casuser.dfcascachehistory ;

run; 


proc cas;

  table.save /

    table="dfcascachehistory"

    name="dfcascachehistory.sashdat"

    replace=True;

    

  table.fileInfo /  path="dfcascachehistory.sashdat";

quit ;






options 

  emailsys=smtp 

  emailhost=

(

"MAILSERVERNAME.nl"

STARTTLS auth=LOGIN

/* your Outlook address */

id=USERNAME@SOMESITE.NL

/* optional: encode PW with PROC PWENCODE */

pw={SAS002}ABCDEFGHI port=25

)

;

/* Small SAS job to produce some data */


filename msg email 

 to="sasuser@somesite.nl"

from="no_reply@somesite.nl"

type='text/html'

subject = "DDS-INFO-001:DFCASCACHE &base_uri"; 

ods graphics / imagefmt=png height=800 width=800;

ods html5 (id=mail) file=msg style=htmlblue options(bitmap_mode="inline") gtitle;

ods escapechar='^';

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black} ";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black}Goededag ,";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black} ";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black}Bijgaand de cascache informatie";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black} ";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black}Vriendelijke groeten,";

ODS TEXT="^S={font_face='Calibri' font_size=3 fontweight=Medium foreground=black} ";


 

proc print data=dfcascache noobs

 style (table) = [frame=box borderwidth=1 ];

;

/* VAR sex name age; */

TITLE1 "DISK USAGE CAS CACHE ";

Footnote1 "&_sasprogramfile";

Footnote2 "2023 &BASE_URI";


run;


proc print data=casuser.dfcascachehistory noobs

 style (table) = [frame=box borderwidth=1 ];

;

run;

proc sgplot data=casuser.dfcascachehistory;


title "Graph of FS_USAGE, by Node";


series x=datum y=FS_USAGE /markers group=Node;


/* keylegend /location=outside position=top; */

keylegend /position=top;


run;



ods html5 (id=mail) close;


cas sess1 terminate;