diff --git a/CHANGELOG.md b/CHANGELOG.md index a138261..3ad9134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## v0.0.1 +## v0.0.2 (2024-05-18) + +### Added + +- Added `synapse_local_users_appservice` metric to count local users by appservice ID + +## v0.0.1 (2024-05-18) ### Added diff --git a/README.md b/README.md index 53d2bdb..d79d333 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ The exporter currently provides the following metrics: - `synapse_local_users_state`: Number of local users by state (active, disabled) - `synapse_local_users_type`: Number of local users by type (guest, user, appservice) - `synapse_local_users_moderation`: Number of local users by moderation status (active, shadow_banned, locked) +- `synapse_local_users_appservice`: Number of local users by appservice ID - `synapse_total_devices`: Total number of devices - `synapse_total_rooms`: Total number of rooms - `synapse_total_events`: Total number of events diff --git a/src/synapse_prometheus_exporter/__main__.py b/src/synapse_prometheus_exporter/__main__.py index 7a58830..a4de1f9 100644 --- a/src/synapse_prometheus_exporter/__main__.py +++ b/src/synapse_prometheus_exporter/__main__.py @@ -24,6 +24,13 @@ LOCAL_USERS_MODERATION = Gauge( ["status", "host"], ) +# Gauge for appservice users by appservice ID +LOCAL_USERS_APPSERVICE = Gauge( + "synapse_local_users_appservice", + "Number of local users by appservice ID", + ["appservice_id", "host"], +) + # Gauge for total number of devices, rooms, and events TOTAL_DEVICES = Gauge( "synapse_total_devices", "Total number of devices in the database", ["host"] @@ -81,11 +88,19 @@ def get_synapse_stats(db_config): "appservice": sum([1 for user in local_users if user[1]]), } local_users_moderation = { - "active": sum([1 for user in local_users if user[4] is False and user[5] is False]), + "active": sum( + [1 for user in local_users if user[4] is False and user[5] is False] + ), "shadow_banned": sum([1 for user in local_users if user[4] is True]), "locked": sum([1 for user in local_users if user[5] is True]), } + local_users_appservice = {} + for user in local_users: + if user[1]: + local_users_appservice[user[1]] = ( + local_users_appservice.get(user[1], 0) + 1 + ) LOCAL_USERS_STATE.labels(state="active", host=host_identifier).set( local_users_state["active"] @@ -114,6 +129,11 @@ def get_synapse_stats(db_config): local_users_moderation["locked"] ) + for appservice_id, count in local_users_appservice.items(): + LOCAL_USERS_APPSERVICE.labels( + appservice_id=appservice_id, host=host_identifier + ).set(count) + # Get the total number of devices, rooms, and events cursor.execute( """