summary refs log tree commit diff
path: root/synapse/app
diff options
context:
space:
mode:
authorNeil Johnson <neil@fragile.org.uk>2018-07-30 22:07:07 +0100
committerNeil Johnson <neil@fragile.org.uk>2018-07-30 22:07:07 +0100
commit9b13817e067d370f3ddb860baef884bf460449b5 (patch)
tree5e41610f8ae5d927690ee60b63f282792517dc03 /synapse/app
parentlimit register and sign in on number of monthly users (diff)
downloadsynapse-9b13817e067d370f3ddb860baef884bf460449b5.tar.xz
factor out metrics from __init__ to app/homeserver
Diffstat (limited to 'synapse/app')
-rwxr-xr-xsynapse/app/homeserver.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 57b815d777..a1512ccea4 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -18,6 +18,7 @@ import logging
 import os
 import sys
 
+from prometheus_client import Gauge
 from six import iteritems
 
 from twisted.application import service
@@ -299,7 +300,12 @@ class SynapseHomeServer(HomeServer):
         except IncorrectDatabaseSetup as e:
             quit_with_error(e.message)
 
-
+# Gauges to expose monthly active user control metrics
+current_mau_gauge = Gauge("synapse_admin_current_mau", "Current MAU")
+max_mau_value_gauge = Gauge("synapse_admin_max_mau_value", "MAU Limit")
+limit_usage_by_mau_gauge = Gauge(
+    "synapse_admin_limit_usage_by_mau", "MAU Limiting enabled"
+)
 def setup(config_options):
     """
     Args:
@@ -512,6 +518,18 @@ def run(hs):
     # table will decrease
     clock.looping_call(generate_user_daily_visit_stats, 5 * 60 * 1000)
 
+    def generate_monthly_active_users():
+        count = 0
+        if hs.config.limit_usage_by_mau:
+            count = hs.get_datastore().count_monthly_users()
+        logger.info("NJ count is %d" % (count,))
+        current_mau_gauge.set(float(count))
+        max_mau_value_gauge.set(float(hs.config.max_mau_value))
+        limit_usage_by_mau_gauge.set(float(hs.config.limit_usage_by_mau))
+
+    generate_monthly_active_users()
+    clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
+
     if hs.config.report_stats:
         logger.info("Scheduling stats reporting for 3 hour intervals")
         clock.looping_call(start_phone_stats_home, 3 * 60 * 60 * 1000)