def phone_stats_home(): logger.info("Gathering stats for reporting") now = int(hs.get_clock().time()) uptime = int(now - start_time) if uptime < 0: uptime = 0 # If the stats directory is empty then this is the first time we've # reported stats. first_time = not stats stats["homeserver"] = hs.config.server_name stats["timestamp"] = now stats["uptime_seconds"] = uptime stats["total_users"] = yield hs.get_datastore().count_all_users() room_count = yield hs.get_datastore().get_room_count() stats["total_room_count"] = room_count stats["daily_active_users"] = yield hs.get_datastore().count_daily_users() daily_messages = yield hs.get_datastore().count_daily_messages() if daily_messages is not None: stats["daily_messages"] = daily_messages else: stats.pop("daily_messages", None) if first_time: # Add callbacks to report the synapse stats as metrics whenever # prometheus requests them, typically every 30s. # As some of the stats are expensive to calculate we only update # them when synapse phones home to matrix.org every 24 hours. metrics = get_metrics_for("synapse.usage") metrics.add_callback("timestamp", lambda: stats["timestamp"]) metrics.add_callback("uptime_seconds", lambda: stats["uptime_seconds"]) metrics.add_callback("total_users", lambda: stats["total_users"]) metrics.add_callback("total_room_count", lambda: stats["total_room_count"]) metrics.add_callback( "daily_active_users", lambda: stats["daily_active_users"] ) metrics.add_callback( "daily_messages", lambda: stats.get("daily_messages", 0) ) logger.info("Reporting stats to matrix.org: %s" % (stats,)) try: yield hs.get_simple_http_client().put_json( "https://matrix.org/report-usage-stats/push", stats ) except Exception as e: logger.warn("Error reporting stats: %s", e)
def phone_stats_home(): logger.info("Gathering stats for reporting") now = int(hs.get_clock().time()) uptime = int(now - start_time) if uptime < 0: uptime = 0 # If the stats directory is empty then this is the first time we've # reported stats. first_time = not stats stats["homeserver"] = hs.config.server_name stats["timestamp"] = now stats["uptime_seconds"] = uptime stats["total_users"] = yield hs.get_datastore().count_all_users() room_count = yield hs.get_datastore().get_room_count() stats["total_room_count"] = room_count stats["daily_active_users"] = yield hs.get_datastore( ).count_daily_users() daily_messages = yield hs.get_datastore().count_daily_messages() if daily_messages is not None: stats["daily_messages"] = daily_messages else: stats.pop("daily_messages", None) if first_time: # Add callbacks to report the synapse stats as metrics whenever # prometheus requests them, typically every 30s. # As some of the stats are expensive to calculate we only update # them when synapse phones home to matrix.org every 24 hours. metrics = get_metrics_for("synapse.usage") metrics.add_callback("timestamp", lambda: stats["timestamp"]) metrics.add_callback("uptime_seconds", lambda: stats["uptime_seconds"]) metrics.add_callback("total_users", lambda: stats["total_users"]) metrics.add_callback("total_room_count", lambda: stats["total_room_count"]) metrics.add_callback("daily_active_users", lambda: stats["daily_active_users"]) metrics.add_callback("daily_messages", lambda: stats.get("daily_messages", 0)) logger.info("Reporting stats to matrix.org: %s" % (stats, )) try: yield hs.get_simple_http_client().put_json( "https://matrix.org/report-usage-stats/push", stats) except Exception as e: logger.warn("Error reporting stats: %s", e)
from synapse.event_auth import get_user_power_level from synapse.api.constants import EventTypes, Membership from synapse.metrics import get_metrics_for from synapse.util.caches import metrics as cache_metrics from synapse.util.caches.descriptors import cached from synapse.util. async import Linearizer from synapse.state import POWER_KEY from collections import namedtuple logger = logging.getLogger(__name__) rules_by_room = {} push_metrics = get_metrics_for(__name__) push_rules_invalidation_counter = push_metrics.register_counter( "push_rules_invalidation_counter") push_rules_state_size_counter = push_metrics.register_counter( "push_rules_state_size_counter") # Measures whether we use the fast path of using state deltas, or if we have to # recalculate from scratch push_rules_delta_state_cache_metric = cache_metrics.register_cache( "cache", size_callback=lambda: 0, # Meaningless size, as this isn't a cache that stores values cache_name="push_rules_delta_state_cache_metric", )
from synapse.api.constants import EventTypes, Membership from synapse.metrics import get_metrics_for from synapse.util.caches import metrics as cache_metrics from synapse.util.caches.descriptors import cached from synapse.util.async import Linearizer from synapse.state import POWER_KEY from collections import namedtuple logger = logging.getLogger(__name__) rules_by_room = {} push_metrics = get_metrics_for(__name__) push_rules_invalidation_counter = push_metrics.register_counter( "push_rules_invalidation_counter" ) push_rules_state_size_counter = push_metrics.register_counter( "push_rules_state_size_counter" ) # Measures whether we use the fast path of using state deltas, or if we have to # recalculate from scratch push_rules_delta_state_cache_metric = cache_metrics.register_cache( "cache", size_callback=lambda: 0, # Meaningless size, as this isn't a cache that stores values cache_name="push_rules_delta_state_cache_metric", )