Is there a way to find the number of users that are currently logged into a Django site running on Linux? I need to restart the server and I want to make sure there are 'few enough' people that it won't be too much a hassle.
Asked
Active
Viewed 2,744 times
3
-
What CMS are you using? – Wesley Apr 05 '12 at 04:27
-
This is on Python/Django – David542 Apr 05 '12 at 04:31
-
First step: define what you mean by "logged in" for your particular use case. Once you've got that out of the way, implementation is trivial. – womble Apr 05 '12 at 05:54
2 Answers
1
To see what users are logged into Linux, you can use w
or who
.
The output of w
on my machine:
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
wesley tty1 :0 Tue12 39:54m 1:34m 0.06s pam: gdm-password
wesley pts/1 :0.0 Tue16 1:38m 0.45s 0.44s ssh user@remoteserver1.com
wesley pts/3 :0.0 Tue16 1:38m 0.49s 0.47s ssh user@remoteserver2.com
wesley pts/5 :0.0 Tue20 0.00s 0.25s 0.03s w
The output of who
on my machine:
wesley tty1 2012-02-14 12:28 (:0)
wesley pts/1 2012-02-14 16:24 (:0.0)
wesley pts/3 2012-02-14 16:34 (:0.0)
wesley pts/5 2012-02-14 20:46 (:0.0)
To see which users are logged into an application, such as WordPress or Joomla, will require different, application specific methods, however.
Since you're using Django, you will need to programmatically query the session
model for non-expired sessions. Check out the Q/A titled "How to get the list of the authenticated users?" over on StackOverflow for a more thorough explanation.
-
This is a django, non-specific site. I'm basically looking to infer the number from either open sessions or some other method – David542 Apr 05 '12 at 04:32