summary refs log tree commit diff
path: root/docs/admin_api/statistics.md
blob: 59f07311ebc00588fe151dd6db9d05495b0e2c82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Users' media usage statistics

Returns information about all local media usage of users. Gives the
possibility to filter them by time and user.

To use it, you will need to authenticate by providing an `access_token`
for a server admin: see [Admin API](../usage/administration/admin_api/).

The API is:

```
GET /_synapse/admin/v1/statistics/users/media
```

A response body like the following is returned:

```json
{
  "users": [
    {
      "displayname": "foo_user_0",
      "media_count": 2,
      "media_length": 134,
      "user_id": "@foo_user_0:test"
    },
    {
      "displayname": "foo_user_1",
      "media_count": 2,
      "media_length": 134,
      "user_id": "@foo_user_1:test"
    }
  ],
  "next_token": 3,
  "total": 10
}
```

To paginate, check for `next_token` and if present, call the endpoint
again with `from` set to the value of `next_token`. This will return a new page.

If the endpoint does not return a `next_token` then there are no more
reports to paginate through.

**Parameters**

The following parameters should be set in the URL:

* `limit`: string representing a positive integer - Is optional but is
  used for pagination, denoting the maximum number of items to return
  in this call. Defaults to `100`.
* `from`: string representing a positive integer - Is optional but used for pagination,
  denoting the offset in the returned results. This should be treated as an opaque value
  and not explicitly set to anything other than the return value of `next_token` from a
  previous call. Defaults to `0`.
* `order_by` - string - The method in which to sort the returned list of users. Valid values are:
  - `user_id` - Users are ordered alphabetically by `user_id`. This is the default.
  - `displayname` - Users are ordered alphabetically by `displayname`.
  - `media_length` - Users are ordered by the total size of uploaded media in bytes.
    Smallest to largest.
  - `media_count` - Users are ordered by number of uploaded media. Smallest to largest.
* `from_ts` - string representing a positive integer - Considers only
  files created at this timestamp or later. Unix timestamp in ms.
* `until_ts` - string representing a positive integer - Considers only
  files created at this timestamp or earlier. Unix timestamp in ms.
* `search_term` - string - Filter users by their user ID localpart **or** displayname.
  The search term can be found in any part of the string.
  Defaults to no filtering.
* `dir` - string - Direction of order. Either `f` for forwards or `b` for backwards.
  Setting this value to `b` will reverse the above sort order. Defaults to `f`.


**Response**

The following fields are returned in the JSON response body:

* `users` - An array of objects, each containing information
  about the user and their local media. Objects contain the following fields:
  - `displayname` - string - Displayname of this user.
  - `media_count` - integer - Number of uploaded media by this user.
  - `media_length` - integer - Size of uploaded media in bytes by this user.
  - `user_id` - string - Fully-qualified user ID (ex. `@user:server.com`).
* `next_token` - integer - Opaque value used for pagination. See above.
* `total` - integer - Total number of users after filtering.


# Get largest rooms by size in database

Returns the 10 largest rooms and an estimate of how much space in the database
they are taking.

This does not include the size of any associated media associated with the room.

Returns an error on SQLite.

*Note:* This uses the planner statistics from PostgreSQL to do the estimates,
which means that the returned information can vary widely from reality. However,
it should be enough to get a rough idea of where database disk space is going.


The API is:

```
GET /_synapse/admin/v1/statistics/database/rooms
```

A response body like the following is returned:

```json
{
  "rooms": [
    {
      "room_id": "!OGEhHVWSdvArJzumhm:matrix.org",
      "estimated_size": 47325417353
    }
  ],
}
```



**Response**

The following fields are returned in the JSON response body:

* `rooms` - An array of objects, sorted by largest room first. Objects contain
  the following fields:
  - `room_id` - string - The room ID.
  - `estimated_size` - integer - Estimated disk space used in bytes by the room
    in the database.


*Added in Synapse 1.83.0*