forked from MirrorHub/synapse
add monthly active users to phonehome stats (#5252)
* add monthly active users to phonehome stats
This commit is contained in:
parent
abce00fc6a
commit
94dac0f3e5
3 changed files with 31 additions and 15 deletions
1
changelog.d/5252.feature
Normal file
1
changelog.d/5252.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add monthly active users to phonehome stats.
|
|
@ -541,6 +541,7 @@ def run(hs):
|
||||||
stats["total_room_count"] = room_count
|
stats["total_room_count"] = room_count
|
||||||
|
|
||||||
stats["daily_active_users"] = yield hs.get_datastore().count_daily_users()
|
stats["daily_active_users"] = yield hs.get_datastore().count_daily_users()
|
||||||
|
stats["monthly_active_users"] = yield hs.get_datastore().count_monthly_users()
|
||||||
stats["daily_active_rooms"] = yield hs.get_datastore().count_daily_active_rooms()
|
stats["daily_active_rooms"] = yield hs.get_datastore().count_daily_active_rooms()
|
||||||
stats["daily_messages"] = yield hs.get_datastore().count_daily_messages()
|
stats["daily_messages"] = yield hs.get_datastore().count_daily_messages()
|
||||||
|
|
||||||
|
|
|
@ -279,23 +279,37 @@ class DataStore(
|
||||||
"""
|
"""
|
||||||
Counts the number of users who used this homeserver in the last 24 hours.
|
Counts the number of users who used this homeserver in the last 24 hours.
|
||||||
"""
|
"""
|
||||||
|
yesterday = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24)
|
||||||
|
return self.runInteraction("count_daily_users", self._count_users, yesterday,)
|
||||||
|
|
||||||
def _count_users(txn):
|
def count_monthly_users(self):
|
||||||
yesterday = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24)
|
"""
|
||||||
|
Counts the number of users who used this homeserver in the last 30 days.
|
||||||
|
Note this method is intended for phonehome metrics only and is different
|
||||||
|
from the mau figure in synapse.storage.monthly_active_users which,
|
||||||
|
amongst other things, includes a 3 day grace period before a user counts.
|
||||||
|
"""
|
||||||
|
thirty_days_ago = int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30)
|
||||||
|
return self.runInteraction(
|
||||||
|
"count_monthly_users",
|
||||||
|
self._count_users,
|
||||||
|
thirty_days_ago,
|
||||||
|
)
|
||||||
|
|
||||||
sql = """
|
def _count_users(self, txn, time_from):
|
||||||
SELECT COALESCE(count(*), 0) FROM (
|
"""
|
||||||
SELECT user_id FROM user_ips
|
Returns number of users seen in the past time_from period
|
||||||
WHERE last_seen > ?
|
"""
|
||||||
GROUP BY user_id
|
sql = """
|
||||||
) u
|
SELECT COALESCE(count(*), 0) FROM (
|
||||||
"""
|
SELECT user_id FROM user_ips
|
||||||
|
WHERE last_seen > ?
|
||||||
txn.execute(sql, (yesterday,))
|
GROUP BY user_id
|
||||||
count, = txn.fetchone()
|
) u
|
||||||
return count
|
"""
|
||||||
|
txn.execute(sql, (time_from,))
|
||||||
return self.runInteraction("count_users", _count_users)
|
count, = txn.fetchone()
|
||||||
|
return count
|
||||||
|
|
||||||
def count_r30_users(self):
|
def count_r30_users(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue