how to get the number of users logged in?

divvi_vamsi
Mega Expert

How to get the number of users logged in on each node through script? I know these stats are available in System Diagnostics page, but is there a way to pull that data to a script?

Thanks
Divya Yamani

1 ACCEPTED SOLUTION

Hello Divya,



Thanks for the update. The below blog has detailed info on what you are looking for.


https://servicenowgems.com/2016/04/28/finding-logged-in-users/


View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Divya,



Try with below script.



var gr = GlideRecord('v_user_session');


gr.query();


while (gr.next()){


gs.log("Logged in user: " + gr.user);


}


Hi Pradeep,



Thanks for the script, but is there a way to get the same count per node for all the nodes existing in the system? and also i see few of the logged in users to be some random names like rest_system..are these system generated users or created by the instance admin owner?



Thanks
Divya


we need to check table : sys_user_session same as logged in users but put the below filters and it gives logged in users currently in your instance irrespective of nodes.


name!=NULL^invalidated=NULL



Regards,


Sachin


Hello Divya,



Thanks for the update. The below blog has detailed info on what you are looking for.


https://servicenowgems.com/2016/04/28/finding-logged-in-users/