measurable.py 770 B

1234567891011121314151617181920212223242526272829
  1. from __future__ import absolute_import
  2. import abc
  3. class AbstractMeasurable(object):
  4. """A measurable quantity that can be registered as a metric"""
  5. @abc.abstractmethod
  6. def measure(self, config, now):
  7. """
  8. Measure this quantity and return the result
  9. Arguments:
  10. config (MetricConfig): The configuration for this metric
  11. now (int): The POSIX time in milliseconds the measurement
  12. is being taken
  13. Returns:
  14. The measured value
  15. """
  16. raise NotImplementedError
  17. class AnonMeasurable(AbstractMeasurable):
  18. def __init__(self, measure_fn):
  19. self._measure_fn = measure_fn
  20. def measure(self, config, now):
  21. return float(self._measure_fn(config, now))