Finding the users logged in to the instance
Problem Statement- We had a requirement to get all the currently logged-in users in the instance. So after doing some research we found the table Logged in Users (v_user_session) can be used for this. However, after some time, we came to know that, the table "v_user_session" stores the logged-in users for a particular node only, and because of this, our solution was not working.
Reason- The "v_user_session" table dynamically gets populated with the user's sessions. ServiceNow stores all of its configurations in the database, but logged-in sessions is actually part of the application layer and not the storage layer. As such, it's reading the logged-in sessions from the Java application. As the applications run on each individual mode, and the nodes themselves do not communicate with one another, all the logged-in user's table shows you are the logged-in users on the application node that you're on. Logging in to another node is a complete random hit-and-miss exercise of clearing your cookies and reconnecting to ServiceNow, hoping the load balancer sends you in a different direction to the node you want to be on. Not great then for finding out who's on your system.
Workaround-
1.Go to sys_user_session table-
>We can get the 'current' logged-in users from the entire instance, by filtering on "Name is not Empty" AND "Invalidated is Empty".
>The sys_user_session.invalidated column will be empty, as long as the related user session is active.
>When the session becomes inactive (either by logging out, or session being destroyed by the platform - based on the value of 'glide.ui.session_timeout' system property), sys_user_session.invalidated will be populated with the session end timestamp.
2. Normally "Logged in users" module under "User Administration" will give you the correct number of users logged in. But when Multi SSO/Single Sign-on is enabled, this module doesn't show the correct information.
You can find the users logged in by following the steps below:
- Go to xmlstats.do with include=sessions
- In the <sessions> tag
- logged_in parameter shows how many users are currently logged in to this node.
Regards,
Nayan
https://www.servicenow.com/community/itsm-articles/finding-the-users-logged-in-to-the-instance/ta-p/2304487