Wrong number of activeUsers

Nextcloud version: 25.0.9
Operating system and version: Debian Bullseye
Apache or nginx version: Nginx 1.18.0
PHP version: 8.1

Is this the first time you’ve seen this error? Yes

Steps to replicate it:

  1. Call the API using curl to get the number of active users
  2. Call the API using occ to get the number of active users (first using user:list and then user:lastseen user by user)
  3. Compare the two results

The curl result gives me one connected user

"activeUsers":{"last5minutes":1,"last1hour":1,"last24hours":1

And the occ result give me none.

Nothing is logged in nextcloud.log or nginx logs at the time of the requests.

Regards,

Try → nc-who ←

much luck!

1 Like

I understand the concern about the the inconsistency, but how many were you expecting? I’m assuming either zero or one is at least in the ballpark, correct?

From the looks of it, you’re comparing occ output to the serverinfo external monitoring endpoint.

From a cursory review of the code, it looks like occ user:lastseen is looking up the lastLogin (i.e. the most recent outright successful login attempt with a username/password) whereas the monitoring endpoint is reporting active users based on session activity (as in they’ve recently done something in NC but didn’t necessarily re-login since their session was still authenticated).

P.S. In the future, when posting for help please more specific with your examples (such as the exact curl call) so people don’t have to guess what you mean by “API” – there are a LOT of APIs in Nextcloud. :slight_smile:

Thank you for your answers !

I understand the concern about the the inconsistency, but how many were you expecting? I’m assuming either zero or one is at least in the ballpark, correct?

I was expecting the numbers to match, that is 0 or 1 indeed.

From a cursory review of the code, it looks like occ user:lastseen is looking up the lastLogin (i.e. the most recent outright successful login attempt with a username/password) whereas the monitoring endpoint is reporting active users based on session activity (as in they’ve recently done something in NC but didn’t necessarily re-login since their session was still authenticated).

This is very clear, thank you @jtr !
I believe all the active sessions are closed as used have not been using their accounts for more than 15 days, and I haven’t changed the default session timeout parameters (Configuration Parameters — Nextcloud latest Administration Manual latest documentation).

Could it be that calling the OCS API as I am doing (providing user credentials), means that the user I am using is counted in the activeUsers ?

P.S. In the future, when posting for help please more specific with your examples (such as the exact curl call) so people don’t have to guess what you mean by “API” – there are a LOT of APIs in Nextcloud. :slight_smile:

Sorry, you are right, I forgot to give the API route I am using, here it is:

ocs/v2.php/apps/serverinfo/api/v1/info?format=json
1 Like

Yes, I think you’re correct.

Using NC-Token (instead of an account) might workaround that, but I don’t remember how/if it interacts with session state.

Sounds good :slight_smile: I will just decrement the number by one :smile:

Thanks !

1 Like