Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /api/v1/stats #356

Closed
omarroth opened this issue Feb 10, 2019 · 5 comments
Closed

Add /api/v1/stats #356

omarroth opened this issue Feb 10, 2019 · 5 comments
Labels
enhancement Improvement of an existing feature

Comments

@omarroth
Copy link
Contributor

Diaspora provides /nodeinfo/1.0 and /nodeinfo/2.0 on instances that have them enabled. Example: https://framasphere.org/nodeinfo/2.0.

Invidious could provide an endpoint /api/v1/stats that provides similar statistics. Statistics would be disabled by default and enabled either in config.yml or as part of #312.

@dimqua
Copy link
Contributor

dimqua commented Feb 10, 2019

In addition, short statistic such as a version number can be added to the footer of the website. This way you can be sure which version you're using.

@omarroth
Copy link
Contributor Author

Using the example from above:

{
  "version": "2.0",
  "software": { "name": "diaspora", "version": "0.7.9.0-p00846856" },
  "protocols": ["diaspora"],
  "services": { "inbound": [], "outbound": ["twitter", "tumblr", "wordpress"] },
  "openRegistrations": true,
  "usage": {
    "users": { "total": 56091, "activeHalfyear": 12026, "activeMonth": 4715 },
    "localPosts": 657359,
    "localComments": 641679
  },
  "metadata": {
    "nodeName": "Framasphere*",
    "xmppChat": false,
    "camo": { "markdown": true, "opengraph": true, "remotePods": false },
    "adminAccount": "podmin"
  }
}

The relevant fields would be version, openRegistrations #293, users, and adminAccount for #312.

There would also likely be localPlaylists once #114 is implemented.

@aaferrari
Copy link
Contributor

To get the number of users, this could be used with PostgreSQL:

select json_build_object(
    'total', (select count(*) from users),
    'activeHalfyear', (select count(*) from users where updated between (current_timestamp - interval '6 months') and current_timestamp),
    'activeMonth', (select count(*) from users where updated between (current_timestamp - interval '1 month') and current_timestamp)
);

Which would return something like
{"total" : 1, "activeHalfyear" : 1, "activeMonth" : 1}
Although it is not clear to me if the updated field is modified when the user starts session, when adjusting the prefencias and/or when subscribing to a channel.

@omarroth
Copy link
Contributor Author

The updated field is used for delivering new notifications and is set to the current time whenever a user visits their subscription feed.

Unfortunately count(*) gets quite slow whenever the number of rows gets too large, see here. Running the above query takes around 4-6 seconds for https://invidio.us.

I can see that being reasonable though if you pull it out into a job like this so statistics are updated separately from the main query.

@omarroth omarroth added the enhancement Improvement of an existing feature label Feb 12, 2019
This was referenced Feb 20, 2019
@omarroth
Copy link
Contributor Author

omarroth commented Mar 2, 2019

Added with 4be82c5.

Statistics are disabled by default. You can see statistics for the official instance here. Example response (as of writing):

{
  "version": "2.0",
  "software": {
    "name": "invidious",
    "version": "0.14.1-daf8e5b"
  },
  "openRegistrations": true,
  "usage": {
    "users": {
      "total": 3165,
      "activeHalfyear": 2853,
      "activeMonth": 1027
    }
  },
  "metadata": {
    "updatedAt": 1551497015,
    "lastChannelRefreshedAt": 1551497015
  }
}

Statistics are updated roughly once every minute, the time it was updated designated by updatedAt.

The schema is based on this spec. Several fields are omitted, such as the services and protocols, as they are not currently applicable.

@omarroth omarroth closed this as completed Mar 2, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants