How to report currently active users?

Peter Binney December 5, 2012

Before taking down an application for upgrade or maintenance we like to check which (if any) users are currently active (ie: have explicitly accessed a page).

Is there some way to report this (ideally with an SQL query), other than grepping the access log using something like:

fgrep -v -e '"GET /rest/' localhost_access_log.2012-12-06.txt | tail

2 answers

1 accepted

0 votes
Answer accepted
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2012

We use a macro based on Andrew Frayling's work:

https://answers.atlassian.com/questions/33385/macro-that-produces-a-list-of-users-last-login-date

You can tweak it to get users who have accessed pages within the last few minutes, for example.

Another thing we do is use Google Analytics, and check the real-time stats. That will tell you how many users are currently using the site (within the last 1 minute, I think), and what pages they are on.

hth,

matt

Peter Binney December 10, 2012

Many thanks Matthew, I'll try that when I get some time.

For now, since Atlassian confirm they have nothing (https://support.atlassian.com/browse/CSP-92874) I'm using a slightly more elaborate access log report:

awk '
/ "GET \/rest/ { next }	# Ignore Ajax fetches
{
   userName = $3                    # $1: IP, $2: Hyphen usually
   TS = $4                          # In form [dd/Mmm/yyyy:hh:mm:ss    $5: +0000] $6: $GET $7: /url/...
   USERS[userName] = substr(TS, 2)  # Array key is name, value is timestamp
}
END {
   for (userName in USERS)
      print USERS[userName], userName
}
' `ls -t localhost_access_log.*.txt | sed -n 1,2p` | sort # Check last 2 days' logs

Peter Binney December 10, 2012

Sorry - `back-quoted` command on last line above should have "| tac" at end. ie:

' `ls -t localhost_access_log.*.txt | sed -n 1,2p | tac` | sort

0 votes
AlysonA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2012

Hi Peter,

This SQL query should be enough to retrieve all users that belong in a group which has global permissions:

SELECT DISTINCT u.lower_user_name
FROM cwd_user u
JOIN cwd_membership m ON u.id = child_user_id
JOIN cwd_group g ON m.parent_id = g.id
JOIN spacepermissions sp ON g.group_name = sp.permgroupname
WHERE permtype='USECONFLUENCE' AND u.active = 'T';

Hope it helps!

Peter Binney December 10, 2012

Thanks Alyson - that's handy, but I want currently active users. eg: to see if I need to postpone down time and/or contact them when about to take Confluence down.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events