diff options
author | Daniel Wagner-Hall <dawagner@gmail.com> | 2015-09-22 13:59:37 +0100 |
---|---|---|
committer | Daniel Wagner-Hall <dawagner@gmail.com> | 2015-09-22 13:59:37 +0100 |
commit | f17aadd1b52463b51b8532cda074094ff2d0339b (patch) | |
tree | 2324815f78ea2fe5eebe29472ca5d169dd274953 /synapse/storage/__init__.py | |
parent | Merge pull request #276 from matrix-org/markjh/history_for_rooms_that_have_be... (diff) | |
parent | Add some docstrings (diff) | |
download | synapse-f17aadd1b52463b51b8532cda074094ff2d0339b.tar.xz |
Merge pull request #285 from matrix-org/daniel/metrics-2
Implement configurable stats reporting
Diffstat (limited to 'synapse/storage/__init__.py')
-rw-r--r-- | synapse/storage/__init__.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index 77cb1dbd81..340e59afcb 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -54,7 +54,7 @@ logger = logging.getLogger(__name__) # Remember to update this number every time a change is made to database # schema files, so the users will be informed on server restarts. -SCHEMA_VERSION = 23 +SCHEMA_VERSION = 24 dir_path = os.path.abspath(os.path.dirname(__file__)) @@ -126,6 +126,27 @@ class DataStore(RoomMemberStore, RoomStore, lock=False, ) + @defer.inlineCallbacks + def count_daily_users(self): + """ + Counts the number of users who used this homeserver in the last 24 hours. + """ + def _count_users(txn): + txn.execute( + "SELECT COUNT(DISTINCT user_id) AS users" + " FROM user_ips" + " WHERE last_seen > ?", + # This is close enough to a day for our purposes. + (int(self._clock.time_msec()) - (1000 * 60 * 60 * 24),) + ) + rows = self.cursor_to_dict(txn) + if rows: + return rows[0]["users"] + return 0 + + ret = yield self.runInteraction("count_users", _count_users) + defer.returnValue(ret) + def get_user_ip_and_agents(self, user): return self._simple_select_list( table="user_ips", |