diff options
author | Erik Johnston <erik@matrix.org> | 2023-04-26 17:00:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 16:00:11 +0000 |
commit | 9900f7c231f8af536fce229117b0a406dc629293 (patch) | |
tree | a688fbc4cf51b64fa4821d19e200f8f50e3a0427 /synapse/rest/admin/statistics.py | |
parent | Update the `check_schema_delta` script to account for when the schema version... (diff) | |
download | synapse-9900f7c231f8af536fce229117b0a406dc629293.tar.xz |
Add admin endpoint to query room sizes (#15482)
Diffstat (limited to 'synapse/rest/admin/statistics.py')
-rw-r--r-- | synapse/rest/admin/statistics.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/rest/admin/statistics.py b/synapse/rest/admin/statistics.py index 9c45f4650d..19780e4b4c 100644 --- a/synapse/rest/admin/statistics.py +++ b/synapse/rest/admin/statistics.py @@ -113,3 +113,28 @@ class UserMediaStatisticsRestServlet(RestServlet): ret["next_token"] = start + len(users_media) return HTTPStatus.OK, ret + + +class LargestRoomsStatistics(RestServlet): + """Get the largest rooms by database size. + + Only works when using PostgreSQL. + """ + + PATTERNS = admin_patterns("/statistics/database/rooms$") + + def __init__(self, hs: "HomeServer"): + self.auth = hs.get_auth() + self.stats_controller = hs.get_storage_controllers().stats + + async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: + await assert_requester_is_admin(self.auth, request) + + room_sizes = await self.stats_controller.get_room_db_size_estimate() + + return HTTPStatus.OK, { + "rooms": [ + {"room_id": room_id, "estimated_size": size} + for room_id, size in room_sizes + ] + } |