stats.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import division
  16. import sys
  17. from ._base import Config
  18. class StatsConfig(Config):
  19. """Stats Configuration
  20. Configuration for the behaviour of synapse's stats engine
  21. """
  22. section = "stats"
  23. def read_config(self, config, **kwargs):
  24. self.stats_enabled = True
  25. self.stats_bucket_size = 86400 * 1000
  26. self.stats_retention = sys.maxsize
  27. stats_config = config.get("stats", None)
  28. if stats_config:
  29. self.stats_enabled = stats_config.get("enabled", self.stats_enabled)
  30. self.stats_bucket_size = self.parse_duration(
  31. stats_config.get("bucket_size", "1d")
  32. )
  33. self.stats_retention = self.parse_duration(
  34. stats_config.get("retention", "%ds" % (sys.maxsize,))
  35. )
  36. def generate_config_section(self, config_dir_path, server_name, **kwargs):
  37. return """
  38. # Local statistics collection. Used in populating the room directory.
  39. #
  40. # 'bucket_size' controls how large each statistics timeslice is. It can
  41. # be defined in a human readable short form -- e.g. "1d", "1y".
  42. #
  43. # 'retention' controls how long historical statistics will be kept for.
  44. # It can be defined in a human readable short form -- e.g. "1d", "1y".
  45. #
  46. #
  47. #stats:
  48. # enabled: true
  49. # bucket_size: 1d
  50. # retention: 1y
  51. """