Report for currently logged in users

Hello All,

How I can generate a list/report of currently logged-in users in the ERP system? It would be advantageous if an admin user can forcefully log-out an idol user or kill a session.


You can set a session time out , this will be a global rule , under system settings>security.

Thanks @msalim79 for the reply.

Actually, it is a global setting. It is definitely helpful. But my requirement is slightly different. I want 2 things: 1) To check how many users are currently logged-in and 2) forcefully log-out or kill a session in an ad-hoc manner. This means it should be need-based. It is up to an admin that the session should be killed or not.

Setting a global session time out would create inconvenience to the regular and routine users.

Out of the box i dont see anything , you would then need to build and customise your needs.

I have found out a solution for the requirement posted.

There is a table in ERPNext DB named ‘tabSessions’ where in one can find out - user, ipaddress, lastupdate, device, status, and sessiondata - columns. By that one can get to know who are currently logged-in in the system. One can build a custom report and produce the requisite data.



Command: uptime
Will show you how many users in

@TheCoder1. It shows the number of users logged to the server thru the terminal. They are not actual application logged-in users.

did you actually implement the report?

@moe01325 . Yes Sir. I have implemented it and it is giving the desired result as shown below.

do you mind sharing it?

Sure @moe01325. Please find following python code. You add a script report using Administrator login and use the code following code and just copy paste it in a python file inside the report directory.

from future import unicode_literals
import frappe
from frappe import _

def execute(filters=None):
columns, data = ,
columns = get_columns(filters)
data = get_result(filters)
return columns, data

def get_columns(filters):
columns = [
“label”: _(“User Name”),
“fieldname”: “Username”,
“fieldtype”: “Link”,
“options”: “User”,
“width”: 150
“label”: _(“IP”),
“fieldname”: “ip”,
“fieldtype”: “Data”,
“width”: 120
“label”: _(“Last Update”),
“fieldname”: “LastUpdate”,
“fieldtype”: “Date”,
“width”: 130
“label”: _(“Device”),
“fieldname”: “device”,
“fieldtype”: “Data”,
“width”: 100
“label”: _(“Status”),
“fieldname”: “status”,
“fieldtype”: “Data”,
“width”: 100

return columns

def get_result(filters):

query = """
  	user AS Username,
  			substring_index(substring_index(sessiondata, 'session_ip', -1), ',', 1), ':',''), "\'", "") AS ip,
  	lastupdate AS LastUpdate,
  	device AS Device,
  	status AS Status
  FROM tabSessions
q_data = frappe.db.sql(query)

data = []
for q in q_data:
    row = {
        "Username": q[0],
        "ip": q[1],
        "LastUpdate": q[2],
        "device": q[3],            
        "status": q[4]      

return data

Thanks a lot! I appreciate it!