feat: Track local users by appservice ID

Introduces a new metric `synapse_local_users_appservice` to count local users by their associated appservice ID, enhancing the granularity of user analytics within the Synapse Prometheus exporter. This update involves modifications to the changelog and README to document the addition, and updates to the main Python script to implement the collection and reporting of this new metric.

The change aims to provide administrators and developers with better insights into appservice usage and user distribution, facilitating improved resource allocation and service optimization.
This commit is contained in:
Kumi 2024-05-18 12:05:05 +02:00
parent 2c991a42a4
commit 25c2887b5a
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 29 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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(
"""